From c77380d10a8854eb6999b4645d6fd86e7c18f5f3 Mon Sep 17 00:00:00 2001 From: Connor Slade Date: Mon, 25 Nov 2024 17:44:13 -0500 Subject: [PATCH] Fix clippy lints --- aoc_2021/src/day_08.rs | 5 +---- aoc_2021/src/day_11.rs | 2 +- aoc_2021/src/day_12.rs | 1 - aoc_2021/src/day_15.rs | 1 - aoc_2022/src/day_16.rs | 1 - aoc_2022/src/day_19.rs | 2 -- aoc_2022/src/day_22.rs | 1 - aoc_2023/src/day_20.rs | 2 +- aoc_2023/src/day_22.rs | 2 +- common/src/part.rs | 18 ++++++++++-------- 10 files changed, 14 insertions(+), 21 deletions(-) diff --git a/aoc_2021/src/day_08.rs b/aoc_2021/src/day_08.rs index 2574449..92ebdf9 100644 --- a/aoc_2021/src/day_08.rs +++ b/aoc_2021/src/day_08.rs @@ -121,10 +121,7 @@ fn parse(inp: &str) -> Vec<(Vec, Vec)> { } // Modified from https://stackoverflow.com/a/59939809/12471934 -fn permutations(items: Vec) -> Vec> -where - T: Ord, -{ +fn permutations(items: Vec) -> Vec> { if items.len() == 1 { return vec![items]; } diff --git a/aoc_2021/src/day_11.rs b/aoc_2021/src/day_11.rs index 73b4ba0..dfe2941 100644 --- a/aoc_2021/src/day_11.rs +++ b/aoc_2021/src/day_11.rs @@ -82,7 +82,7 @@ fn tick_octopi(octopi: &mut Vec>, x: usize, y: usize) { } } -fn octo_neighbors(octopi: &Vec>, x: usize, y: usize) -> Vec<(usize, usize)> { +fn octo_neighbors(octopi: &[Vec], x: usize, y: usize) -> Vec<(usize, usize)> { let mut out = Vec::new(); let (lenx, leny) = (octopi[0].len() as isize, octopi.len() as isize); let (x, y) = (x as isize, y as isize); diff --git a/aoc_2021/src/day_12.rs b/aoc_2021/src/day_12.rs index 19239c4..4656a85 100644 --- a/aoc_2021/src/day_12.rs +++ b/aoc_2021/src/day_12.rs @@ -97,7 +97,6 @@ fn parse(input: &str) -> ParseResult { #[cfg(test)] mod test { - use common::solution; use indoc::indoc; const CASE: &str = indoc! {" diff --git a/aoc_2021/src/day_15.rs b/aoc_2021/src/day_15.rs index 79bf0af..eca1d7c 100644 --- a/aoc_2021/src/day_15.rs +++ b/aoc_2021/src/day_15.rs @@ -45,7 +45,6 @@ fn part_b(_input: &str) -> Answer { #[cfg(test)] mod test { - use common::solution; use indoc::indoc; const CASE: &str = indoc! {" diff --git a/aoc_2022/src/day_16.rs b/aoc_2022/src/day_16.rs index dd9cedc..8640310 100644 --- a/aoc_2022/src/day_16.rs +++ b/aoc_2022/src/day_16.rs @@ -152,7 +152,6 @@ fn parse(input: &str) -> ParseResult { #[cfg(test)] mod test { - use common::solution; use indoc::indoc; const CASE: &str = indoc! {" diff --git a/aoc_2022/src/day_19.rs b/aoc_2022/src/day_19.rs index c90c843..86210c7 100644 --- a/aoc_2022/src/day_19.rs +++ b/aoc_2022/src/day_19.rs @@ -191,8 +191,6 @@ impl RobotType { mod test { use indoc::indoc; - use common::solution; - const CASE: &str = indoc! {" Blueprint 1: Each ore robot costs 4 ore. Each clay robot costs 2 ore. Each obsidian robot costs 3 ore and 14 clay. Each geode robot costs 2 ore and 7 obsidian. Blueprint 2: Each ore robot costs 2 ore. Each clay robot costs 3 ore. Each obsidian robot costs 3 ore and 8 clay. Each geode robot costs 3 ore and 12 obsidian. diff --git a/aoc_2022/src/day_22.rs b/aoc_2022/src/day_22.rs index 222f6c9..71ae41e 100644 --- a/aoc_2022/src/day_22.rs +++ b/aoc_2022/src/day_22.rs @@ -212,7 +212,6 @@ fn wrap_3d(world: &World, mut _pos: Point) -> Option<(Point, Direction)> { #[cfg(test)] mod test { - use common::solution; use indoc::indoc; const CASE: &str = indoc! {" diff --git a/aoc_2023/src/day_20.rs b/aoc_2023/src/day_20.rs index 9994418..d22e985 100644 --- a/aoc_2023/src/day_20.rs +++ b/aoc_2023/src/day_20.rs @@ -173,7 +173,7 @@ fn parse_input(input: &str) -> HashMap<&str, Connection<'_>> { _ => ConnectionType::Normal, }; - let source = source.trim_start_matches(|c| c == '%' || c == '&'); + let source = source.trim_start_matches(['%', '&']); out.insert( source, Connection { diff --git a/aoc_2023/src/day_22.rs b/aoc_2023/src/day_22.rs index 53a202d..17ae63e 100644 --- a/aoc_2023/src/day_22.rs +++ b/aoc_2023/src/day_22.rs @@ -28,7 +28,7 @@ fn solve(mut map: Vec, exhaustive: bool, count: fn(u32) -> u32) -> u32 { out } -fn shift_down(map: &mut Vec, exhaustive: bool) -> u32 { +fn shift_down(map: &mut [Box], exhaustive: bool) -> u32 { let mut moved = HashSet::new(); let mut dirty = true; while dirty { diff --git a/common/src/part.rs b/common/src/part.rs index 2471bec..5f6f4c5 100644 --- a/common/src/part.rs +++ b/common/src/part.rs @@ -1,4 +1,7 @@ -use std::str::FromStr; +use std::{ + fmt::{self, Display, Write}, + str::FromStr, +}; #[derive(Debug, Clone, Copy)] pub enum Part { @@ -18,12 +21,11 @@ impl FromStr for Part { } } -impl ToString for Part { - fn to_string(&self) -> String { - match self { - Part::A => "a", - Part::B => "b", - } - .to_owned() +impl Display for Part { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + f.write_char(match self { + Part::A => 'a', + Part::B => 'b', + }) } }