Skip to content

Commit f58afa9

Browse files
authored
apply automatic clippy fixes to examples (#1022)
```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 ```
1 parent f6e3e66 commit f58afa9

File tree

7 files changed

+10
-12
lines changed

7 files changed

+10
-12
lines changed

exercises/bowling/example.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ impl Frame {
4343
return self.bonus_score() <= 10;
4444
}
4545

46-
if let Some(first) = self.bonus.iter().next() {
46+
if let Some(first) = self.bonus.get(0) {
4747
if *first == 10 {
4848
self.bonus_score() <= 20
4949
} else {

exercises/doubly-linked-list/example.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ impl<T> LinkedList<T> {
106106
impl<T> Drop for LinkedList<T> {
107107
fn drop(&mut self) {
108108
let mut cursor = self.cursor_front();
109-
while let Some(_) = cursor.take() {}
109+
while cursor.take().is_some() {}
110110
}
111111
}
112112

exercises/fizzy/example.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ mod test {
120120
"fizz", "fizz", "fizz", "buzz", "buzz", "16", "8", "4", "2", "1",
121121
];
122122
let got = fizz_buzz()
123-
.apply(collatz_12.into_iter().cloned())
123+
.apply(collatz_12.iter().cloned())
124124
.collect::<Vec<_>>();
125125
assert_eq!(expect, got);
126126
}

exercises/forth/example.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ impl Forth {
155155
}
156156

157157
fn pop_two(&mut self) -> StackResult<(Value, Value)> {
158-
self.pop().and_then(|b| self.pop().and_then(|a| Ok((a, b))))
158+
self.pop().and_then(|b| self.pop().map(|a| (a, b)))
159159
}
160160

161161
fn bin_op<F>(&mut self, op: F) -> ForthResult

exercises/phone-number/example.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ pub fn number(user_number: &str) -> Option<String> {
55

66
if number_len < 10
77
|| number_len > 11
8-
|| (filtered_number.len() == 11 && filtered_number.chars().next().unwrap() != '1')
8+
|| (filtered_number.len() == 11 && !filtered_number.starts_with('1'))
99
{
1010
return None;
1111
}

exercises/poker/example.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use counter::Counter;
99
/// the winning hand(s) as were passed in, not reconstructed strings which happen to be equal.
1010
pub fn winning_hands<'a>(hands: &[&'a str]) -> Option<Vec<&'a str>> {
1111
let mut hands = hands
12-
.into_iter()
12+
.iter()
1313
.map(|source| Hand::try_from(*source))
1414
.collect::<Result<Vec<_>, _>>()
1515
.ok()?;

exercises/rail-fence-cipher/example.rs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,11 @@ impl RailFence {
1717
*down = false;
1818
*rail -= 1;
1919
}
20+
} else if *rail > 0 {
21+
*rail -= 1;
2022
} else {
21-
if *rail > 0 {
22-
*rail -= 1;
23-
} else {
24-
*down = true;
25-
*rail += 1;
26-
}
23+
*down = true;
24+
*rail += 1;
2725
}
2826
}
2927

0 commit comments

Comments
 (0)