Skip to content

Commit 8e01d85

Browse files
committed
Use unreachable! instead of panic!
1 parent c537c02 commit 8e01d85

File tree

6 files changed

+12
-12
lines changed

6 files changed

+12
-12
lines changed

rust-aoc/src/year2015/day201501.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ fn solve_part1(input: &str) -> i32 {
1515
'(' => pos += 1,
1616
')' => pos -= 1,
1717
_ => {
18-
panic!("Unknown char {cur}")
18+
unreachable!("Unknown char {cur}")
1919
}
2020
}
2121
}
@@ -29,14 +29,14 @@ fn solve_part2(input: &str) -> i32 {
2929
'(' => pos += 1,
3030
')' => pos -= 1,
3131
_ => {
32-
panic!("Unknown char {cur}")
32+
unreachable!("Unknown char {cur}")
3333
}
3434
}
3535
if pos < 0 {
3636
return (idx as i32) + 1;
3737
}
3838
}
39-
panic!("No basement for {input}")
39+
unreachable!("No basement for {input}")
4040
}
4141

4242
#[cfg(not(tarpaulin_include))]

rust-aoc/src/year2023/day202302.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ fn solve_part1(lines: &Vec<String>) -> i32 {
3838
"red" => Colour::Red,
3939
"blue" => Colour::Blue,
4040
"green" => Colour::Green,
41-
c => panic!("Unknown colour {c}"),
41+
c => unreachable!("Unknown colour {c}"),
4242
};
4343
let value: i32 = orb_and_value.first().unwrap().parse().unwrap();
4444
if *limits.get(&orb).unwrap() < value {
@@ -77,7 +77,7 @@ fn solve_part2(lines: &Vec<String>) -> i32 {
7777
"red" => Colour::Red,
7878
"blue" => Colour::Blue,
7979
"green" => Colour::Green,
80-
c => panic!("Unknown colour {c}"),
80+
c => unreachable!("Unknown colour {c}"),
8181
};
8282
let value: i32 = orb_and_value.first().unwrap().parse().unwrap();
8383
let cur_limit = limits.get(&orb).unwrap();

rust-aoc/src/year2024/day202415.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ fn read_input(lines: &[String]) -> (HashSet<Point2D>, HashSet<Point2D>, VecDeque
6565
'^' => Dir::N,
6666
'>' => Dir::E,
6767
'v' => Dir::S,
68-
_ => panic!(),
68+
_ => unreachable!(),
6969
})
7070
.for_each(|d| q.push_back(d));
7171
}
@@ -129,7 +129,7 @@ fn read_input2(lines: &[String]) -> (HashSet<Point2D>, HashSet<Box>, VecDeque<Di
129129
'^' => Dir::N,
130130
'>' => Dir::E,
131131
'v' => Dir::S,
132-
_ => panic!(),
132+
_ => unreachable!(),
133133
})
134134
.for_each(|d| q.push_back(d));
135135
}

rust-aoc/src/year2024/day202417.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ fn run_program(a: u64, b: u64, c: u64, program: &[u64]) -> Vec<u64> {
5757
4 => a,
5858
5 => b,
5959
6 => c,
60-
7 => panic!(),
60+
7 => unreachable!(),
6161
other => other,
6262
};
6363
match cmd {
@@ -91,7 +91,7 @@ fn run_program(a: u64, b: u64, c: u64, program: &[u64]) -> Vec<u64> {
9191
let denom = 2_u64.pow(real_operand as u32);
9292
c = a / denom;
9393
}
94-
_ => panic!(),
94+
_ => unreachable!(),
9595
}
9696
i += 2;
9797
}

rust-aoc/src/year2024/day202418.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ fn solve_part1_and_2(lines: &[String], max: i32, take: usize) -> (i32, String) {
3131
Nil => return (part1.steps(), format!("{},{}", nb.x, nb.y)),
3232
}
3333
}
34-
panic!()
34+
unreachable!()
3535
}
3636

3737
fn cords_to_point(line: &str) -> Point2D {
@@ -78,7 +78,7 @@ fn iterate(start: Point2D, target: Point2D, blocks: &HashSet<Point2D>) -> Positi
7878
while let Some(cur) = q.pop_front() {
7979
let (p, steps) = match cur {
8080
Position::Exist(p, steps, _) => (p, steps),
81-
Nil => panic!(),
81+
Nil => unreachable!(),
8282
};
8383
// println!("Checking {:?}", cur);
8484
if visited.contains(&p) {

rust-aoc/src/year2024/day202424.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ impl Rule {
5050
"AND" => And,
5151
"OR" => Or,
5252
"XOR" => Xor,
53-
_ => panic!(),
53+
_ => unreachable!(),
5454
},
5555
}
5656
}

0 commit comments

Comments
 (0)