Skip to content

Commit a43985e

Browse files
authored
Merge pull request #1623 from remlse/clippy-warnings
fix new clippy and shellcheck errors
2 parents aa6b295 + e413f3c commit a43985e

File tree

119 files changed

+198
-348
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

119 files changed

+198
-348
lines changed

_test/count_ignores.sh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,12 @@ for e in "$repo"/exercises/*/*; do
2525
done
2626
want_ignores=$((total_tests - 1))
2727
if [ "$total_ignores" != "$want_ignores" ]; then
28+
# ShellCheck wants us to use printf,
29+
# but there are no other uses of printf in this repo,
30+
# so printf hasn't been tested to work yet.
31+
# (We would not be opposed to using printf and removing this disable;
32+
# we just haven't tested it to confirm it works yet).
33+
# shellcheck disable=SC2028
2834
echo "\033[1;31m$e: Has $total_tests tests and $total_ignores ignores (should be $want_ignores)\033[0m"
2935
exitcode=1
3036
fi

bin/test-exercise

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ done
9292
# run tests from within exercise directory
9393
# (use subshell so we auto-reset to current pwd after)
9494
(
95-
cd $exercise
95+
cd "$exercise"
9696
if [ -n "$CLIPPY" ]; then
9797
# Consider any Clippy to be an error in tests only.
9898
# For now, not the example solutions since they have many Clippy warnings,

concepts/destructuring/about.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ struct ArabianNights {
3232
let teller = ArabianNights { name: "Scheherazade".into(), stories: 1001 };
3333
{
3434
let ArabianNights { name, stories } = teller;
35-
println!("{} told {} stories", name, stories);
35+
println!("{name} told {stories} stories");
3636
}
3737
```
3838

@@ -42,7 +42,7 @@ The `..` operator can be used to ignore some fields when destructuring:
4242

4343
```rust
4444
let ArabianNights { name, .. } = teller;
45-
println!("{} survived by her wits", name);
45+
println!("{name} survived by her wits");
4646
```
4747

4848
## Conditional Destructuring
@@ -51,6 +51,6 @@ Destructuring structs and tuples is infallible. However, enums can also be destr
5151

5252
```rust
5353
if let Some(foo) = foo {
54-
println!("{:?}", foo);
54+
println!("{foo:?}");
5555
}
5656
```

concepts/fold/about.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ Once the iterator drains, the final value of the accumulator is returned.
1212
```rust
1313
pub fn main() {
1414
let even_sum = (1..=10).fold(0, |acc, num| if num % 2 == 0 { acc + num } else { acc });
15-
println!("{:?}", even_sum);
15+
println!("{even_sum:?}");
1616
}
1717
```
1818

@@ -39,7 +39,7 @@ pub fn giant_grunts(initial: char) -> String {
3939

4040
pub fn main() {
4141
let song = giant_grunts('F');
42-
println!("{:?}", song);
42+
println!("{song:?}");
4343
}
4444
```
4545

concepts/functions/about.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ In the following example the function takes in one parameter of type `i32`, bind
2323

2424
```rust
2525
fn print_integer(value: i32) {
26-
println!("{:?}", value);
26+
println!("{value:?}");
2727
}
2828
```
2929

concepts/hashmap/about.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ Other than the indexing operator, there are two other ways of accessing values s
2525

2626
```rust
2727
if let Some(blue_score) = scores.get("Blue") {
28-
println!("Blue scored: {} \n", blue_score);
28+
println!("Blue scored: {blue_score} \n");
2929
}
3030
```
3131

@@ -41,7 +41,7 @@ for vote in votes {
4141
*count += 1;
4242
}
4343

44-
println!("{:#?}", vote_counter);
44+
println!("{vote_counter:#?}");
4545
```
4646

4747
This API makes certain common access patterns very convenient; it has an entire concept (Entry API) dedicated to it.

concepts/iterators/introduction.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,6 @@ assert_eq!(None, iter.next());
2323

2424
// Loop over iterators with built-in methods, such as `map` and `collect`
2525
let w: HashMap<_, _> = v.into_iter().map(|x| (x, x + 1)).collect();
26-
println!("{:?}", w);
26+
println!("{w:?}");
2727
// => {1: 2, 0: 1, 2: 3}
28-
```
28+
```

concepts/loops/about.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ fn main() {
3636
let a = [10, 20, 30, 40, 50];
3737

3838
for x in a {
39-
println!("the value is: {}", x);
39+
println!("the value is: {x}");
4040
}
4141
}
4242
```
@@ -46,7 +46,7 @@ Ranges are iterators too, which makes iterating through them with the `for` loop
4646
```rust
4747
fn main() {
4848
for x in 0..10 {
49-
println!("the value is: {}", x);
49+
println!("the value is: {x}");
5050
}
5151
}
5252
```

concepts/match-basics/about.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ fn ordinal(n: u32) -> String {
3636
3 => "rd",
3737
_ => "th",
3838
};
39-
format!("{}{}", n, ordinal)
39+
format!("{n}{ordinal}")
4040
}
4141
```
4242

@@ -105,7 +105,7 @@ impl<E: std::fmt::Display> OrLog for Result<(), E> {
105105
// discard Ok results
106106
Ok(()) => {},
107107
// log errors
108-
Err(err) => println!("ERROR: {}", err),
108+
Err(err) => println!("ERROR: {err}"),
109109
}
110110
}
111111
}

concepts/references/about.md

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,13 @@ For example:
77
fn log(msg: String) { // msg takes ownership of the value passed to it
88
let formatted_datetime = String::new();
99
// code to format current datetime snipped
10-
println!("{} at {}", msg, formatted_datetime);
10+
println!("{msg} at {formatted_datetime}");
1111
} // msg is dropped here
1212

1313
pub fn main() {
1414
let my_string = "Something happened".to_string();
1515
log(my_string); // passing my_string transfers ownership of its value to msg
16-
//println!("{:?}", my_string); // uncommenting this line will error because my_string's value has been dropped while owned by msg
16+
//println!("{my_string:?}"); // uncommenting this line will error because my_string's value has been dropped while owned by msg
1717
}
1818
```
1919

@@ -30,13 +30,13 @@ for the duration of that function.
3030
fn log(msg: &String) { //msg is defined as a reference with an ampersand
3131
let formatted_datetime: String;
3232
// code to format current datetime snipped
33-
println!("{} at {}", msg, formatted_datetime);
33+
println!("{msg} at {formatted_datetime}");
3434
}
3535

3636
pub fn main() {
3737
let my_string = "Something happened".to_string();
3838
log(&my_string); // my_string is passed as a reference with an ampersand
39-
println!("{:?}", my_string);
39+
println!("{my_string:?}");
4040
}
4141
```
4242

@@ -119,9 +119,9 @@ fn add_five(counter: &mut i32) { //counter is defined as a mutable reference
119119

120120
pub fn main() {
121121
let mut my_count = 0; // my_count must be defined as mutable
122-
println!("{:?}", my_count);
122+
println!("{my_count:?}");
123123
add_five(&mut my_count); // my_count is passed as a mutable reference
124-
println!("{:?}", my_count);
124+
println!("{my_count:?}");
125125
}
126126
```
127127

@@ -138,11 +138,11 @@ fn add_five(counter: &mut i32) {
138138

139139
pub fn main() {
140140
let mut my_count = 0;
141-
println!("{:?}", my_count);
141+
println!("{my_count:?}");
142142
let mut my_count2 = &mut my_count; // first mutable reference to my_count
143143
add_five(&mut my_count); // this errors because my_count's mutable borrow by my_count2 will be used on the next line
144144
add_five(my_count2);
145-
println!("{:?}", my_count);
145+
println!("{my_count:?}");
146146
}
147147
```
148148

@@ -155,11 +155,11 @@ fn add_five(counter: &mut i32) {
155155

156156
pub fn main() {
157157
let mut my_count = 0;
158-
println!("{:?}", my_count);
158+
println!("{my_count:?}");
159159
let mut my_count2 = &mut my_count; // first mutable reference to my_count
160160
add_five(my_count2); // my_count2's borrow of my_count is not used afer this point
161161
add_five(&mut my_count); // compiler allows second mutable borrow of my_count
162-
println!("{:?}", my_count); // because it does not conflict with first mutable borrow
162+
println!("{my_count:?}"); // because it does not conflict with first mutable borrow
163163
}
164164
```
165165

0 commit comments

Comments
 (0)