From 5c758b7a200aa30704b00bad5fe67e1fd02feeb8 Mon Sep 17 00:00:00 2001 From: Fredrik Fornwall Date: Mon, 9 Sep 2024 14:37:06 +0200 Subject: [PATCH] Rust 1.81.0 --- Cargo.toml | 2 +- crates/core/src/common/int_to_ascii.rs | 4 ++-- crates/core/src/common/md5.rs | 3 ++- crates/core/src/year2018/day07.rs | 5 ++--- crates/core/src/year2018/day10.rs | 2 +- crates/core/src/year2018/day16.rs | 2 +- crates/core/src/year2018/day23.rs | 4 +--- crates/core/src/year2018/day24.rs | 2 +- crates/core/src/year2019/day12.rs | 4 +--- crates/core/src/year2019/day22.rs | 2 +- crates/core/src/year2021/day20.rs | 2 +- crates/grpc-server/src/main.rs | 1 + crates/svgplot/src/lib.rs | 2 +- rust-toolchain | 2 +- 14 files changed, 17 insertions(+), 20 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 7e112bb2..712f9b22 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -9,7 +9,7 @@ edition = "2021" homepage = "https://github.com/fornwall/advent-of-code" license = "MIT" repository = "https://github.com/fornwall/advent-of-code" -rust-version = "1.80.1" +rust-version = "1.81.0" version = "2022.0.66" [profile.release] diff --git a/crates/core/src/common/int_to_ascii.rs b/crates/core/src/common/int_to_ascii.rs index 38b1903d..2e7bcee7 100644 --- a/crates/core/src/common/int_to_ascii.rs +++ b/crates/core/src/common/int_to_ascii.rs @@ -22,8 +22,8 @@ impl IntToAsciiContext { #[test] fn to_ascii() { let mut context = IntToAsciiContext::new(); - assert_eq!(context.ascii_bytes(1), &[b'1']); - assert_eq!(context.ascii_bytes(0), &[b'0']); + assert_eq!(context.ascii_bytes(1), b"1"); + assert_eq!(context.ascii_bytes(0), b"0"); assert_eq!(context.ascii_bytes(134), b"134"); assert_eq!(context.ascii_bytes(4_294_967_295), b"4294967295"); } diff --git a/crates/core/src/common/md5.rs b/crates/core/src/common/md5.rs index 4b6f0c34..41cf07b6 100644 --- a/crates/core/src/common/md5.rs +++ b/crates/core/src/common/md5.rs @@ -138,7 +138,8 @@ fn transform(state: &mut [u32; 4], input: &[u32; 16]) { ($a:expr, $b:expr) => ($a.wrapping_add($b)); ); macro_rules! rotate( - ($x:expr, $n:expr) => (($x << $n) | ($x >> (32 - $n))); + //($x:expr, $n:expr) => (($x << $n) | ($x >> (32 - $n))); + ($x:expr, $n:expr) => ($x.rotate_left($n)); ); { macro_rules! F( diff --git a/crates/core/src/year2018/day07.rs b/crates/core/src/year2018/day07.rs index c698b2fa..f6701222 100644 --- a/crates/core/src/year2018/day07.rs +++ b/crates/core/src/year2018/day07.rs @@ -55,12 +55,11 @@ fn parse_input(input_string: &str) -> Result { let step_name = parts[7] .chars() .next() - .ok_or(format!("Invalid line: {line_number}"))?; + .ok_or_else(|| format!("Invalid line: {line_number}"))?; let depends_on = parts[1] .chars() .next() - .ok_or(format!("Invalid line: {line_number}"))?; - + .ok_or_else(|| format!("Invalid line: {line_number}"))?; let step = step_map .entry(step_name) .or_insert_with(|| Step::new(step_name)); diff --git a/crates/core/src/year2018/day10.rs b/crates/core/src/year2018/day10.rs index 3ce94d77..e5848605 100644 --- a/crates/core/src/year2018/day10.rs +++ b/crates/core/src/year2018/day10.rs @@ -17,7 +17,7 @@ pub fn solve(input: &Input) -> Result { .map(|(line_index, line)| { let error = || format!("Invalid input at line {}", line_index + 1); - let parts: Vec<&str> = line.split(|c| c == '<' || c == '>' || c == ',').collect(); + let parts: Vec<&str> = line.split(['<', '>', ',']).collect(); if parts.len() < 6 || !line.starts_with("position=") { return Err(error()); } diff --git a/crates/core/src/year2018/day16.rs b/crates/core/src/year2018/day16.rs index 5df5df7c..7355f046 100644 --- a/crates/core/src/year2018/day16.rs +++ b/crates/core/src/year2018/day16.rs @@ -47,7 +47,7 @@ impl ProblemInput { let after = line.starts_with("After:"); if before || after { let parts: Vec = line[9..] - .split(|c| c == '[' || c == ']' || c == ',') + .split(['[', ']', ',']) .filter_map(|s| { if s.is_empty() { None diff --git a/crates/core/src/year2018/day23.rs b/crates/core/src/year2018/day23.rs index 1ec5490d..d00d6f53 100644 --- a/crates/core/src/year2018/day23.rs +++ b/crates/core/src/year2018/day23.rs @@ -101,9 +101,7 @@ impl Nanobot { .enumerate() .map(|(line_index, line)| { let line_number = line_index + 1; - let parts: Vec<&str> = line - .split(|c| c == '<' || c == '>' || c == ',' || c == '=') - .collect(); + let parts: Vec<&str> = line.split(['<', '>', ',', '=']).collect(); let error_message = || format!("Invalid input on line {line_number}"); if parts.len() != 8 { return Err(error_message()); diff --git a/crates/core/src/year2018/day24.rs b/crates/core/src/year2018/day24.rs index f6100f4d..68d1c32b 100644 --- a/crates/core/src/year2018/day24.rs +++ b/crates/core/src/year2018/day24.rs @@ -58,7 +58,7 @@ impl ArmyGroup { } else { // "17 units each with 5390 hit points (weak to radiation, bludgeoning) with // an attack that does 4507 fire damage at initiative 2". - let main_parts: Vec<&str> = line.split(|c| c == '(' || c == ')').collect(); + let main_parts: Vec<&str> = line.split(['(', ')']).collect(); let mut weaknesses = Vec::new(); let mut immunities = Vec::new(); diff --git a/crates/core/src/year2019/day12.rs b/crates/core/src/year2019/day12.rs index 8d36db20..a4659a28 100644 --- a/crates/core/src/year2019/day12.rs +++ b/crates/core/src/year2019/day12.rs @@ -28,9 +28,7 @@ impl Moons { let mut positions = [[0; 3]; 4]; for (i, line) in input.lines().enumerate() { let error_message = |_| format!("Invalid line: {}", i + 1); - let parts: Vec<&str> = line - .split(|c| c == '=' || c == ' ' || c == '>' || c == ',') - .collect(); + let parts: Vec<&str> = line.split(['=', ' ', '>', ',']).collect(); if parts.len() != 9 { return Err(format!("Invalid line: {}", i + 1)); diff --git a/crates/core/src/year2019/day22.rs b/crates/core/src/year2019/day22.rs index e214faa7..1206e0ce 100644 --- a/crates/core/src/year2019/day22.rs +++ b/crates/core/src/year2019/day22.rs @@ -44,7 +44,7 @@ pub fn solve(input: &Input) -> Result { deck.iter() .position(|&card| card == 2019) .map(|p| p as i128) - .ok_or(format!("No card {desired_card} found")) + .ok_or_else(|| format!("No card {desired_card} found")) } else { /// Explanation: /// diff --git a/crates/core/src/year2021/day20.rs b/crates/core/src/year2021/day20.rs index 5fc7d380..531017e0 100644 --- a/crates/core/src/year2021/day20.rs +++ b/crates/core/src/year2021/day20.rs @@ -12,7 +12,7 @@ struct Image { } impl Image { - fn new(pixels: Vec) -> Self { + const fn new(pixels: Vec) -> Self { Self { pixels } } diff --git a/crates/grpc-server/src/main.rs b/crates/grpc-server/src/main.rs index f022fe76..0d5a1533 100644 --- a/crates/grpc-server/src/main.rs +++ b/crates/grpc-server/src/main.rs @@ -7,6 +7,7 @@ use advent::{ProblemInput, ProblemOutput}; mod advent { #![allow(warnings)] + #![allow(clippy::derive_partial_eq_without_eq)] #![allow(clippy::future_not_send)] #![allow(clippy::missing_const_for_fn)] #![allow(clippy::similar_names)] diff --git a/crates/svgplot/src/lib.rs b/crates/svgplot/src/lib.rs index 3d4a1a55..f5ec3b29 100644 --- a/crates/svgplot/src/lib.rs +++ b/crates/svgplot/src/lib.rs @@ -131,7 +131,7 @@ impl SvgImage { .unwrap(); } self.common_attributes.write(&mut buffer); - buffer.write_all(&[b'>', b'\n']).unwrap(); + buffer.write_all(b">\n").unwrap(); let mut first = true; for (id, element) in &self.elements { diff --git a/rust-toolchain b/rust-toolchain index a561eb92..bd4541d2 100644 --- a/rust-toolchain +++ b/rust-toolchain @@ -1,4 +1,4 @@ [toolchain] -channel = "1.80.1" +channel = "1.81.0" components = ["rustfmt", "clippy"] targets = ["wasm32-unknown-unknown"]