1
2
Fork 0
mirror of https://github.com/mat-1/azalea.git synced 2025-08-02 06:16:04 +00:00

use variables directly in format strings

thanks clippy we love you
This commit is contained in:
mat 2022-10-27 21:22:47 -05:00
parent 7ae8bfab50
commit 9de6c03dfb
17 changed files with 49 additions and 49 deletions

View file

@ -15,5 +15,5 @@ async fn main() {
) )
.await .await
.unwrap(); .unwrap();
println!("{:?}", auth_result); println!("{auth_result:?}");
} }

View file

@ -336,7 +336,7 @@ async fn auth_with_xbox_live(
"SiteName": "user.auth.xboxlive.com", "SiteName": "user.auth.xboxlive.com",
// i thought this was supposed to be d={} but it doesn't work for // i thought this was supposed to be d={} but it doesn't work for
// me when i add it ?????? // me when i add it ??????
"RpsTicket": format!("{}", access_token) "RpsTicket": format!("{access_token}")
}, },
"RelyingParty": "http://auth.xboxlive.com", "RelyingParty": "http://auth.xboxlive.com",
"TokenType": "JWT" "TokenType": "JWT"
@ -359,7 +359,7 @@ async fn auth_with_xbox_live(
// not_after looks like 2020-12-21T19:52:08.4463796Z // not_after looks like 2020-12-21T19:52:08.4463796Z
let expires_at = DateTime::parse_from_rfc3339(&res.not_after) let expires_at = DateTime::parse_from_rfc3339(&res.not_after)
.map_err(|e| XboxLiveAuthError::InvalidExpiryDate(format!("{}: {}", res.not_after, e)))? .map_err(|e| XboxLiveAuthError::InvalidExpiryDate(format!("{}: {e}", res.not_after)))?
.with_timezone(&Utc) .with_timezone(&Utc)
.timestamp() as u64; .timestamp() as u64;
Ok(ExpiringValue { Ok(ExpiringValue {
@ -416,7 +416,7 @@ async fn auth_with_minecraft(
.post("https://api.minecraftservices.com/authentication/login_with_xbox") .post("https://api.minecraftservices.com/authentication/login_with_xbox")
.header("Accept", "application/json") .header("Accept", "application/json")
.json(&json!({ .json(&json!({
"identityToken": format!("XBL3.0 x={};{}", user_hash, xsts_token) "identityToken": format!("XBL3.0 x={user_hash};{xsts_token}")
})) }))
.send() .send()
.await? .await?
@ -446,7 +446,7 @@ async fn check_ownership(
.get("https://api.minecraftservices.com/entitlements/mcstore") .get("https://api.minecraftservices.com/entitlements/mcstore")
.header( .header(
"Authorization", "Authorization",
format!("Bearer {}", minecraft_access_token), format!("Bearer {minecraft_access_token}"),
) )
.send() .send()
.await? .await?
@ -474,7 +474,7 @@ async fn get_profile(
.get("https://api.minecraftservices.com/minecraft/profile") .get("https://api.minecraftservices.com/minecraft/profile")
.header( .header(
"Authorization", "Authorization",
format!("Bearer {}", minecraft_access_token), format!("Bearer {minecraft_access_token}"),
) )
.send() .send()
.await? .await?

View file

@ -317,7 +317,7 @@ pub fn make_block_states(input: TokenStream) -> TokenStream {
// } // }
let property_variants = properties_map let property_variants = properties_map
.get(property_name) .get(property_name)
.unwrap_or_else(|| panic!("Property '{}' not found", property_name)) .unwrap_or_else(|| panic!("Property '{property_name}' not found"))
.clone(); .clone();
block_properties_vec.push(property_variants); block_properties_vec.push(property_variants);
} }
@ -354,7 +354,7 @@ pub fn make_block_states(input: TokenStream) -> TokenStream {
previous_names.push(property_name.clone()); previous_names.push(property_name.clone());
if let Some(index) = index { if let Some(index) = index {
// property_name.push_str(&format!("_{}", &index.to_string())); // property_name.push_str(&format!("_{}", &index.to_string()));
write!(property_name, "_{}", index).unwrap(); write!(property_name, "_{index}").unwrap();
} }
properties_with_name.push(PropertyWithNameAndDefault { properties_with_name.push(PropertyWithNameAndDefault {
name: Ident::new(&property_name, proc_macro2::Span::call_site()), name: Ident::new(&property_name, proc_macro2::Span::call_site()),
@ -391,7 +391,7 @@ pub fn make_block_states(input: TokenStream) -> TokenStream {
proc_macro2::Span::call_site(), proc_macro2::Span::call_site(),
); );
let block_struct_name = Ident::new( let block_struct_name = Ident::new(
&format!("{}Block", block_name_pascal_case), &format!("{block_name_pascal_case}Block"),
proc_macro2::Span::call_site(), proc_macro2::Span::call_site(),
); );

View file

@ -45,35 +45,35 @@ impl fmt::Debug for BuiltInExceptions {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self { match self {
BuiltInExceptions::DoubleTooSmall { found, min } => { BuiltInExceptions::DoubleTooSmall { found, min } => {
write!(f, "Double must not be less than {}, found {}", min, found) write!(f, "Double must not be less than {min}, found {found}")
} }
BuiltInExceptions::DoubleTooBig { found, max } => { BuiltInExceptions::DoubleTooBig { found, max } => {
write!(f, "Double must not be more than {}, found {}", max, found) write!(f, "Double must not be more than {max}, found {found}")
} }
BuiltInExceptions::FloatTooSmall { found, min } => { BuiltInExceptions::FloatTooSmall { found, min } => {
write!(f, "Float must not be less than {}, found {}", min, found) write!(f, "Float must not be less than {min}, found {found}")
} }
BuiltInExceptions::FloatTooBig { found, max } => { BuiltInExceptions::FloatTooBig { found, max } => {
write!(f, "Float must not be more than {}, found {}", max, found) write!(f, "Float must not be more than {max}, found {found}")
} }
BuiltInExceptions::IntegerTooSmall { found, min } => { BuiltInExceptions::IntegerTooSmall { found, min } => {
write!(f, "Integer must not be less than {}, found {}", min, found) write!(f, "Integer must not be less than {min}, found {found}")
} }
BuiltInExceptions::IntegerTooBig { found, max } => { BuiltInExceptions::IntegerTooBig { found, max } => {
write!(f, "Integer must not be more than {}, found {}", max, found) write!(f, "Integer must not be more than {max}, found {found}")
} }
BuiltInExceptions::LongTooSmall { found, min } => { BuiltInExceptions::LongTooSmall { found, min } => {
write!(f, "Long must not be less than {}, found {}", min, found) write!(f, "Long must not be less than {min}, found {found}")
} }
BuiltInExceptions::LongTooBig { found, max } => { BuiltInExceptions::LongTooBig { found, max } => {
write!(f, "Long must not be more than {}, found {}", max, found) write!(f, "Long must not be more than {max}, found {found}")
} }
BuiltInExceptions::LiteralIncorrect { expected } => { BuiltInExceptions::LiteralIncorrect { expected } => {
write!(f, "Expected literal {}", expected) write!(f, "Expected literal {expected}")
} }
BuiltInExceptions::ReaderExpectedStartOfQuote => { BuiltInExceptions::ReaderExpectedStartOfQuote => {
@ -97,25 +97,25 @@ impl fmt::Debug for BuiltInExceptions {
) )
} }
BuiltInExceptions::ReaderInvalidInt { value } => { BuiltInExceptions::ReaderInvalidInt { value } => {
write!(f, "Invalid Integer '{}'", value) write!(f, "Invalid Integer '{value}'")
} }
BuiltInExceptions::ReaderExpectedInt => { BuiltInExceptions::ReaderExpectedInt => {
write!(f, "Expected Integer") write!(f, "Expected Integer")
} }
BuiltInExceptions::ReaderInvalidLong { value } => { BuiltInExceptions::ReaderInvalidLong { value } => {
write!(f, "Invalid long '{}'", value) write!(f, "Invalid long '{value}'")
} }
BuiltInExceptions::ReaderExpectedLong => { BuiltInExceptions::ReaderExpectedLong => {
write!(f, "Expected long") write!(f, "Expected long")
} }
BuiltInExceptions::ReaderInvalidDouble { value } => { BuiltInExceptions::ReaderInvalidDouble { value } => {
write!(f, "Invalid double '{}'", value) write!(f, "Invalid double '{value}'")
} }
BuiltInExceptions::ReaderExpectedDouble => { BuiltInExceptions::ReaderExpectedDouble => {
write!(f, "Expected double") write!(f, "Expected double")
} }
BuiltInExceptions::ReaderInvalidFloat { value } => { BuiltInExceptions::ReaderInvalidFloat { value } => {
write!(f, "Invalid Float '{}'", value) write!(f, "Invalid Float '{value}'")
} }
BuiltInExceptions::ReaderExpectedFloat => { BuiltInExceptions::ReaderExpectedFloat => {
write!(f, "Expected Float") write!(f, "Expected Float")
@ -124,7 +124,7 @@ impl fmt::Debug for BuiltInExceptions {
write!(f, "Expected bool") write!(f, "Expected bool")
} }
BuiltInExceptions::ReaderExpectedSymbol { symbol } => { BuiltInExceptions::ReaderExpectedSymbol { symbol } => {
write!(f, "Expected '{}'", symbol) write!(f, "Expected '{symbol}'")
} }
BuiltInExceptions::DispatcherUnknownCommand => { BuiltInExceptions::DispatcherUnknownCommand => {
@ -140,7 +140,7 @@ impl fmt::Debug for BuiltInExceptions {
) )
} }
BuiltInExceptions::DispatcherParseException { message } => { BuiltInExceptions::DispatcherParseException { message } => {
write!(f, "Could not parse command: {}", message) write!(f, "Could not parse command: {message}")
} }
} }
} }
@ -148,12 +148,12 @@ impl fmt::Debug for BuiltInExceptions {
impl BuiltInExceptions { impl BuiltInExceptions {
pub fn create(self) -> CommandSyntaxException { pub fn create(self) -> CommandSyntaxException {
let message = Message::from(format!("{:?}", self)); let message = Message::from(format!("{self:?}"));
CommandSyntaxException::create(self, message) CommandSyntaxException::create(self, message)
} }
pub fn create_with_context(self, reader: &StringReader) -> CommandSyntaxException { pub fn create_with_context(self, reader: &StringReader) -> CommandSyntaxException {
let message = Message::from(format!("{:?}", self)); let message = Message::from(format!("{self:?}"));
CommandSyntaxException::new(self, message, reader.string(), reader.cursor()) CommandSyntaxException::new(self, message, reader.string(), reader.cursor())
} }
} }

View file

@ -275,7 +275,7 @@ fn execute_redirected_multiple_times() {
child2.clone().unwrap().nodes[0].range, child2.clone().unwrap().nodes[0].range,
child2.clone().unwrap().range child2.clone().unwrap().range
); );
assert_eq!(child2.clone().unwrap().nodes[0].node, concrete_node); assert_eq!(child2.unwrap().nodes[0].node, concrete_node);
assert_eq!(CommandDispatcher::execute_parsed(parse).unwrap(), 42); assert_eq!(CommandDispatcher::execute_parsed(parse).unwrap(), 42);
} }
@ -406,5 +406,5 @@ fn get_path() {
fn find_node_doesnt_exist() { fn find_node_doesnt_exist() {
let subject = CommandDispatcher::<()>::new(); let subject = CommandDispatcher::<()>::new();
assert_eq!(subject.find_node(&vec!["foo", "bar"]), None) assert_eq!(subject.find_node(&["foo", "bar"]), None)
} }

View file

@ -78,7 +78,7 @@ mod tests {
let u = Uuid::parse_str("6536bfed-8695-48fd-83a1-ecd24cf2a0fd").unwrap(); let u = Uuid::parse_str("6536bfed-8695-48fd-83a1-ecd24cf2a0fd").unwrap();
let mut buf = Vec::new(); let mut buf = Vec::new();
u.write_into(&mut buf).unwrap(); u.write_into(&mut buf).unwrap();
println!("{:?}", buf); println!("{buf:?}");
assert_eq!(buf.len(), 16); assert_eq!(buf.len(), 16);
let u2 = Uuid::read_from(&mut Cursor::new(&buf)).unwrap(); let u2 = Uuid::read_from(&mut Cursor::new(&buf)).unwrap();
assert_eq!(u, u2); assert_eq!(u, u2);

View file

@ -186,7 +186,7 @@ impl<'de> Deserialize<'de> for Component {
nbt nbt
} else { } else {
return Err(de::Error::custom( return Err(de::Error::custom(
format!("Don't know how to turn {} into a Component", json).as_str(), format!("Don't know how to turn {json} into a Component").as_str(),
)); ));
}; };
let _separator = Component::parse_separator(&json).map_err(de::Error::custom)?; let _separator = Component::parse_separator(&json).map_err(de::Error::custom)?;
@ -223,7 +223,7 @@ impl<'de> Deserialize<'de> for Component {
// ok so it's not an object, if it's an array deserialize every item // ok so it's not an object, if it's an array deserialize every item
else if !json.is_array() { else if !json.is_array() {
return Err(de::Error::custom( return Err(de::Error::custom(
format!("Don't know how to turn {} into a Component", json).as_str(), format!("Don't know how to turn {json} into a Component").as_str(),
)); ));
} }
let json_array = json.as_array().unwrap(); let json_array = json.as_array().unwrap();

View file

@ -134,8 +134,8 @@ impl Display for TranslatableComponent {
impl Display for StringOrComponent { impl Display for StringOrComponent {
fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), fmt::Error> { fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), fmt::Error> {
match self { match self {
StringOrComponent::String(s) => write!(f, "{}", s), StringOrComponent::String(s) => write!(f, "{s}"),
StringOrComponent::Component(c) => write!(f, "{}", c), StringOrComponent::Component(c) => write!(f, "{c}"),
} }
} }
} }

View file

@ -230,7 +230,7 @@ impl Client {
} }
}, },
Err(e) => { Err(e) => {
panic!("Error: {:?}", e); panic!("Error: {e:?}");
} }
} }
}; };
@ -300,7 +300,7 @@ impl Client {
if IGNORE_ERRORS { if IGNORE_ERRORS {
continue; continue;
} else { } else {
panic!("Error handling packet: {}", e); panic!("Error handling packet: {e}");
} }
} }
}, },
@ -308,7 +308,7 @@ impl Client {
if IGNORE_ERRORS { if IGNORE_ERRORS {
warn!("{}", e); warn!("{}", e);
match e { match e {
ReadPacketError::FrameSplitter { .. } => panic!("Error: {:?}", e), ReadPacketError::FrameSplitter { .. } => panic!("Error: {e:?}"),
_ => continue, _ => continue,
} }
} else { } else {

View file

@ -20,7 +20,7 @@ pub enum Err {
impl Debug for Err { impl Debug for Err {
fn fmt(&self, f: &mut Formatter) -> Result<(), Error> { fn fmt(&self, f: &mut Formatter) -> Result<(), Error> {
match self { match self {
Err::InvalidDifficulty(s) => write!(f, "Invalid difficulty: {}", s), Err::InvalidDifficulty(s) => write!(f, "Invalid difficulty: {s}"),
} }
} }
} }
@ -52,7 +52,7 @@ impl Difficulty {
2 => Difficulty::NORMAL, 2 => Difficulty::NORMAL,
3 => Difficulty::HARD, 3 => Difficulty::HARD,
// this shouldn't be possible because of the modulo, so panicking is fine // this shouldn't be possible because of the modulo, so panicking is fine
_ => panic!("Unknown difficulty id: {}", id), _ => panic!("Unknown difficulty id: {id}"),
} }
} }

View file

@ -42,7 +42,7 @@ impl Axis {
0 => Axis::X, 0 => Axis::X,
1 => Axis::Y, 1 => Axis::Y,
2 => Axis::Z, 2 => Axis::Z,
_ => panic!("Invalid ordinal {}", ordinal), _ => panic!("Invalid ordinal {ordinal}"),
} }
} }
} }

View file

@ -73,7 +73,7 @@ impl GameType {
"creative" => GameType::CREATIVE, "creative" => GameType::CREATIVE,
"adventure" => GameType::ADVENTURE, "adventure" => GameType::ADVENTURE,
"spectator" => GameType::SPECTATOR, "spectator" => GameType::SPECTATOR,
_ => panic!("Unknown game type name: {}", name), _ => panic!("Unknown game type name: {name}"),
} }
} }
} }

View file

@ -10,10 +10,10 @@ pub enum Error {
impl std::fmt::Display for Error { impl std::fmt::Display for Error {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
match self { match self {
Error::InvalidTagType(id) => write!(f, "Invalid tag type: {}", id), Error::InvalidTagType(id) => write!(f, "Invalid tag type: {id}"),
Error::InvalidTag => write!(f, "Invalid tag"), Error::InvalidTag => write!(f, "Invalid tag"),
Error::WriteError(e) => write!(f, "Write error: {}", e), Error::WriteError(e) => write!(f, "Write error: {e}"),
Error::Utf8Error(e) => write!(f, "Utf8 error: {}", e), Error::Utf8Error(e) => write!(f, "Utf8 error: {e}"),
Error::UnexpectedEof => write!(f, "Unexpected EOF"), Error::UnexpectedEof => write!(f, "Unexpected EOF"),
} }
} }

View file

@ -19,7 +19,7 @@ pub fn box_shape(
max_y: f64, max_y: f64,
max_z: f64, max_z: f64,
) -> VoxelShape { ) -> VoxelShape {
assert!(min_x >= 0., "min_x must be >= 0 but was {}", min_x); assert!(min_x >= 0., "min_x must be >= 0 but was {min_x}");
assert!(min_y >= 0.); assert!(min_y >= 0.);
assert!(min_z >= 0.); assert!(min_z >= 0.);
assert!(max_x >= 0.); assert!(max_x >= 0.);

View file

@ -35,7 +35,7 @@ fn packet_encoder<P: ProtocolPacket + std::fmt::Debug>(
return Err(PacketEncodeError::TooBig { return Err(PacketEncodeError::TooBig {
actual: buf.len(), actual: buf.len(),
maximum: MAXIMUM_UNCOMPRESSED_LENGTH as usize, maximum: MAXIMUM_UNCOMPRESSED_LENGTH as usize,
packet_string: format!("{:?}", packet), packet_string: format!("{packet:?}"),
}); });
} }
Ok(buf) Ok(buf)

View file

@ -76,8 +76,8 @@ pub fn registry(input: TokenStream) -> TokenStream {
let max_id = input.items.len() as u32; let max_id = input.items.len() as u32;
let doc_0 = format!("Transmutes a u32 to a {}.", name); let doc_0 = format!("Transmutes a u32 to a {name}.");
let doc_1 = format!("The `id` should be at most {}.", max_id); let doc_1 = format!("The `id` should be at most {max_id}.");
generated.extend(quote! { generated.extend(quote! {
impl #name { impl #name {
@ -97,7 +97,7 @@ pub fn registry(input: TokenStream) -> TokenStream {
} }
}); });
let doc_0 = format!("Safely transmutes a u32 to a {}.", name); let doc_0 = format!("Safely transmutes a u32 to a {name}.");
generated.extend(quote! { generated.extend(quote! {
impl TryFrom<u32> for #name { impl TryFrom<u32> for #name {

View file

@ -158,7 +158,7 @@ impl Chunk {
} }
pub fn section_index(&self, y: i32, min_y: i32) -> u32 { pub fn section_index(&self, y: i32, min_y: i32) -> u32 {
assert!(y >= min_y, "y ({}) must be at least {}", y, min_y); assert!(y >= min_y, "y ({y}) must be at least {min_y}");
let min_section_index = min_y.div_floor(16); let min_section_index = min_y.div_floor(16);
(y.div_floor(16) - min_section_index) as u32 (y.div_floor(16) - min_section_index) as u32
} }