From f07cd0dc37a93c9cb4871c578b0c8e59a4a99e4d Mon Sep 17 00:00:00 2001 From: Peter Goodspeed-Niklaus Date: Wed, 18 Nov 2020 13:07:08 +0100 Subject: [PATCH] apply automatic clippy fixes to examples ```sh for ex in exercises/*; do ( cd "$ex" cp example.rs src/lib.rs if [ -f Cargo-example.toml ]; then cp Cargo-example.toml Cargo.toml fi cargo +nightly clippy -Z unstable-options --fix --allow-dirty cp src/lib.rs example.rs git checkout -- src/lib.rs Cargo.toml ) done ``` --- exercises/bowling/example.rs | 2 +- exercises/doubly-linked-list/example.rs | 2 +- exercises/fizzy/example.rs | 2 +- exercises/forth/example.rs | 2 +- exercises/phone-number/example.rs | 2 +- exercises/poker/example.rs | 2 +- exercises/rail-fence-cipher/example.rs | 10 ++++------ 7 files changed, 10 insertions(+), 12 deletions(-) diff --git a/exercises/bowling/example.rs b/exercises/bowling/example.rs index b99beadcb..af7aa50fd 100644 --- a/exercises/bowling/example.rs +++ b/exercises/bowling/example.rs @@ -43,7 +43,7 @@ impl Frame { return self.bonus_score() <= 10; } - if let Some(first) = self.bonus.iter().next() { + if let Some(first) = self.bonus.get(0) { if *first == 10 { self.bonus_score() <= 20 } else { diff --git a/exercises/doubly-linked-list/example.rs b/exercises/doubly-linked-list/example.rs index 44fdd2ab3..a46dd40ea 100644 --- a/exercises/doubly-linked-list/example.rs +++ b/exercises/doubly-linked-list/example.rs @@ -106,7 +106,7 @@ impl LinkedList { impl Drop for LinkedList { fn drop(&mut self) { let mut cursor = self.cursor_front(); - while let Some(_) = cursor.take() {} + while cursor.take().is_some() {} } } diff --git a/exercises/fizzy/example.rs b/exercises/fizzy/example.rs index b166eac5e..8f33da885 100644 --- a/exercises/fizzy/example.rs +++ b/exercises/fizzy/example.rs @@ -120,7 +120,7 @@ mod test { "fizz", "fizz", "fizz", "buzz", "buzz", "16", "8", "4", "2", "1", ]; let got = fizz_buzz() - .apply(collatz_12.into_iter().cloned()) + .apply(collatz_12.iter().cloned()) .collect::>(); assert_eq!(expect, got); } diff --git a/exercises/forth/example.rs b/exercises/forth/example.rs index a1b4de496..5e4d60cd8 100644 --- a/exercises/forth/example.rs +++ b/exercises/forth/example.rs @@ -155,7 +155,7 @@ impl Forth { } fn pop_two(&mut self) -> StackResult<(Value, Value)> { - self.pop().and_then(|b| self.pop().and_then(|a| Ok((a, b)))) + self.pop().and_then(|b| self.pop().map(|a| (a, b))) } fn bin_op(&mut self, op: F) -> ForthResult diff --git a/exercises/phone-number/example.rs b/exercises/phone-number/example.rs index 0a8c108d9..49612212d 100644 --- a/exercises/phone-number/example.rs +++ b/exercises/phone-number/example.rs @@ -5,7 +5,7 @@ pub fn number(user_number: &str) -> Option { if number_len < 10 || number_len > 11 - || (filtered_number.len() == 11 && filtered_number.chars().next().unwrap() != '1') + || (filtered_number.len() == 11 && !filtered_number.starts_with('1')) { return None; } diff --git a/exercises/poker/example.rs b/exercises/poker/example.rs index af9b024f6..2fbac1b0e 100644 --- a/exercises/poker/example.rs +++ b/exercises/poker/example.rs @@ -9,7 +9,7 @@ use counter::Counter; /// the winning hand(s) as were passed in, not reconstructed strings which happen to be equal. pub fn winning_hands<'a>(hands: &[&'a str]) -> Option> { let mut hands = hands - .into_iter() + .iter() .map(|source| Hand::try_from(*source)) .collect::, _>>().ok()?; hands.sort_by(|a, b| a.partial_cmp(b).unwrap_or(Ordering::Less)); diff --git a/exercises/rail-fence-cipher/example.rs b/exercises/rail-fence-cipher/example.rs index 3ceb8dcd6..fa4399f9a 100644 --- a/exercises/rail-fence-cipher/example.rs +++ b/exercises/rail-fence-cipher/example.rs @@ -17,13 +17,11 @@ impl RailFence { *down = false; *rail -= 1; } + } else if *rail > 0 { + *rail -= 1; } else { - if *rail > 0 { - *rail -= 1; - } else { - *down = true; - *rail += 1; - } + *down = true; + *rail += 1; } }