From b87aa986345cd80bc44c7fe7bffeb72f5fe0ddb5 Mon Sep 17 00:00:00 2001 From: mo8it Date: Thu, 4 Jul 2024 13:38:35 +0200 Subject: [PATCH] Fix warnings --- exercises/06_move_semantics/move_semantics5.rs | 2 ++ exercises/08_enums/enums2.rs | 3 ++- exercises/10_modules/modules2.rs | 1 + exercises/13_error_handling/errors4.rs | 2 ++ exercises/13_error_handling/errors6.rs | 3 +-- exercises/15_traits/traits3.rs | 2 ++ exercises/19_smart_pointers/rc1.rs | 1 + solutions/01_variables/variables3.rs | 2 ++ solutions/06_move_semantics/move_semantics5.rs | 2 ++ solutions/08_enums/enums2.rs | 3 ++- solutions/10_modules/modules2.rs | 1 + solutions/11_hashmaps/hashmaps3.rs | 4 ++-- solutions/13_error_handling/errors2.rs | 1 + solutions/13_error_handling/errors4.rs | 2 ++ solutions/13_error_handling/errors6.rs | 3 +-- solutions/15_traits/traits3.rs | 2 ++ solutions/19_smart_pointers/rc1.rs | 1 + solutions/23_conversions/try_from_into.rs | 1 + 18 files changed, 28 insertions(+), 8 deletions(-) diff --git a/exercises/06_move_semantics/move_semantics5.rs b/exercises/06_move_semantics/move_semantics5.rs index 6506568..13279ba 100644 --- a/exercises/06_move_semantics/move_semantics5.rs +++ b/exercises/06_move_semantics/move_semantics5.rs @@ -1,3 +1,5 @@ +#![allow(clippy::ptr_arg)] + // TODO: Fix the compiler errors without changing anything except adding or // removing references (the character `&`). diff --git a/exercises/08_enums/enums2.rs b/exercises/08_enums/enums2.rs index 14aa29a..32cf2a6 100644 --- a/exercises/08_enums/enums2.rs +++ b/exercises/08_enums/enums2.rs @@ -1,3 +1,4 @@ +#[allow(dead_code)] #[derive(Debug)] enum Message { // TODO: Define the different variants used below. @@ -5,7 +6,7 @@ enum Message { impl Message { fn call(&self) { - println!("{:?}", self); + println!("{self:?}"); } } diff --git a/exercises/10_modules/modules2.rs b/exercises/10_modules/modules2.rs index 782a70e..02eb80a 100644 --- a/exercises/10_modules/modules2.rs +++ b/exercises/10_modules/modules2.rs @@ -1,6 +1,7 @@ // You can bring module paths into scopes and provide new names for them with // the `use` and `as` keywords. +#[allow(dead_code)] mod delicious_snacks { // TODO: Add the following two `use` statements after fixing them. // use self::fruits::PEAR as ???; diff --git a/exercises/13_error_handling/errors4.rs b/exercises/13_error_handling/errors4.rs index ba01e54..e41d594 100644 --- a/exercises/13_error_handling/errors4.rs +++ b/exercises/13_error_handling/errors4.rs @@ -1,3 +1,5 @@ +#![allow(clippy::comparison_chain)] + #[derive(PartialEq, Debug)] enum CreationError { Negative, diff --git a/exercises/13_error_handling/errors6.rs b/exercises/13_error_handling/errors6.rs index 0652abd..b656c61 100644 --- a/exercises/13_error_handling/errors6.rs +++ b/exercises/13_error_handling/errors6.rs @@ -35,7 +35,7 @@ impl PositiveNonzeroInteger { fn new(value: i64) -> Result { match value { x if x < 0 => Err(CreationError::Negative), - x if x == 0 => Err(CreationError::Zero), + 0 => Err(CreationError::Zero), x => Ok(Self(x as u64)), } } @@ -55,7 +55,6 @@ fn main() { #[cfg(test)] mod test { use super::*; - use std::num::IntErrorKind; #[test] fn test_parse_error() { diff --git a/exercises/15_traits/traits3.rs b/exercises/15_traits/traits3.rs index c244650..2e8969e 100644 --- a/exercises/15_traits/traits3.rs +++ b/exercises/15_traits/traits3.rs @@ -1,3 +1,5 @@ +#![allow(dead_code)] + trait Licensed { // TODO: Add a default implementation for `licensing_info` so that // implementors like the two structs below can share that default behavior diff --git a/exercises/19_smart_pointers/rc1.rs b/exercises/19_smart_pointers/rc1.rs index ecd3438..48e19dc 100644 --- a/exercises/19_smart_pointers/rc1.rs +++ b/exercises/19_smart_pointers/rc1.rs @@ -8,6 +8,7 @@ use std::rc::Rc; #[derive(Debug)] struct Sun; +#[allow(dead_code)] #[derive(Debug)] enum Planet { Mercury(Rc), diff --git a/solutions/01_variables/variables3.rs b/solutions/01_variables/variables3.rs index 7db42a9..b493917 100644 --- a/solutions/01_variables/variables3.rs +++ b/solutions/01_variables/variables3.rs @@ -1,3 +1,5 @@ +#![allow(clippy::needless_late_init)] + fn main() { // Reading uninitialized variables isn't allowed in Rust! // Therefore, we need to assign a value first. diff --git a/solutions/06_move_semantics/move_semantics5.rs b/solutions/06_move_semantics/move_semantics5.rs index 1b3ca4e..678ec97 100644 --- a/solutions/06_move_semantics/move_semantics5.rs +++ b/solutions/06_move_semantics/move_semantics5.rs @@ -1,3 +1,5 @@ +#![allow(clippy::ptr_arg)] + fn main() { let data = "Rust is great!".to_string(); diff --git a/solutions/08_enums/enums2.rs b/solutions/08_enums/enums2.rs index 13175dd..b19394c 100644 --- a/solutions/08_enums/enums2.rs +++ b/solutions/08_enums/enums2.rs @@ -1,3 +1,4 @@ +#[allow(dead_code)] #[derive(Debug)] enum Message { Move { x: i64, y: i64 }, @@ -8,7 +9,7 @@ enum Message { impl Message { fn call(&self) { - println!("{:?}", self); + println!("{self:?}"); } } diff --git a/solutions/10_modules/modules2.rs b/solutions/10_modules/modules2.rs index 55c316d..298d76e 100644 --- a/solutions/10_modules/modules2.rs +++ b/solutions/10_modules/modules2.rs @@ -1,3 +1,4 @@ +#[allow(dead_code)] mod delicious_snacks { // Added `pub` and used the expected alias after `as`. pub use self::fruits::PEAR as fruit; diff --git a/solutions/11_hashmaps/hashmaps3.rs b/solutions/11_hashmaps/hashmaps3.rs index f4059bb..54f480b 100644 --- a/solutions/11_hashmaps/hashmaps3.rs +++ b/solutions/11_hashmaps/hashmaps3.rs @@ -28,13 +28,13 @@ fn build_scores_table(results: &str) -> HashMap<&str, Team> { let team_2_score: u8 = split_iterator.next().unwrap().parse().unwrap(); // Insert the default with zeros if a team doesn't exist yet. - let mut team_1 = scores.entry(team_1_name).or_insert_with(|| Team::default()); + let team_1 = scores.entry(team_1_name).or_insert_with(Team::default); // Update the values. team_1.goals_scored += team_1_score; team_1.goals_conceded += team_2_score; // Similarely for the second team. - let mut team_2 = scores.entry(team_2_name).or_insert_with(|| Team::default()); + let team_2 = scores.entry(team_2_name).or_insert_with(Team::default); team_2.goals_scored += team_2_score; team_2.goals_conceded += team_1_score; } diff --git a/solutions/13_error_handling/errors2.rs b/solutions/13_error_handling/errors2.rs index f652ecb..0597c8c 100644 --- a/solutions/13_error_handling/errors2.rs +++ b/solutions/13_error_handling/errors2.rs @@ -16,6 +16,7 @@ use std::num::ParseIntError; +#[allow(unused_variables)] fn total_cost(item_quantity: &str) -> Result { let processing_fee = 1; let cost_per_item = 5; diff --git a/solutions/13_error_handling/errors4.rs b/solutions/13_error_handling/errors4.rs index c43f493..f4d39bf 100644 --- a/solutions/13_error_handling/errors4.rs +++ b/solutions/13_error_handling/errors4.rs @@ -1,3 +1,5 @@ +#![allow(clippy::comparison_chain)] + #[derive(PartialEq, Debug)] enum CreationError { Negative, diff --git a/solutions/13_error_handling/errors6.rs b/solutions/13_error_handling/errors6.rs index 70680cf..429d3ea 100644 --- a/solutions/13_error_handling/errors6.rs +++ b/solutions/13_error_handling/errors6.rs @@ -36,7 +36,7 @@ impl PositiveNonzeroInteger { fn new(value: i64) -> Result { match value { x if x < 0 => Err(CreationError::Negative), - x if x == 0 => Err(CreationError::Zero), + 0 => Err(CreationError::Zero), x => Ok(Self(x as u64)), } } @@ -57,7 +57,6 @@ fn main() { #[cfg(test)] mod test { use super::*; - use std::num::IntErrorKind; #[test] fn test_parse_error() { diff --git a/solutions/15_traits/traits3.rs b/solutions/15_traits/traits3.rs index 3d8ec85..747d919 100644 --- a/solutions/15_traits/traits3.rs +++ b/solutions/15_traits/traits3.rs @@ -1,3 +1,5 @@ +#![allow(dead_code)] + trait Licensed { fn licensing_info(&self) -> String { "Default license".to_string() diff --git a/solutions/19_smart_pointers/rc1.rs b/solutions/19_smart_pointers/rc1.rs index c0a41ab..512eb9c 100644 --- a/solutions/19_smart_pointers/rc1.rs +++ b/solutions/19_smart_pointers/rc1.rs @@ -8,6 +8,7 @@ use std::rc::Rc; #[derive(Debug)] struct Sun; +#[allow(dead_code)] #[derive(Debug)] enum Planet { Mercury(Rc), diff --git a/solutions/23_conversions/try_from_into.rs b/solutions/23_conversions/try_from_into.rs index acb7721..ee802eb 100644 --- a/solutions/23_conversions/try_from_into.rs +++ b/solutions/23_conversions/try_from_into.rs @@ -4,6 +4,7 @@ // type itself. You can read more about it in the documentation: // https://doc.rust-lang.org/std/convert/trait.TryFrom.html +#![allow(clippy::useless_vec)] use std::convert::{TryFrom, TryInto}; #[derive(Debug, PartialEq)]