From 58bfd5a0b6d76e862988fe1528e2c6ac45c04ef2 Mon Sep 17 00:00:00 2001 From: maneatingape <44142177+maneatingape@users.noreply.github.com> Date: Thu, 9 Jan 2025 17:43:27 +0100 Subject: [PATCH] Bump Rust version to 1.84 --- .github/workflows/checks.yml | 2 +- .github/workflows/docs.yml | 1 + Cargo.toml | 8 ++++++-- README.md | 4 ++-- src/util/integer.rs | 7 ------- src/util/math.rs | 22 ---------------------- src/year2017/day23.rs | 4 +--- src/year2018/day22.rs | 3 ++- src/year2019/day14.rs | 19 ++++++++++--------- src/year2023/day06.rs | 3 +-- src/year2023/day15.rs | 3 ++- src/year2023/day17.rs | 3 ++- src/year2024/day09.rs | 3 ++- 13 files changed, 30 insertions(+), 52 deletions(-) diff --git a/.github/workflows/checks.yml b/.github/workflows/checks.yml index 0bc6e44a..f87f7ca5 100644 --- a/.github/workflows/checks.yml +++ b/.github/workflows/checks.yml @@ -20,7 +20,7 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - - run: rustup default 1.83 + - run: rustup default 1.84 - run: cargo test test-nightly: diff --git a/.github/workflows/docs.yml b/.github/workflows/docs.yml index dadddce5..08b44326 100644 --- a/.github/workflows/docs.yml +++ b/.github/workflows/docs.yml @@ -18,6 +18,7 @@ jobs: url: ${{ steps.deployment.outputs.page_url }} steps: - uses: actions/checkout@v4 + - run: rustup default 1.84 - run: cargo doc env: RUSTDOCFLAGS: "--document-private-items --default-theme=ayu --deny warnings" diff --git a/Cargo.toml b/Cargo.toml index 75f61211..2e856384 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -2,7 +2,7 @@ name = "aoc" version = "2024.12.25" edition = "2021" -rust-version = "1.83" +rust-version = "1.84" [features] frivolity = [] @@ -54,6 +54,7 @@ absolute_paths = "warn" alloc_instead_of_core = "warn" allow_attributes = "allow" allow_attributes_without_reason = "allow" +arbitrary_source_item_ordering = "allow" arithmetic_side_effects = "allow" as_conversions = "allow" as_underscore = "warn" @@ -151,6 +152,7 @@ macro_use_imports = "warn" manual_assert = "warn" manual_c_str_literals = "warn" manual_instant_elapsed = "warn" +manual_is_power_of_two = "warn" manual_is_variant_and = "warn" manual_let_else = "warn" manual_ok_or = "warn" @@ -158,6 +160,7 @@ manual_string_new = "warn" many_single_char_names = "allow" map_err_ignore = "warn" map_unwrap_or = "warn" +map_with_unused_argument_over_ranges = "warn" match_bool = "warn" match_on_vec_items = "allow" match_same_arms = "warn" @@ -267,6 +270,7 @@ unimplemented = "warn" uninlined_format_args = "warn" unnecessary_box_returns = "warn" unnecessary_join = "warn" +unnecessary_literal_bound = "warn" unnecessary_safety_comment = "warn" unnecessary_safety_doc = "warn" unnecessary_self_imports = "warn" @@ -284,7 +288,7 @@ unused_trait_names = "warn" unwrap_in_result = "allow" unwrap_used = "allow" use_debug = "warn" -used_underscore_binding = "warn" +used_underscore_items = "warn" verbose_bit_mask = "warn" verbose_file_reads = "warn" wildcard_enum_match_arm = "allow" diff --git a/README.md b/README.md index 87edee6a..d841ba46 100644 --- a/README.md +++ b/README.md @@ -283,7 +283,7 @@ Performance is reasonable even on older hardware, for example a 2011 MacBook Pro | 19 | [Go With The Flow](https://adventofcode.com/2018/day/19) | [Source](src/year2018/day19.rs) | 1 | | 20 | [A Regular Map](https://adventofcode.com/2018/day/20) | [Source](src/year2018/day20.rs) | 36 | | 21 | [Chronal Conversion](https://adventofcode.com/2018/day/21) | [Source](src/year2018/day21.rs) | 66 | -| 22 | [Mode Maze](https://adventofcode.com/2018/day/22) | [Source](src/year2018/day22.rs) | 3396 | +| 22 | [Mode Maze](https://adventofcode.com/2018/day/22) | [Source](src/year2018/day22.rs) | 3197 | | 23 | [Experimental Emergency Teleportation](https://adventofcode.com/2018/day/23) | [Source](src/year2018/day23.rs) | 506 | | 24 | [Immune System Simulator 20XX](https://adventofcode.com/2018/day/24) | [Source](src/year2018/day24.rs) | 2056 | | 25 | [Four-Dimensional Adventure](https://adventofcode.com/2018/day/25) | [Source](src/year2018/day25.rs) | 323 | @@ -316,7 +316,7 @@ Performance is reasonable even on older hardware, for example a 2011 MacBook Pro | 20 | [Particle Swarm](https://adventofcode.com/2017/day/20) | [Source](src/year2017/day20.rs) | 245 | | 21 | [Fractal Art](https://adventofcode.com/2017/day/21) | [Source](src/year2017/day21.rs) | 5 | | 22 | [Sporifica Virus](https://adventofcode.com/2017/day/22) | [Source](src/year2017/day22.rs) | 36000 | -| 23 | [Coprocessor Conflagration](https://adventofcode.com/2017/day/23) | [Source](src/year2017/day23.rs) | 55 | +| 23 | [Coprocessor Conflagration](https://adventofcode.com/2017/day/23) | [Source](src/year2017/day23.rs) | 54 | | 24 | [Electromagnetic Moat](https://adventofcode.com/2017/day/24) | [Source](src/year2017/day24.rs) | 275 | | 25 | [The Halting Problem](https://adventofcode.com/2017/day/25) | [Source](src/year2017/day25.rs) | 3698 | diff --git a/src/util/integer.rs b/src/util/integer.rs index 7b114baa..438ccaca 100644 --- a/src/util/integer.rs +++ b/src/util/integer.rs @@ -22,7 +22,6 @@ pub trait Integer: const ONE: T; const TEN: T; - fn ilog2(self) -> T; fn trailing_zeros(self) -> T; } @@ -37,12 +36,6 @@ macro_rules! integer { const ONE: $t = 1; const TEN: $t = 10; - #[inline] - #[allow(trivial_numeric_casts)] - fn ilog2(self) -> $t { - <$t>::ilog2(self) as $t - } - #[inline] #[allow(trivial_numeric_casts)] fn trailing_zeros(self) -> $t { diff --git a/src/util/math.rs b/src/util/math.rs index 2cb2444d..4ed33435 100644 --- a/src/util/math.rs +++ b/src/util/math.rs @@ -22,10 +22,6 @@ pub trait IntegerMathOps> { fn mod_pow(self, e: T, m: T) -> T; } -pub trait UnsignedMathOps> { - fn sqrt(self) -> T; -} - pub trait SignedMathOps> { fn mod_inv(self, m: T) -> Option; } @@ -64,24 +60,6 @@ impl> IntegerMathOps for T { } } -impl> UnsignedMathOps for T { - // Integer square root. Once [`isqrt`] is stablized then this function can be removed. - fn sqrt(self) -> T { - let mut bit = T::ONE << (self.ilog2() >> T::ONE); - let mut root = bit; - - while bit > T::ONE { - bit = bit >> T::ONE; - let next = root | bit; - if next * next <= self { - root = next; - } - } - - root - } -} - impl> SignedMathOps for T { // Modular multiplicative inverse fn mod_inv(self, m: T) -> Option { diff --git a/src/year2017/day23.rs b/src/year2017/day23.rs index 2e958d37..ee021c47 100644 --- a/src/year2017/day23.rs +++ b/src/year2017/day23.rs @@ -49,8 +49,6 @@ //! this directly would take at least 10⁵.10⁵.10³ = 10¹³ = 10,000,000,000,000 steps. //! //! [`Day 18`]: crate::year2017::day18 - -use crate::util::math::*; use crate::util::parse::*; /// We only need the vrey first number from the input. @@ -71,7 +69,7 @@ pub fn part2(input: &u32) -> usize { /// Simple [prime number check](https://en.wikipedia.org/wiki/Primality_test) /// of all factors from 2 to √n inclusive. fn composite(n: u32) -> Option { - for f in 2..=n.sqrt() { + for f in 2..=n.isqrt() { if n % f == 0 { return Some(n); } diff --git a/src/year2018/day22.rs b/src/year2018/day22.rs index 5f7120aa..302b538c 100644 --- a/src/year2018/day22.rs +++ b/src/year2018/day22.rs @@ -27,6 +27,7 @@ use crate::util::grid::*; use crate::util::iter::*; use crate::util::parse::*; use crate::util::point::*; +use std::iter::repeat_with; /// The index of each tool is that tool that *cannot* be used in that region, for example /// Rocky => 0 => Neither, Wet => 1 => Torch and Narrow => 2 => Climbing Gear. @@ -72,7 +73,7 @@ pub fn part2(input: &Input) -> i32 { // Initialise bucket queue with pre-allocated capacity to reduce reallocations needed. let mut base = 0; - let mut todo = (0..BUCKETS).map(|_| Vec::with_capacity(1000)).collect::>(); + let mut todo = repeat_with(|| Vec::with_capacity(1000)).take(BUCKETS).collect::>(); // Add extra width and height so the search does not exceed the bounds of the grid. let mut cave = scan_cave(input, width + 10, height + 140); diff --git a/src/year2019/day14.rs b/src/year2019/day14.rs index 23c2854e..c0dc2b30 100644 --- a/src/year2019/day14.rs +++ b/src/year2019/day14.rs @@ -6,6 +6,7 @@ use crate::util::hash::*; use crate::util::iter::*; use crate::util::parse::*; use std::cmp::Ordering; +use std::iter::repeat_with; struct Ingredient { amount: u64, @@ -23,15 +24,15 @@ pub struct Reaction { pub fn parse(input: &str) -> Vec { let lines: Vec<_> = input.lines().collect(); - let mut reactions: Vec<_> = (0..lines.len() + 1) - .map(|_| { - Reaction { - amount: 0, - chemical: 1, // Default to ORE, other chemicals will overwrite. - ingredients: Vec::new(), - } - }) - .collect(); + let mut reactions: Vec<_> = repeat_with(|| { + Reaction { + amount: 0, + chemical: 1, // Default to ORE, other chemicals will overwrite. + ingredients: Vec::new(), + } + }) + .take(lines.len() + 1) + .collect(); // Assign FUEL and ORE known indices as we'll need to look them up later. let mut indices = FastMap::new(); diff --git a/src/year2023/day06.rs b/src/year2023/day06.rs index 59db2b49..84413142 100644 --- a/src/year2023/day06.rs +++ b/src/year2023/day06.rs @@ -19,7 +19,6 @@ //! [quadratic formula](https://en.wikipedia.org/wiki/Quadratic_formula). //! //! * `(t ± √(t² - 4d)) / 2` -use crate::util::math::*; use crate::util::parse::*; pub fn parse(input: &str) -> Vec<&str> { @@ -45,7 +44,7 @@ fn race(first: &str, second: &str) -> u128 { for (time, distance) in times.zip(distances) { // Use the quadratic formula to find the start and end positions. - let root = (time * time - 4 * distance).sqrt(); + let root = (time * time - 4 * distance).isqrt(); let mut start = (time - root).div_ceil(2); let mut end = (time + root) / 2; diff --git a/src/year2023/day15.rs b/src/year2023/day15.rs index af36866b..9eb167c9 100644 --- a/src/year2023/day15.rs +++ b/src/year2023/day15.rs @@ -2,6 +2,7 @@ //! //! Calculates part one and two at the same time as a speed optimization. use crate::util::parse::*; +use std::iter::repeat_with; type Input = (usize, usize); @@ -13,7 +14,7 @@ struct Item<'a> { pub fn parse(input: &str) -> Input { let mut part_one = 0; let mut part_two = 0; - let mut boxes: Vec>> = (0..256).map(|_| Vec::new()).collect(); + let mut boxes: Vec>> = repeat_with(Vec::new).take(256).collect(); for step in input.trim().as_bytes().split(|&b| b == b',') { let size = step.len(); diff --git a/src/year2023/day17.rs b/src/year2023/day17.rs index a0f4aa00..7ad2e08f 100644 --- a/src/year2023/day17.rs +++ b/src/year2023/day17.rs @@ -28,6 +28,7 @@ //! [`BinaryHeap`]: std::collections::BinaryHeap use crate::util::grid::*; use crate::util::parse::*; +use std::iter::repeat_with; /// Parse the input into a 2D grid of `u8` then convert to `u32` for convenience. pub fn parse(input: &str) -> Grid { @@ -55,7 +56,7 @@ fn astar(grid: &Grid) -> i32 { let heat = &grid.bytes; let mut index = 0; - let mut todo = (0..100).map(|_| Vec::with_capacity(1000)).collect::>(); + let mut todo = repeat_with(|| Vec::with_capacity(1000)).take(100).collect::>(); let mut cost = vec![[i32::MAX; 2]; heat.len()]; // Start from the top left corner checking both vertical and horizontal directions. diff --git a/src/year2024/day09.rs b/src/year2024/day09.rs index 081f0555..03ccf167 100644 --- a/src/year2024/day09.rs +++ b/src/year2024/day09.rs @@ -15,6 +15,7 @@ //! When moving a file to a free block, the corresponding heap is popped and then any leftover //! space is pushed back to the heap at a smaller index. The heap at index zero is not used //! but makes the indexing easier. +use std::iter::repeat_with; /// [Triangular numbers](https://en.wikipedia.org/wiki/Triangular_number) offset by two. /// Files can be a max size of 9 so we only need the first 10 values, including zero to make @@ -66,7 +67,7 @@ pub fn part1(disk: &[usize]) -> usize { pub fn part2(disk: &[usize]) -> usize { let mut block = 0; let mut checksum = 0; - let mut free: Vec<_> = (0..10).map(|_| Vec::with_capacity(1_100)).collect(); + let mut free: Vec<_> = repeat_with(|| Vec::with_capacity(1_100)).take(10).collect(); // Build a min-heap (leftmost free block first) where the size of each block is // implicit in the index of the array.