From 9de6c03dfbaa08890b1ec8322a97b7097d4a9d37 Mon Sep 17 00:00:00 2001 From: mat Date: Thu, 27 Oct 2022 21:22:47 -0500 Subject: [PATCH] use variables directly in format strings thanks clippy we love you --- azalea-auth/examples/auth.rs | 2 +- azalea-auth/src/auth.rs | 10 +++--- azalea-block/azalea-block-macros/src/lib.rs | 6 ++-- .../src/exceptions/builtin_exceptions.rs | 34 +++++++++---------- .../tests/command_dispatcher_test.rs | 4 +-- azalea-buf/src/serializable_uuid.rs | 2 +- azalea-chat/src/component.rs | 4 +-- azalea-chat/src/translatable_component.rs | 4 +-- azalea-client/src/client.rs | 6 ++-- azalea-core/src/difficulty.rs | 4 +-- azalea-core/src/direction.rs | 2 +- azalea-core/src/game_type.rs | 2 +- azalea-nbt/src/error.rs | 6 ++-- azalea-physics/src/collision/shape.rs | 2 +- azalea-protocol/src/write.rs | 2 +- .../azalea-registry-macros/src/lib.rs | 6 ++-- azalea-world/src/chunk_storage.rs | 2 +- 17 files changed, 49 insertions(+), 49 deletions(-) diff --git a/azalea-auth/examples/auth.rs b/azalea-auth/examples/auth.rs index 8f7cf7f9..350c5b17 100644 --- a/azalea-auth/examples/auth.rs +++ b/azalea-auth/examples/auth.rs @@ -15,5 +15,5 @@ async fn main() { ) .await .unwrap(); - println!("{:?}", auth_result); + println!("{auth_result:?}"); } diff --git a/azalea-auth/src/auth.rs b/azalea-auth/src/auth.rs index 0d7c7ace..0b043baf 100644 --- a/azalea-auth/src/auth.rs +++ b/azalea-auth/src/auth.rs @@ -336,7 +336,7 @@ async fn auth_with_xbox_live( "SiteName": "user.auth.xboxlive.com", // i thought this was supposed to be d={} but it doesn't work for // me when i add it ?????? - "RpsTicket": format!("{}", access_token) + "RpsTicket": format!("{access_token}") }, "RelyingParty": "http://auth.xboxlive.com", "TokenType": "JWT" @@ -359,7 +359,7 @@ async fn auth_with_xbox_live( // not_after looks like 2020-12-21T19:52:08.4463796Z 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) .timestamp() as u64; Ok(ExpiringValue { @@ -416,7 +416,7 @@ async fn auth_with_minecraft( .post("https://api.minecraftservices.com/authentication/login_with_xbox") .header("Accept", "application/json") .json(&json!({ - "identityToken": format!("XBL3.0 x={};{}", user_hash, xsts_token) + "identityToken": format!("XBL3.0 x={user_hash};{xsts_token}") })) .send() .await? @@ -446,7 +446,7 @@ async fn check_ownership( .get("https://api.minecraftservices.com/entitlements/mcstore") .header( "Authorization", - format!("Bearer {}", minecraft_access_token), + format!("Bearer {minecraft_access_token}"), ) .send() .await? @@ -474,7 +474,7 @@ async fn get_profile( .get("https://api.minecraftservices.com/minecraft/profile") .header( "Authorization", - format!("Bearer {}", minecraft_access_token), + format!("Bearer {minecraft_access_token}"), ) .send() .await? diff --git a/azalea-block/azalea-block-macros/src/lib.rs b/azalea-block/azalea-block-macros/src/lib.rs index 0c226ec6..08bb4fbe 100644 --- a/azalea-block/azalea-block-macros/src/lib.rs +++ b/azalea-block/azalea-block-macros/src/lib.rs @@ -317,7 +317,7 @@ pub fn make_block_states(input: TokenStream) -> TokenStream { // } let property_variants = properties_map .get(property_name) - .unwrap_or_else(|| panic!("Property '{}' not found", property_name)) + .unwrap_or_else(|| panic!("Property '{property_name}' not found")) .clone(); block_properties_vec.push(property_variants); } @@ -354,7 +354,7 @@ pub fn make_block_states(input: TokenStream) -> TokenStream { previous_names.push(property_name.clone()); if let Some(index) = index { // property_name.push_str(&format!("_{}", &index.to_string())); - write!(property_name, "_{}", index).unwrap(); + write!(property_name, "_{index}").unwrap(); } properties_with_name.push(PropertyWithNameAndDefault { 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(), ); let block_struct_name = Ident::new( - &format!("{}Block", block_name_pascal_case), + &format!("{block_name_pascal_case}Block"), proc_macro2::Span::call_site(), ); diff --git a/azalea-brigadier/src/exceptions/builtin_exceptions.rs b/azalea-brigadier/src/exceptions/builtin_exceptions.rs index 09951a03..d95ee237 100755 --- a/azalea-brigadier/src/exceptions/builtin_exceptions.rs +++ b/azalea-brigadier/src/exceptions/builtin_exceptions.rs @@ -45,35 +45,35 @@ impl fmt::Debug for BuiltInExceptions { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { match self { 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 } => { - 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 } => { - 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 } => { - 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 } => { - 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 } => { - 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 } => { - 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 } => { - 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 } => { - write!(f, "Expected literal {}", expected) + write!(f, "Expected literal {expected}") } BuiltInExceptions::ReaderExpectedStartOfQuote => { @@ -97,25 +97,25 @@ impl fmt::Debug for BuiltInExceptions { ) } BuiltInExceptions::ReaderInvalidInt { value } => { - write!(f, "Invalid Integer '{}'", value) + write!(f, "Invalid Integer '{value}'") } BuiltInExceptions::ReaderExpectedInt => { write!(f, "Expected Integer") } BuiltInExceptions::ReaderInvalidLong { value } => { - write!(f, "Invalid long '{}'", value) + write!(f, "Invalid long '{value}'") } BuiltInExceptions::ReaderExpectedLong => { write!(f, "Expected long") } BuiltInExceptions::ReaderInvalidDouble { value } => { - write!(f, "Invalid double '{}'", value) + write!(f, "Invalid double '{value}'") } BuiltInExceptions::ReaderExpectedDouble => { write!(f, "Expected double") } BuiltInExceptions::ReaderInvalidFloat { value } => { - write!(f, "Invalid Float '{}'", value) + write!(f, "Invalid Float '{value}'") } BuiltInExceptions::ReaderExpectedFloat => { write!(f, "Expected Float") @@ -124,7 +124,7 @@ impl fmt::Debug for BuiltInExceptions { write!(f, "Expected bool") } BuiltInExceptions::ReaderExpectedSymbol { symbol } => { - write!(f, "Expected '{}'", symbol) + write!(f, "Expected '{symbol}'") } BuiltInExceptions::DispatcherUnknownCommand => { @@ -140,7 +140,7 @@ impl fmt::Debug for BuiltInExceptions { ) } 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 { pub fn create(self) -> CommandSyntaxException { - let message = Message::from(format!("{:?}", self)); + let message = Message::from(format!("{self:?}")); CommandSyntaxException::create(self, message) } 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()) } } diff --git a/azalea-brigadier/tests/command_dispatcher_test.rs b/azalea-brigadier/tests/command_dispatcher_test.rs index cb33ac73..e30dd2c1 100755 --- a/azalea-brigadier/tests/command_dispatcher_test.rs +++ b/azalea-brigadier/tests/command_dispatcher_test.rs @@ -275,7 +275,7 @@ fn execute_redirected_multiple_times() { child2.clone().unwrap().nodes[0].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); } @@ -406,5 +406,5 @@ fn get_path() { fn find_node_doesnt_exist() { let subject = CommandDispatcher::<()>::new(); - assert_eq!(subject.find_node(&vec!["foo", "bar"]), None) + assert_eq!(subject.find_node(&["foo", "bar"]), None) } diff --git a/azalea-buf/src/serializable_uuid.rs b/azalea-buf/src/serializable_uuid.rs index dc251269..f42eed86 100644 --- a/azalea-buf/src/serializable_uuid.rs +++ b/azalea-buf/src/serializable_uuid.rs @@ -78,7 +78,7 @@ mod tests { let u = Uuid::parse_str("6536bfed-8695-48fd-83a1-ecd24cf2a0fd").unwrap(); let mut buf = Vec::new(); u.write_into(&mut buf).unwrap(); - println!("{:?}", buf); + println!("{buf:?}"); assert_eq!(buf.len(), 16); let u2 = Uuid::read_from(&mut Cursor::new(&buf)).unwrap(); assert_eq!(u, u2); diff --git a/azalea-chat/src/component.rs b/azalea-chat/src/component.rs index 12df03cd..6dd11084 100755 --- a/azalea-chat/src/component.rs +++ b/azalea-chat/src/component.rs @@ -186,7 +186,7 @@ impl<'de> Deserialize<'de> for Component { nbt } else { 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)?; @@ -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 else if !json.is_array() { 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(); diff --git a/azalea-chat/src/translatable_component.rs b/azalea-chat/src/translatable_component.rs index 918c2c42..7c01819b 100644 --- a/azalea-chat/src/translatable_component.rs +++ b/azalea-chat/src/translatable_component.rs @@ -134,8 +134,8 @@ impl Display for TranslatableComponent { impl Display for StringOrComponent { fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), fmt::Error> { match self { - StringOrComponent::String(s) => write!(f, "{}", s), - StringOrComponent::Component(c) => write!(f, "{}", c), + StringOrComponent::String(s) => write!(f, "{s}"), + StringOrComponent::Component(c) => write!(f, "{c}"), } } } diff --git a/azalea-client/src/client.rs b/azalea-client/src/client.rs index 54e08aae..2ca92354 100644 --- a/azalea-client/src/client.rs +++ b/azalea-client/src/client.rs @@ -230,7 +230,7 @@ impl Client { } }, Err(e) => { - panic!("Error: {:?}", e); + panic!("Error: {e:?}"); } } }; @@ -300,7 +300,7 @@ impl Client { if IGNORE_ERRORS { continue; } else { - panic!("Error handling packet: {}", e); + panic!("Error handling packet: {e}"); } } }, @@ -308,7 +308,7 @@ impl Client { if IGNORE_ERRORS { warn!("{}", e); match e { - ReadPacketError::FrameSplitter { .. } => panic!("Error: {:?}", e), + ReadPacketError::FrameSplitter { .. } => panic!("Error: {e:?}"), _ => continue, } } else { diff --git a/azalea-core/src/difficulty.rs b/azalea-core/src/difficulty.rs index 5cc2f9fa..9d504307 100755 --- a/azalea-core/src/difficulty.rs +++ b/azalea-core/src/difficulty.rs @@ -20,7 +20,7 @@ pub enum Err { impl Debug for Err { fn fmt(&self, f: &mut Formatter) -> Result<(), Error> { 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, 3 => Difficulty::HARD, // this shouldn't be possible because of the modulo, so panicking is fine - _ => panic!("Unknown difficulty id: {}", id), + _ => panic!("Unknown difficulty id: {id}"), } } diff --git a/azalea-core/src/direction.rs b/azalea-core/src/direction.rs index dcc9a654..6a29cab9 100644 --- a/azalea-core/src/direction.rs +++ b/azalea-core/src/direction.rs @@ -42,7 +42,7 @@ impl Axis { 0 => Axis::X, 1 => Axis::Y, 2 => Axis::Z, - _ => panic!("Invalid ordinal {}", ordinal), + _ => panic!("Invalid ordinal {ordinal}"), } } } diff --git a/azalea-core/src/game_type.rs b/azalea-core/src/game_type.rs index 635ee6fe..f1f08962 100755 --- a/azalea-core/src/game_type.rs +++ b/azalea-core/src/game_type.rs @@ -73,7 +73,7 @@ impl GameType { "creative" => GameType::CREATIVE, "adventure" => GameType::ADVENTURE, "spectator" => GameType::SPECTATOR, - _ => panic!("Unknown game type name: {}", name), + _ => panic!("Unknown game type name: {name}"), } } } diff --git a/azalea-nbt/src/error.rs b/azalea-nbt/src/error.rs index 308c74c8..d3c5ff44 100755 --- a/azalea-nbt/src/error.rs +++ b/azalea-nbt/src/error.rs @@ -10,10 +10,10 @@ pub enum Error { impl std::fmt::Display for Error { fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { 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::WriteError(e) => write!(f, "Write error: {}", e), - Error::Utf8Error(e) => write!(f, "Utf8 error: {}", e), + Error::WriteError(e) => write!(f, "Write error: {e}"), + Error::Utf8Error(e) => write!(f, "Utf8 error: {e}"), Error::UnexpectedEof => write!(f, "Unexpected EOF"), } } diff --git a/azalea-physics/src/collision/shape.rs b/azalea-physics/src/collision/shape.rs index 59a83c80..e6bc6cf7 100644 --- a/azalea-physics/src/collision/shape.rs +++ b/azalea-physics/src/collision/shape.rs @@ -19,7 +19,7 @@ pub fn box_shape( max_y: f64, max_z: f64, ) -> 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_z >= 0.); assert!(max_x >= 0.); diff --git a/azalea-protocol/src/write.rs b/azalea-protocol/src/write.rs index 9df54f4d..8e56e5fc 100755 --- a/azalea-protocol/src/write.rs +++ b/azalea-protocol/src/write.rs @@ -35,7 +35,7 @@ fn packet_encoder( return Err(PacketEncodeError::TooBig { actual: buf.len(), maximum: MAXIMUM_UNCOMPRESSED_LENGTH as usize, - packet_string: format!("{:?}", packet), + packet_string: format!("{packet:?}"), }); } Ok(buf) diff --git a/azalea-registry/azalea-registry-macros/src/lib.rs b/azalea-registry/azalea-registry-macros/src/lib.rs index 16d8608e..5e4a0f9e 100644 --- a/azalea-registry/azalea-registry-macros/src/lib.rs +++ b/azalea-registry/azalea-registry-macros/src/lib.rs @@ -76,8 +76,8 @@ pub fn registry(input: TokenStream) -> TokenStream { let max_id = input.items.len() as u32; - let doc_0 = format!("Transmutes a u32 to a {}.", name); - let doc_1 = format!("The `id` should be at most {}.", max_id); + let doc_0 = format!("Transmutes a u32 to a {name}."); + let doc_1 = format!("The `id` should be at most {max_id}."); generated.extend(quote! { 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! { impl TryFrom for #name { diff --git a/azalea-world/src/chunk_storage.rs b/azalea-world/src/chunk_storage.rs index 3d2cb613..5bc744c3 100644 --- a/azalea-world/src/chunk_storage.rs +++ b/azalea-world/src/chunk_storage.rs @@ -158,7 +158,7 @@ impl Chunk { } 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); (y.div_floor(16) - min_section_index) as u32 }