From ce008e47da6abedf57d89747a3ecbe046caf1aef Mon Sep 17 00:00:00 2001 From: Bert Peters Date: Sun, 12 Nov 2023 14:59:55 +0100 Subject: [PATCH] 100% fewer suppresed clippy warnings --- 2022/src/day22.rs | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/2022/src/day22.rs b/2022/src/day22.rs index fb997d9..3540033 100644 --- a/2022/src/day22.rs +++ b/2022/src/day22.rs @@ -297,27 +297,23 @@ pub fn part2(input: &[u8]) -> Result { Step::Forward(mut amount) => { 'outer: while amount > 0 { let map = &squares[current_square].0; - - // Need to allow unused range bound, since we're actually tracking how much we - // still have to do. The loops are expected to end early, and we should remember - // how much work we've actually done. - #[allow(clippy::mut_range_bound)] let coord = match dir { Direction::Up => { - for _ in 0..amount { + while amount > 0 { if y == 0 { break; } else if map[y - 1][x] == b'#' { break 'outer; } else { y -= 1; + amount -= 1; } } x } Direction::Down => { - for _ in 0..amount { + while amount > 0 { if y + 1 >= side_length { break; } else if map[y + 1][x] == b'#' { @@ -331,7 +327,7 @@ pub fn part2(input: &[u8]) -> Result { x } Direction::Left => { - for _ in 0..amount { + while amount > 0 { if x == 0 { break; } else if map[y][x - 1] == b'#' { @@ -345,7 +341,7 @@ pub fn part2(input: &[u8]) -> Result { y } Direction::Right => { - for _ in 0..amount { + while amount > 0 { if x + 1 >= side_length { break; } else if map[y][x + 1] == b'#' {