Skip to content

Commit b9e170c

Browse files
committed
clippy fix
1 parent 479b077 commit b9e170c

File tree

107 files changed

+430
-503
lines changed

Some content is hidden

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

107 files changed

+430
-503
lines changed

src/aoc/cli.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ const ARG_VERSION: &str = "--version";
1414

1515
/// The main CLI runner.
1616
pub fn run() -> ExitCode {
17-
println!("{}\n", MSG_TITLE);
17+
println!("{MSG_TITLE}\n");
1818
let args = env::args().collect::<Vec<_>>();
1919
match parse_args(&args) {
2020
Err(msg) => {
@@ -25,7 +25,7 @@ pub fn run() -> ExitCode {
2525
if msg == ARG_HELP {
2626
return ExitCode::SUCCESS;
2727
}
28-
println!("{ANSI_RED_INV}[ERROR]{ANSI_RESET} {}\n", msg);
28+
println!("{ANSI_RED_INV}[ERROR]{ANSI_RESET} {msg}\n");
2929
ExitCode::from(2)
3030
}
3131
Ok((year, day)) => {

src/aoc/runner.rs

Lines changed: 17 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -92,34 +92,19 @@ pub fn run_puzzles(year: Option<usize>, day: Option<usize>, parallel: bool) -> b
9292
}
9393
let season = puzzle_list[idx].0.year;
9494
if season != prev_season {
95-
println!(
96-
"======= {} ===================================================",
97-
season
98-
);
95+
println!("======= {season} ===================================================");
9996
}
10097
prev_season = season;
101-
print!("{}", message);
98+
print!("{message}");
10299
}
103100
let msg_skip_fail = if count_skipped_puzzles > 0 && count_failed_puzzles > 0 {
104101
format!(
105-
" ({}{}{} skipped, {}{}{} failed)",
106-
ANSI_YELLOW,
107-
count_skipped_puzzles,
108-
ANSI_RESET,
109-
ANSI_RED,
110-
count_failed_puzzles,
111-
ANSI_RESET
102+
" ({ANSI_YELLOW}{count_skipped_puzzles}{ANSI_RESET} skipped, {ANSI_RED}{count_failed_puzzles}{ANSI_RESET} failed)"
112103
)
113104
} else if count_skipped_puzzles > 0 {
114-
format!(
115-
" ({}{}{} skipped)",
116-
ANSI_YELLOW, count_skipped_puzzles, ANSI_RESET
117-
)
105+
format!(" ({ANSI_YELLOW}{count_skipped_puzzles}{ANSI_RESET} skipped)")
118106
} else if count_failed_puzzles > 0 {
119-
format!(
120-
" ({}{}{} failed)",
121-
ANSI_RED, count_failed_puzzles, ANSI_RESET
122-
)
107+
format!(" ({ANSI_RED}{count_failed_puzzles}{ANSI_RESET} failed)")
123108
} else {
124109
String::new()
125110
};
@@ -142,7 +127,7 @@ pub fn run_puzzles(year: Option<usize>, day: Option<usize>, parallel: bool) -> b
142127
MSG_FAIL_TOTAL
143128
};
144129
if count_puzzles > 0 {
145-
println!("{}\n", msg);
130+
println!("{msg}\n");
146131
}
147132
all_passed
148133
}
@@ -155,7 +140,7 @@ pub fn run_puzzle(puzzle: &PuzzleMetaData, solve: Solver, to_skip: bool) -> (boo
155140
let mut all_passed = true;
156141
let mut all_message = String::new();
157142
if to_skip {
158-
all_message = format!("{}\n", MSG_SKIP);
143+
all_message = format!("{MSG_SKIP}\n");
159144
} else {
160145
let count_examples = puzzle.example_solutions.len();
161146
let mut cases = (1..=count_examples).collect::<Vec<_>>();
@@ -228,7 +213,7 @@ pub fn run_case(puzzle: &PuzzleMetaData, solve: Solver, case: usize) -> (bool, S
228213
} else {
229214
all_passed = false;
230215
pre_msg = MSG_FAIL;
231-
ans_msg = format!("{ANSI_YELLOW}{}{ANSI_RESET}", ans_case);
216+
ans_msg = format!("{ANSI_YELLOW}{ans_case}{ANSI_RESET}");
232217
post_msg = format!(
233218
"{}[expected: {}]",
234219
" ".repeat(20 - min(20, ans_case.to_string().len())),
@@ -244,15 +229,10 @@ pub fn run_case(puzzle: &PuzzleMetaData, solve: Solver, case: usize) -> (bool, S
244229
ans_msg = format!("{ANSI_YELLOW}n/a{ANSI_RESET}");
245230
}
246231
if case == 0 {
247-
all_message += &format!(
248-
"{} Puzzle part #{} : {}{}\n",
249-
pre_msg, part, ans_msg, post_msg
250-
);
232+
all_message += &format!("{pre_msg} Puzzle part #{part} : {ans_msg}{post_msg}\n");
251233
} else {
252-
all_message += &format!(
253-
"{} Example #{} part #{} : {}{}\n",
254-
pre_msg, case, part, ans_msg, post_msg
255-
);
234+
all_message +=
235+
&format!("{pre_msg} Example #{case} part #{part} : {ans_msg}{post_msg}\n");
256236
}
257237
}
258238
(all_passed, all_message)
@@ -270,9 +250,9 @@ fn get_plural(item: usize) -> String {
270250
// ------------------------------------------------------------
271251
fn get_case_error(case: usize, e: PuzzleError) -> String {
272252
if case == 0 {
273-
format!("{MSG_FAIL} Puzzle : {:?}\n", e)
253+
format!("{MSG_FAIL} Puzzle : {e:?}\n")
274254
} else {
275-
format!("{MSG_FAIL} Example #{} : {:?}\n", case, e)
255+
format!("{MSG_FAIL} Example #{case} : {e:?}\n")
276256
}
277257
}
278258

@@ -292,7 +272,7 @@ fn get_expected<'a>(puzzle: &'a PuzzleMetaData, case: usize) -> PuzzleExpected<'
292272
/// * `case == 1, 2, ...` for example inputs
293273
pub fn read_input(puzzle: &PuzzleMetaData, case: usize) -> Result<String, PuzzleError> {
294274
if case > puzzle.example_solutions.len() {
295-
Err(format!("missing expected solution for example #{}", case))?;
275+
Err(format!("missing expected solution for example #{case}"))?;
296276
}
297277
let input_path = if case == 0 {
298278
format!(
@@ -306,7 +286,7 @@ pub fn read_input(puzzle: &PuzzleMetaData, case: usize) -> Result<String, Puzzle
306286
)
307287
};
308288
let input = fs::read_to_string(path::Path::new(&input_path))
309-
.map_err(|_| format!("cannot read input file: {}", input_path))?;
289+
.map_err(|_| format!("cannot read input file: {input_path}"))?;
310290
if input.is_empty() {
311291
Err("empty input")?;
312292
}
@@ -370,15 +350,12 @@ pub mod tests {
370350

371351
/// Similar to `test_invalid()`, but also checks if the error message contains the givent string slice.
372352
pub fn test_invalid_msg(input: PuzzleInput, solve: Solver, msg: &str) {
373-
let result = solve(&input);
353+
let result = solve(input);
374354
assert!(result.is_err());
375355
if !msg.is_empty() {
376356
let e = result.unwrap_err().0;
377357
if !e.contains(msg) {
378-
eprintln!(
379-
"*** Error message does not match the expected: {} != {}",
380-
e, msg
381-
);
358+
eprintln!("*** Error message does not match the expected: {e} != {msg}");
382359
}
383360
assert!(e.contains(msg));
384361
}

src/aoc2015/aoc2015day01.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,7 @@ pub fn solve(input: PuzzleInput) -> PuzzleResult {
2323
for c in line.chars() {
2424
if c != '(' && c != ')' {
2525
Err(format!(
26-
"input must contain only `(` or `)` chars, found `{}`",
27-
c
26+
"input must contain only `(` or `)` chars, found `{c}`"
2827
))?;
2928
}
3029
}
@@ -69,11 +68,11 @@ mod tests {
6968

7069
#[test]
7170
fn invalid_single_line() {
72-
test_invalid_msg(&[&"(())", &"()"], solve, "input must have a single line");
71+
test_invalid_msg(&["(())", "()"], solve, "input must have a single line");
7372
}
7473

7574
#[test]
7675
fn invalid_only_parentheses() {
77-
test_invalid_msg(&[&"(a)"], solve, "input must contain only `(` or `)`");
76+
test_invalid_msg(&["(a)"], solve, "input must contain only `(` or `)`");
7877
}
7978
}

src/aoc2015/aoc2015day02.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ pub fn solve(input: PuzzleInput) -> PuzzleResult {
2222
line.split('x')
2323
.map(|x| {
2424
x.parse::<ItemType>()
25-
.map_err(|_| format!("input must contain only integers, found `{}`", x))
25+
.map_err(|_| format!("input must contain only integers, found `{x}`"))
2626
})
2727
.collect::<Result<Vec<_>, _>>()
2828
})
@@ -71,7 +71,7 @@ mod tests {
7171
#[test]
7272
fn invalid_only_2d_array_of_ints() {
7373
test_invalid_msg(
74-
&[&"1x2x3", &"4xax6"],
74+
&["1x2x3", "4xax6"],
7575
solve,
7676
"input must contain only integers",
7777
);
@@ -80,7 +80,7 @@ mod tests {
8080
#[test]
8181
fn invalid_only_triplets_of_ints() {
8282
test_invalid_msg(
83-
&[&"1x2x3x4"],
83+
&["1x2x3x4"],
8484
solve,
8585
"input must contain 3 integers per line",
8686
);

src/aoc2015/aoc2015day03.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ pub fn delta(dir: char) -> Result<(i32, i32), PuzzleError> {
5858
'v' => Ok((0, 1)),
5959
'<' => Ok((-1, 0)),
6060
'^' => Ok((0, -1)),
61-
_ => Err(format!("direction must be >v<^, found `{}`", dir))?,
61+
_ => Err(format!("direction must be >v<^, found `{dir}`"))?,
6262
}
6363
}
6464

@@ -85,11 +85,11 @@ mod tests {
8585

8686
#[test]
8787
fn invalid_single_line() {
88-
test_invalid(&[&"<>", &"><"], solve);
88+
test_invalid(&["<>", "><"], solve);
8989
}
9090

9191
#[test]
9292
fn invalid_only_directions() {
93-
test_invalid(&[&"<a>"], solve);
93+
test_invalid(&["<a>"], solve);
9494
}
9595
}

src/aoc2015/aoc2015day04.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,6 @@ mod tests {
6868

6969
#[test]
7070
fn invalid_single_line() {
71-
test_invalid(&[&"a", &"b"], solve);
71+
test_invalid(&["a", "b"], solve);
7272
}
7373
}

src/aoc2015/aoc2015day06.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -136,21 +136,21 @@ mod tests {
136136

137137
#[test]
138138
fn invalid_number_of_words() {
139-
test_invalid(&[&"a"], solve);
139+
test_invalid(&["a"], solve);
140140
}
141141

142142
#[test]
143143
fn invalid_position_number() {
144-
test_invalid(&[&"turn on 0,0,1 through 0,0"], solve);
144+
test_invalid(&["turn on 0,0,1 through 0,0"], solve);
145145
}
146146

147147
#[test]
148148
fn invalid_positions_must_be_integers() {
149-
test_invalid(&[&"turn on 0,a through 0,0"], solve);
149+
test_invalid(&["turn on 0,a through 0,0"], solve);
150150
}
151151

152152
#[test]
153153
fn invalid_verb() {
154-
test_invalid(&[&"discard 0,0 through 0,0"], solve);
154+
test_invalid(&["discard 0,0 through 0,0"], solve);
155155
}
156156
}

src/aoc2015/aoc2015day07.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ impl Circuit {
107107
let gate = self
108108
.gates
109109
.get(id)
110-
.ok_or(format!("invalid wire id `{}`", id))?;
110+
.ok_or(format!("invalid wire id `{id}`"))?;
111111
if let Some(x) = gate.value {
112112
return Ok(x);
113113
}
@@ -132,7 +132,7 @@ impl Circuit {
132132
"OR" => a | b,
133133
"LSHIFT" => a << b,
134134
"RSHIFT" => a >> b,
135-
_ => Err(format!("invalid operator `{}`", operator))?,
135+
_ => Err(format!("invalid operator `{operator}`"))?,
136136
}
137137
}
138138
};
@@ -160,26 +160,26 @@ mod tests {
160160

161161
#[test]
162162
fn invalid_must_have_arrow() {
163-
test_invalid(&[&"a"], solve);
163+
test_invalid(&["a"], solve);
164164
}
165165

166166
#[test]
167167
fn invalid_too_many_operands() {
168-
test_invalid(&[&"x LSHIFT 2 3 -> y"], solve);
168+
test_invalid(&["x LSHIFT 2 3 -> y"], solve);
169169
}
170170

171171
#[test]
172172
fn invalid_unary_operator() {
173-
test_invalid(&[&"AND x -> y"], solve);
173+
test_invalid(&["AND x -> y"], solve);
174174
}
175175

176176
#[test]
177177
fn invalid_binary_operator() {
178-
test_invalid(&[&"x XOR y -> z"], solve);
178+
test_invalid(&["x XOR y -> z"], solve);
179179
}
180180

181181
#[test]
182182
fn invalid_wire_id() {
183-
test_invalid(&[&"x AND 1 -> y"], solve);
183+
test_invalid(&["x AND 1 -> y"], solve);
184184
}
185185
}

src/aoc2015/aoc2015day09.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -111,21 +111,21 @@ mod tests {
111111

112112
#[test]
113113
fn invalid_missing_equal_sign() {
114-
test_invalid(&[&"a"], solve);
114+
test_invalid(&["a"], solve);
115115
}
116116

117117
#[test]
118118
fn invalid_missing_to() {
119-
test_invalid(&[&"a = 1"], solve);
119+
test_invalid(&["a = 1"], solve);
120120
}
121121

122122
#[test]
123123
fn invalid_distance_must_be_integer() {
124-
test_invalid(&[&"a to b = c"], solve);
124+
test_invalid(&["a to b = c"], solve);
125125
}
126126

127127
#[test]
128128
fn invalid_source_and_destination_must_be_different() {
129-
test_invalid(&[&"a to a = 1"], solve);
129+
test_invalid(&["a to a = 1"], solve);
130130
}
131131
}

src/aoc2015/aoc2015day10.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,6 @@ mod tests {
7272

7373
#[test]
7474
fn invalid_single_line() {
75-
test_invalid(&[&"a", &"b"], solve);
75+
test_invalid(&["a", "b"], solve);
7676
}
7777
}

0 commit comments

Comments
 (0)