Skip to content

Commit c3b35f8

Browse files
committed
Update to Rust 1.88 and let chains
1 parent 7539172 commit c3b35f8

File tree

11 files changed

+62
-68
lines changed

11 files changed

+62
-68
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ edition = "2024"
1010
license = "MIT"
1111
publish = false
1212
repository = "https://github.com/ictrobot/aoc-rs"
13-
rust-version = "1.87.0"
13+
rust-version = "1.88.0"
1414

1515
[workspace.lints.clippy]
1616
pedantic = { level = "warn", priority = -1 }

crates/aoc/src/cli/arguments.rs

Lines changed: 17 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -54,29 +54,27 @@ impl Arguments {
5454
}
5555

5656
// Allow using "-" as a positional argument
57-
if option.len() > 1 {
58-
if let Some(option) = option.strip_prefix('-') {
59-
// Short form options
60-
let mut options: Vec<_> = option.chars().collect();
61-
let last = options.pop().unwrap();
62-
for option in options {
63-
result
64-
.handle_short(option, ArgumentValue::None)
65-
.map_err(|e| {
66-
UsageError::InvalidArguments(
67-
format!("option -{option}: {e}").into(),
68-
)
69-
})?;
70-
}
71-
72-
// The last short form option can consume a value
57+
if option.len() > 1
58+
&& let Some(option) = option.strip_prefix('-')
59+
{
60+
// Short form options
61+
let mut options: Vec<_> = option.chars().collect();
62+
let last = options.pop().unwrap();
63+
for option in options {
7364
result
74-
.handle_short(last, ArgumentValue::Available(&mut args))
65+
.handle_short(option, ArgumentValue::None)
7566
.map_err(|e| {
76-
UsageError::InvalidArguments(format!("option -{last}: {e}").into())
67+
UsageError::InvalidArguments(format!("option -{option}: {e}").into())
7768
})?;
78-
continue;
7969
}
70+
71+
// The last short form option can consume a value
72+
result
73+
.handle_short(last, ArgumentValue::Available(&mut args))
74+
.map_err(|e| {
75+
UsageError::InvalidArguments(format!("option -{last}: {e}").into())
76+
})?;
77+
continue;
8078
}
8179

8280
args.push_front(option);

crates/aoc/src/cli/mode/test/manager.rs

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -181,17 +181,15 @@ impl Manager {
181181
let mut max_year = None;
182182
let mut succeeded = 0;
183183
let mut total = 0;
184-
while let Some(&(y, _)) = puzzles.peek() {
185-
if self.puzzles[y].iter().all(|p| p.get_status() == status) {
186-
max_year = Some(y);
187-
for p in &self.puzzles[y] {
188-
succeeded += p.get_succeeded();
189-
total += p.get_case_count();
190-
}
191-
take_while_peeking(&mut puzzles, |&(y2, _)| y == y2).for_each(drop);
192-
} else {
193-
break;
184+
while let Some(&(y, _)) = puzzles.peek()
185+
&& self.puzzles[y].iter().all(|p| p.get_status() == status)
186+
{
187+
max_year = Some(y);
188+
for p in &self.puzzles[y] {
189+
succeeded += p.get_succeeded();
190+
total += p.get_case_count();
194191
}
192+
take_while_peeking(&mut puzzles, |&(y2, _)| y == y2).for_each(drop);
195193
}
196194
if let Some(max_year) = max_year {
197195
if year == max_year {

crates/utils/src/number.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -260,11 +260,9 @@ pub fn is_prime<T: UnsignedInteger>(n: T) -> bool {
260260
}
261261

262262
let mut i = T::from(5);
263-
while let Some(square) = i.checked_mul(i) {
264-
if square > n {
265-
break;
266-
}
267-
263+
while let Some(square) = i.checked_mul(i)
264+
&& square <= n
265+
{
268266
if n % i == T::ZERO || n % (i + T::from(2)) == T::ZERO {
269267
return false;
270268
}

crates/xtask/src/cmd/input.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -133,10 +133,10 @@ fn read_session_token() -> Result<String, String> {
133133
if let Ok(token) = read_to_string(TOKEN_FILE) {
134134
return Ok(token.trim_end().to_string());
135135
}
136-
if let Ok(home) = env::var(HOME_VAR) {
137-
if let Ok(token) = read_to_string(Path::new(&home).join(TOKEN_FILE)) {
138-
return Ok(token.trim_end().to_string());
139-
}
136+
if let Ok(home) = env::var(HOME_VAR)
137+
&& let Ok(token) = read_to_string(Path::new(&home).join(TOKEN_FILE))
138+
{
139+
return Ok(token.trim_end().to_string());
140140
}
141141

142142
Err(format!(

crates/year2016/src/day07.rs

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -58,13 +58,15 @@ impl Day07 {
5858
let (a, b, c) = (line[i], line[i + 1], line[i + 2]);
5959

6060
// Part 1
61-
if let Some(&d) = line.get(i + 3) {
62-
if a != b && a == d && b == c {
63-
if in_brackets {
64-
part1_valid = false;
65-
} else {
66-
part1_match = true;
67-
}
61+
if let Some(&d) = line.get(i + 3)
62+
&& a != b
63+
&& a == d
64+
&& b == c
65+
{
66+
if in_brackets {
67+
part1_valid = false;
68+
} else {
69+
part1_match = true;
6870
}
6971
}
7072

crates/year2018/src/day05.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,11 @@ impl Day05 {
3636
fn react(polymer: impl Iterator<Item = u8>) -> Vec<u8> {
3737
let mut stack = Vec::with_capacity(polymer.size_hint().1.unwrap_or(0));
3838
for b in polymer {
39-
if let Some(last) = stack.last() {
40-
if last ^ b == 32 {
41-
stack.pop();
42-
continue;
43-
}
39+
if let Some(last) = stack.last()
40+
&& last ^ b == 32
41+
{
42+
stack.pop();
43+
continue;
4444
}
4545
stack.push(b);
4646
}

crates/year2024/src/day09.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -93,10 +93,10 @@ impl<'a> Day09<'a> {
9393

9494
// Check for free spaces at least as long as the file before the file's position
9595
for len in file_len..=9 {
96-
if let Some(&pos) = free_positions[len as usize - 1].front() {
97-
if pos < next_pos {
98-
(next_pos, free_len) = (pos, len);
99-
}
96+
if let Some(&pos) = free_positions[len as usize - 1].front()
97+
&& pos < next_pos
98+
{
99+
(next_pos, free_len) = (pos, len);
100100
}
101101
}
102102

crates/year2024/src/day13.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -82,10 +82,10 @@ impl Machine {
8282
return None;
8383
}
8484

85-
if let Ok(count_a) = (det_a / det_denominator).try_into() {
86-
if let Ok(count_b) = (det_b / det_denominator).try_into() {
87-
return Some((count_a, count_b));
88-
}
85+
if let Ok(count_a) = (det_a / det_denominator).try_into()
86+
&& let Ok(count_b) = (det_b / det_denominator).try_into()
87+
{
88+
return Some((count_a, count_b));
8989
}
9090

9191
None

crates/year2024/src/day17.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -111,10 +111,10 @@ impl Day17 {
111111

112112
for x in 0..8 {
113113
let a = base | (x << (pos * 3));
114-
if self.check_pos_matches(a, pos) {
115-
if let Some(result) = self.search(a, pos - 1) {
116-
return Some(result);
117-
}
114+
if self.check_pos_matches(a, pos)
115+
&& let Some(result) = self.search(a, pos - 1)
116+
{
117+
return Some(result);
118118
}
119119
}
120120
None

0 commit comments

Comments
 (0)