diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 71abc8aa..4079983d 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -103,4 +103,4 @@ jobs: rustup install --profile default nightly rustup default nightly - uses: Swatinem/rust-cache@v2 - - run: cargo clippy --all-targets + - run: cargo clippy --all-targets -- -D warnings diff --git a/Cargo.toml b/Cargo.toml index 21e616d2..30ff8bf1 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -10,8 +10,8 @@ version = "4.13.0" authors = ["Samuel Tardieu "] categories = ["algorithms"] readme = "README.md" -edition = "2021" -rust-version = "1.77.2" +edition = "2024" +rust-version = "1.85.0" [package.metadata.release] sign-commit = true @@ -47,7 +47,9 @@ version_check = "0.9.5" [lints.clippy] module_name_repetitions = { level = "allow", priority = 1 } too_long_first_doc_paragraph = { level = "allow", priority = 1 } # Temporary -pedantic = { level = "deny", priority = 0 } +pedantic = "deny" +# Do not activate until Clippy issue #13356 is fixed +#allow_attributes = "deny" [[bench]] name = "algos" diff --git a/benches/algos-fill.rs b/benches/algos-fill.rs index b02e5d23..cf7c7a75 100644 --- a/benches/algos-fill.rs +++ b/benches/algos-fill.rs @@ -1,7 +1,7 @@ // This version uses a filler in the Pt structure to increase // the cost of cloning a node. -use codspeed_criterion_compat::{criterion_group, criterion_main, Criterion}; +use codspeed_criterion_compat::{Criterion, criterion_group, criterion_main}; use pathfinding::prelude::{astar, bfs, dfs, dijkstra, fringe, idastar, iddfs}; #[derive(Clone, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)] diff --git a/benches/algos.rs b/benches/algos.rs index 6df282df..ed734b49 100644 --- a/benches/algos.rs +++ b/benches/algos.rs @@ -1,4 +1,4 @@ -use codspeed_criterion_compat::{criterion_group, criterion_main, Criterion}; +use codspeed_criterion_compat::{Criterion, criterion_group, criterion_main}; use itertools::Itertools; use pathfinding::prelude::{ astar, bfs, dfs, dijkstra, fringe, idastar, iddfs, separate_components, diff --git a/benches/edmondskarp.rs b/benches/edmondskarp.rs index 943c03f0..be7dd03d 100644 --- a/benches/edmondskarp.rs +++ b/benches/edmondskarp.rs @@ -1,6 +1,6 @@ -use codspeed_criterion_compat::{criterion_group, criterion_main, Criterion}; +use codspeed_criterion_compat::{Criterion, criterion_group, criterion_main}; use pathfinding::directed::edmonds_karp::{ - edmonds_karp, DenseCapacity, EKFlows, EdmondsKarp, SparseCapacity, + DenseCapacity, EKFlows, EdmondsKarp, SparseCapacity, edmonds_karp, }; use std::collections::HashMap; diff --git a/benches/kuhn_munkres.rs b/benches/kuhn_munkres.rs index 2a056977..775f3bea 100644 --- a/benches/kuhn_munkres.rs +++ b/benches/kuhn_munkres.rs @@ -1,5 +1,5 @@ -use codspeed_criterion_compat::{criterion_group, criterion_main, BenchmarkId, Criterion}; -use pathfinding::prelude::{kuhn_munkres, Matrix}; +use codspeed_criterion_compat::{BenchmarkId, Criterion, criterion_group, criterion_main}; +use pathfinding::prelude::{Matrix, kuhn_munkres}; use rand::{Rng, SeedableRng}; use rand_xorshift::XorShiftRng; diff --git a/benches/matrices.rs b/benches/matrices.rs index 30b67045..a5057976 100644 --- a/benches/matrices.rs +++ b/benches/matrices.rs @@ -1,7 +1,7 @@ -use codspeed_criterion_compat::{criterion_group, criterion_main, Criterion}; +use codspeed_criterion_compat::{Criterion, criterion_group, criterion_main}; use pathfinding::matrix::Matrix; -#[allow(clippy::missing_panics_doc)] +#[expect(clippy::missing_panics_doc)] pub fn transpose_benchmark(c: &mut Criterion) { // Generate a 100 x 100 square matrix with entries from 1 to 100^2 let data: Vec = (0..100 * 100).collect(); @@ -10,7 +10,7 @@ pub fn transpose_benchmark(c: &mut Criterion) { c.bench_function("transpose", |b| b.iter(|| m.transpose())); } -#[allow(clippy::missing_panics_doc)] +#[expect(clippy::missing_panics_doc)] pub fn transpose_non_square_benchmark(c: &mut Criterion) { // Generate a 1000 x 10 square matrix with entries from 1 to 100^2 let data: Vec = (0..100 * 100).collect(); diff --git a/benches/movingai.rs b/benches/movingai.rs index 5d841aa4..a7c51c0a 100644 --- a/benches/movingai.rs +++ b/benches/movingai.rs @@ -1,18 +1,18 @@ // Test with files from https://movingai.com/benchmarks/ -use codspeed_criterion_compat::{criterion_group, criterion_main, Criterion}; +use codspeed_criterion_compat::{Criterion, criterion_group, criterion_main}; use movingai::parser::{parse_map_file, parse_scen_file}; use movingai::{Coords2D, Map2D}; use noisy_float::prelude::*; use pathfinding::directed::astar::astar; use std::path::Path; -#[allow(clippy::cast_precision_loss)] +#[expect(clippy::cast_precision_loss)] fn distance(a: &Coords2D, b: &Coords2D) -> R64 { r64((a.0 as f64 - b.0 as f64).hypot(a.1 as f64 - b.1 as f64)) } -#[allow(clippy::missing_panics_doc)] +#[expect(clippy::missing_panics_doc)] pub fn arena(c: &mut Criterion) { c.bench_function("arena", |b| { b.iter(|| { diff --git a/benches/separate_components.rs b/benches/separate_components.rs index 0127b60a..38a709cf 100644 --- a/benches/separate_components.rs +++ b/benches/separate_components.rs @@ -1,7 +1,7 @@ -use codspeed_criterion_compat::{criterion_group, criterion_main, Criterion}; +use codspeed_criterion_compat::{Criterion, criterion_group, criterion_main}; use itertools::Itertools; use pathfinding::prelude::separate_components; -use rand::{prelude::SliceRandom, Rng, RngCore, SeedableRng}; +use rand::{Rng, RngCore, SeedableRng, prelude::SliceRandom}; use rand_xorshift::XorShiftRng; use std::collections::HashSet; diff --git a/examples/sliding-puzzle.rs b/examples/sliding-puzzle.rs index 7321937f..19d5502d 100644 --- a/examples/sliding-puzzle.rs +++ b/examples/sliding-puzzle.rs @@ -12,8 +12,8 @@ const SIDE: u8 = 3; const SIDE: u8 = 4; const LIMIT: usize = (SIDE * SIDE) as usize; -#[allow(clippy::derived_hash_with_manual_eq)] #[derive(Clone, Debug, Hash)] +#[allow(clippy::derived_hash_with_manual_eq)] // expect doesn't work, clippy issue #13356 struct Game { positions: [u8; LIMIT], // Correct position of piece at every index hole_idx: u8, // Current index of the hole @@ -95,7 +95,7 @@ impl Game { // However, since the successors are the current board with the hole moved one // position, we need to build a clone of the current board that will be reused in // this iterator. - fn successors(&self) -> impl Iterator { + fn successors(&self) -> impl Iterator + use<> { let game = self.clone(); SUCCESSORS[self.hole_idx as usize] .iter() diff --git a/src/directed/astar.rs b/src/directed/astar.rs index 64a10d00..5e0dfbcd 100644 --- a/src/directed/astar.rs +++ b/src/directed/astar.rs @@ -77,7 +77,7 @@ use crate::FxIndexMap; /// |&p| p == GOAL); /// assert_eq!(result.expect("no path found").1, 4); /// ``` -#[allow(clippy::missing_panics_doc)] +#[expect(clippy::missing_panics_doc)] pub fn astar( start: &N, mut successors: FN, @@ -169,7 +169,7 @@ where /// /// Each path comprises both the start and an end node. Note that while every path shares the same /// start node, different paths may have different end nodes. -#[allow(clippy::missing_panics_doc)] +#[expect(clippy::missing_panics_doc)] pub fn astar_bag( start: &N, mut successors: FN, diff --git a/src/directed/dijkstra.rs b/src/directed/dijkstra.rs index ab6f3314..fd3d9be1 100644 --- a/src/directed/dijkstra.rs +++ b/src/directed/dijkstra.rs @@ -99,7 +99,7 @@ where reached.map(|target| { ( reverse_path(&parents, |&(p, _)| p, target), - parents.get_index(target).unwrap().1 .1, + parents.get_index(target).unwrap().1.1, ) }) } @@ -168,7 +168,7 @@ where /// /// The [`build_path`] function can be used to build a full path from the starting point to one /// of the reachable targets. -#[allow(clippy::missing_panics_doc)] +#[expect(clippy::missing_panics_doc)] pub fn dijkstra_partial( start: &N, mut successors: FN, @@ -277,7 +277,7 @@ where /// assert_eq!(vec![1], build_path(&1, &parents)); /// assert_eq!(vec![101], build_path(&101, &parents)); /// ``` -#[allow(clippy::implicit_hasher)] +#[expect(clippy::implicit_hasher)] pub fn build_path(target: &N, parents: &HashMap) -> Vec where N: Eq + Hash + Clone, diff --git a/src/directed/edmonds_karp.rs b/src/directed/edmonds_karp.rs index 2f809ded..981742d0 100644 --- a/src/directed/edmonds_karp.rs +++ b/src/directed/edmonds_karp.rs @@ -8,7 +8,7 @@ //! edges. use super::bfs::bfs; -use crate::{matrix::Matrix, FxIndexSet}; +use crate::{FxIndexSet, matrix::Matrix}; use num_traits::{Bounded, Signed, Zero}; use std::collections::{BTreeMap, BTreeSet, VecDeque}; use std::hash::Hash; diff --git a/src/directed/fringe.rs b/src/directed/fringe.rs index 7c05f868..15b511a3 100644 --- a/src/directed/fringe.rs +++ b/src/directed/fringe.rs @@ -77,7 +77,7 @@ use std::mem; /// |&p| p == GOAL); /// assert_eq!(result.expect("no path found").1, 4); /// ``` -#[allow(clippy::missing_panics_doc)] +#[expect(clippy::missing_panics_doc)] pub fn fringe( start: &N, mut successors: FN, diff --git a/src/directed/idastar.rs b/src/directed/idastar.rs index de8b5fa3..bdb2b24e 100644 --- a/src/directed/idastar.rs +++ b/src/directed/idastar.rs @@ -1,7 +1,9 @@ //! Compute a shortest path using the [IDA* search //! algorithm](https://en.wikipedia.org/wiki/Iterative_deepening_A*). +use indexmap::IndexSet; use num_traits::Zero; +use std::{hash::Hash, ops::ControlFlow}; /// Compute a shortest path using the [IDA* search /// algorithm](https://en.wikipedia.org/wiki/Iterative_deepening_A*). @@ -76,52 +78,43 @@ pub fn idastar( mut success: FS, ) -> Option<(Vec, C)> where - N: Eq + Clone, + N: Eq + Clone + Hash, C: Zero + Ord + Copy, FN: FnMut(&N) -> IN, IN: IntoIterator, FH: FnMut(&N) -> C, FS: FnMut(&N) -> bool, { - let mut bound = heuristic(start); - let mut path = vec![start.clone()]; - loop { - match search( - &mut path, - Zero::zero(), - bound, - &mut successors, - &mut heuristic, - &mut success, - ) { - Path::Found(path, cost) => return Some((path, cost)), - Path::Minimum(min) => { - if bound == min { - return None; - } - bound = min; - } - Path::Impossible => return None, - } - } -} + let mut path = IndexSet::from([start.clone()]); -enum Path { - Found(Vec, C), - Minimum(C), - Impossible, + std::iter::repeat(()) + .try_fold(heuristic(start), |bound, ()| { + search( + &mut path, + Zero::zero(), + bound, + &mut successors, + &mut heuristic, + &mut success, + ) + .map_break(Some)? + // .filter(|min| *min > bound) + .map_or(ControlFlow::Break(None), ControlFlow::Continue) + }) + .break_value() + .unwrap_or_default() // To avoid a missing panics section, as this always break } fn search( - path: &mut Vec, + path: &mut IndexSet, cost: C, bound: C, successors: &mut FN, heuristic: &mut FH, success: &mut FS, -) -> Path +) -> ControlFlow<(Vec, C), Option> where - N: Eq + Clone, + N: Eq + Clone + Hash, C: Zero + Ord + Copy, FN: FnMut(&N) -> IN, IN: IntoIterator, @@ -132,12 +125,12 @@ where let start = &path[path.len() - 1]; let f = cost + heuristic(start); if f > bound { - return Path::Minimum(f); + return ControlFlow::Continue(Some(f)); } if success(start) { - return Path::Found(path.clone(), f); + return ControlFlow::Break((path.iter().cloned().collect(), f)); } - let mut neighbs = successors(start) + let mut neighbs: Vec<(N, C, C)> = successors(start) .into_iter() .filter_map(|(n, c)| { (!path.contains(&n)).then(|| { @@ -151,13 +144,12 @@ where }; let mut min = None; for (node, extra, _) in neighbs { - path.push(node); - match search(path, cost + extra, bound, successors, heuristic, success) { - found_path @ Path::Found(_, _) => return found_path, - Path::Minimum(m) if !min.is_some_and(|n| n < m) => min = Some(m), + let (idx, _) = path.insert_full(node); + match search(path, cost + extra, bound, successors, heuristic, success)? { + Some(m) if min.is_none_or(|n| n >= m) => min = Some(m), _ => (), } - path.pop(); + path.swap_remove_index(idx); } - min.map_or(Path::Impossible, Path::Minimum) + ControlFlow::Continue(min) } diff --git a/src/directed/mod.rs b/src/directed/mod.rs index ddd7a960..8913f7fa 100644 --- a/src/directed/mod.rs +++ b/src/directed/mod.rs @@ -17,7 +17,7 @@ pub mod strongly_connected_components; pub mod topological_sort; pub mod yen; -#[allow(clippy::needless_collect)] +#[expect(clippy::needless_collect)] fn reverse_path(parents: &FxIndexMap, mut parent: F, start: usize) -> Vec where N: Eq + Hash + Clone, diff --git a/src/directed/strongly_connected_components.rs b/src/directed/strongly_connected_components.rs index 8795a2b2..9645b644 100644 --- a/src/directed/strongly_connected_components.rs +++ b/src/directed/strongly_connected_components.rs @@ -104,7 +104,7 @@ where /// /// The function returns the strongly connected component containing the node, /// which is guaranteed to contain at least `node`. -#[allow(clippy::missing_panics_doc)] +#[expect(clippy::missing_panics_doc)] pub fn strongly_connected_component(node: &N, successors: FN) -> Vec where N: Clone + Hash + Eq, diff --git a/src/directed/topological_sort.rs b/src/directed/topological_sort.rs index c3ae336a..0e989451 100644 --- a/src/directed/topological_sort.rs +++ b/src/directed/topological_sort.rs @@ -152,8 +152,8 @@ where /// In this case, the strongly connected set(s) can then be found using the /// [`strongly_connected_components`](super::strongly_connected_components::strongly_connected_components) /// function on the list of remaining nodes. -#[allow(clippy::type_complexity)] -#[allow(clippy::missing_panics_doc)] +#[expect(clippy::type_complexity)] +#[expect(clippy::missing_panics_doc)] pub fn topological_sort_into_groups( nodes: &[N], mut successors: FN, diff --git a/src/grid.rs b/src/grid.rs index f403594b..c58e12f4 100644 --- a/src/grid.rs +++ b/src/grid.rs @@ -2,10 +2,10 @@ //! without diagonal links. use super::matrix::Matrix; +use crate::FxIndexSet; use crate::directed::bfs::bfs_reach; use crate::directed::dfs::dfs_reach; use crate::utils::constrain; -use crate::FxIndexSet; use num_traits::ToPrimitive; use std::collections::BTreeSet; use std::fmt; @@ -214,7 +214,7 @@ impl Grid { /// Return an iterator over the border vertices. The grid must not have /// a zero width or height. - fn borders(&self) -> impl Iterator { + fn borders(&self) -> impl Iterator + use<> { let width = self.width; let height = self.height; (0..width) diff --git a/src/kuhn_munkres.rs b/src/kuhn_munkres.rs index e37ee339..ae9bf7b3 100644 --- a/src/kuhn_munkres.rs +++ b/src/kuhn_munkres.rs @@ -3,7 +3,7 @@ //! [Kuhn-Munkres algorithm](https://en.wikipedia.org/wiki/Hungarian_algorithm) //! (also known as Hungarian algorithm). -use crate::{matrix::Matrix, FxIndexSet}; +use crate::{FxIndexSet, matrix::Matrix}; use num_traits::{Bounded, Signed, Zero}; use std::iter::Sum; diff --git a/src/lib.rs b/src/lib.rs index 356c3eff..622d8433 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -76,7 +76,7 @@ //! in this context, you can wrap them into compliant types using the //! [ordered-float](https://crates.io/crates/ordered-float) crate. //! -//! The minimum supported Rust version (MSRV) is Rust 1.77.2. +//! The minimum supported Rust version (MSRV) is Rust 1.85.0. //! //! [A*]: https://en.wikipedia.org/wiki/A*_search_algorithm //! [BFS]: https://en.wikipedia.org/wiki/Breadth-first_search diff --git a/src/matrix.rs b/src/matrix.rs index deaef393..d917cb05 100644 --- a/src/matrix.rs +++ b/src/matrix.rs @@ -482,7 +482,7 @@ impl Matrix { 2 => self.data.reverse(), n => { for r in 0..self.rows / 2 { - for c in 0..(self.columns + 1) / 2 { + for c in 0..usize::midpoint(1, self.columns) { // i1 … i2 // … … … // i4 … i3 @@ -531,7 +531,7 @@ impl Matrix { &self, (r, c): (usize, usize), diagonals: bool, - ) -> impl Iterator { + ) -> impl Iterator + use { let (row_range, col_range) = if r < self.rows && c < self.columns { ( r.saturating_sub(1)..(self.rows).min(r + 2), @@ -597,7 +597,7 @@ impl Matrix { &self, start: (usize, usize), direction: (isize, isize), - ) -> impl Iterator { + ) -> impl Iterator + use { in_direction(start, direction, (self.rows, self.columns)) } @@ -628,14 +628,14 @@ impl Matrix { since = "4.1.0", remove = "> 4.x" )] - pub fn indices(&self) -> impl Iterator { + pub fn indices(&self) -> impl Iterator + use { self.keys() } /// Return an iterator on the Matrix indices, first row first. The values are /// computed when this method is called and will not change even if new rows are /// added before the iterator is consumed. - pub fn keys(&self) -> impl Iterator { + pub fn keys(&self) -> impl Iterator + use { let columns = self.columns; (0..self.rows).flat_map(move |r| (0..columns).map(move |c| (r, c))) } diff --git a/src/undirected/connected_components.rs b/src/undirected/connected_components.rs index 6fd4b2fc..b027565b 100644 --- a/src/undirected/connected_components.rs +++ b/src/undirected/connected_components.rs @@ -233,7 +233,7 @@ where /// This function returns a map between every vertex and the index of /// the set it belongs to in the `components` list. #[must_use] -#[allow(clippy::implicit_hasher)] +#[expect(clippy::implicit_hasher)] pub fn component_index(components: &[HashSet]) -> HashMap where N: Clone + Hash + Eq, diff --git a/src/utils.rs b/src/utils.rs index 0d3fd803..b43ed774 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -36,7 +36,7 @@ where /// assert_eq!(move_in_direction((1, 1), (-1, -2), board), None); /// ``` #[must_use] -#[allow(clippy::cast_possible_wrap, clippy::cast_sign_loss)] +#[expect(clippy::cast_possible_wrap, clippy::cast_sign_loss)] pub fn move_in_direction( start: (usize, usize), direction: (isize, isize), @@ -90,7 +90,7 @@ pub fn in_direction( /// assert_eq!(constrain(-30, 7), 5); /// ``` #[must_use] -#[allow(clippy::cast_sign_loss)] +#[expect(clippy::cast_sign_loss)] pub const fn constrain(value: isize, upper: usize) -> usize { if value > 0 { value as usize % upper diff --git a/tests/astar_bag.rs b/tests/astar_bag.rs index bfad17ff..f4a12158 100644 --- a/tests/astar_bag.rs +++ b/tests/astar_bag.rs @@ -22,15 +22,12 @@ fn multiple_sinks() { ) .unwrap(); assert_eq!(cost, 4); - assert_eq!( - solutions.sorted().collect_vec(), - vec![ - vec![1, 2, 4], - vec![1, 2, 5, 6, 7], - vec![1, 3, 4], - vec![1, 3, 5, 6, 7], - ] - ); + assert_eq!(solutions.sorted().collect_vec(), vec![ + vec![1, 2, 4], + vec![1, 2, 5, 6, 7], + vec![1, 3, 4], + vec![1, 3, 5, 6, 7], + ]); } #[test] diff --git a/tests/cliques.rs b/tests/cliques.rs index 9faba56e..38445c95 100644 --- a/tests/cliques.rs +++ b/tests/cliques.rs @@ -24,13 +24,9 @@ fn test_same_node_appears_in_multiple_clique() { let cliques_as_vectors: Vec> = sort(&cliques); assert_eq!( - vec![ - vec![1, 5, 9], - vec![2, 6], - vec![3, 6, 9], - vec![3, 7], - vec![4, 8] - ], + vec![vec![1, 5, 9], vec![2, 6], vec![3, 6, 9], vec![3, 7], vec![ + 4, 8 + ]], cliques_as_vectors ); } diff --git a/tests/codejam-2017-a.rs b/tests/codejam-2017-a.rs index d6328626..aae701b1 100644 --- a/tests/codejam-2017-a.rs +++ b/tests/codejam-2017-a.rs @@ -8,7 +8,7 @@ use std::io::{self, Cursor}; use std::num::ParseIntError; #[derive(Debug)] -#[allow(dead_code)] +#[expect(dead_code)] enum Error { Io(io::Error), Parse(ParseIntError), @@ -99,7 +99,7 @@ fn test>(n: usize, file: &mut dyn BufRead) -> Result= 0); - #[allow(clippy::cast_sign_loss)] + #[expect(clippy::cast_sign_loss)] let n = n as usize; if n > max { max = n; diff --git a/tests/connected-components.rs b/tests/connected-components.rs index 15313ce8..0e3ba43a 100644 --- a/tests/connected-components.rs +++ b/tests/connected-components.rs @@ -36,10 +36,9 @@ fn basic_components() { let mut c = components(&[vec![1, 2], vec![3, 4], vec![5, 6], vec![1, 4, 7]]); c.sort_unstable_by_key(|v| *v.iter().min().unwrap()); assert_eq!(c.len(), 2); - assert_eq!( - c[0].clone().into_iter().sorted().collect_vec(), - vec![1, 2, 3, 4, 7] - ); + assert_eq!(c[0].clone().into_iter().sorted().collect_vec(), vec![ + 1, 2, 3, 4, 7 + ]); assert_eq!(c[1].clone().into_iter().sorted().collect_vec(), vec![5, 6]); } @@ -48,10 +47,9 @@ fn empty_components() { let mut c = components(&[vec![1, 2], vec![3, 4], vec![], vec![1, 4, 7]]); c.sort_unstable_by_key(|v| *v.iter().min().unwrap()); assert_eq!(c.len(), 1); - assert_eq!( - c[0].clone().into_iter().sorted().collect_vec(), - vec![1, 2, 3, 4, 7] - ); + assert_eq!(c[0].clone().into_iter().sorted().collect_vec(), vec![ + 1, 2, 3, 4, 7 + ]); } #[test] @@ -67,14 +65,12 @@ fn basic_connected_components() { }); c.sort_unstable_by_key(|v| *v.iter().min().unwrap()); assert_eq!(c.len(), 2); - assert_eq!( - c[0].clone().into_iter().sorted().collect_vec(), - vec![1, 3, 5, 7] - ); - assert_eq!( - c[1].clone().into_iter().sorted().collect_vec(), - vec![2, 4, 6, 8] - ); + assert_eq!(c[0].clone().into_iter().sorted().collect_vec(), vec![ + 1, 3, 5, 7 + ]); + assert_eq!(c[1].clone().into_iter().sorted().collect_vec(), vec![ + 2, 4, 6, 8 + ]); assert_eq!(counter, 2); } diff --git a/tests/dijkstra-all.rs b/tests/dijkstra-all.rs index 228bf6b9..27c59680 100644 --- a/tests/dijkstra-all.rs +++ b/tests/dijkstra-all.rs @@ -1,5 +1,5 @@ use pathfinding::prelude::*; -use rand::{rngs, Rng}; +use rand::{Rng, rngs}; fn build_network(size: usize) -> Matrix { let mut network = Matrix::new(size, size, 0); @@ -52,7 +52,10 @@ fn all_paths() { let other_path = build_path(&target, &paths); // There might be several paths, but we know that internally we use the // same algorithm so the comparison holds. - assert_eq!(path, other_path, "path {start} -> {target} differ in {network:?}: {path:?} vs {other_path:?}"); + assert_eq!( + path, other_path, + "path {start} -> {target} differ in {network:?}: {path:?} vs {other_path:?}" + ); } } else { assert!( diff --git a/tests/dijkstra-reach.rs b/tests/dijkstra-reach.rs index e3fdde88..51e543a3 100644 --- a/tests/dijkstra-reach.rs +++ b/tests/dijkstra-reach.rs @@ -1,5 +1,5 @@ use itertools::Itertools; -use pathfinding::prelude::{dijkstra_reach, DijkstraReachableItem}; +use pathfinding::prelude::{DijkstraReachableItem, dijkstra_reach}; use std::collections::HashMap; #[test] @@ -12,11 +12,13 @@ fn dijkstra_reach_numbers() { assert!((0..100).all(|x| reach.iter().any(|y| x == y.total_cost))); // dijkstra_reach should return reachable nodes in order of cost - assert!(reach - .iter() - .map(|x| x.total_cost) - .tuple_windows() - .all(|(a, b)| b >= a)); + assert!( + reach + .iter() + .map(|x| x.total_cost) + .tuple_windows() + .all(|(a, b)| b >= a) + ); } #[test] diff --git a/tests/edmondskarp.rs b/tests/edmondskarp.rs index e5f0e94e..e96ca6aa 100644 --- a/tests/edmondskarp.rs +++ b/tests/edmondskarp.rs @@ -60,7 +60,7 @@ fn wikipedia_example_sparse() { wikipedia_example::>(); } -#[allow(clippy::cast_possible_truncation)] +#[expect(clippy::cast_possible_truncation)] fn wikipedia_progressive_example>() { let successors = successors_wikipedia(); let size = successors.len(); diff --git a/tests/gps.rs b/tests/gps.rs index e7d9f902..451c6a0c 100644 --- a/tests/gps.rs +++ b/tests/gps.rs @@ -15,10 +15,10 @@ impl Coords { self.1.to_radians() } - #[allow(clippy::cast_possible_truncation, clippy::cast_sign_loss)] + #[expect(clippy::cast_possible_truncation, clippy::cast_sign_loss)] fn distance_in_meters(&self, other: &Self) -> u64 { let x = - (other.lon_rad() - self.lon_rad()) * ((other.lat_rad() + self.lat_rad()) / 2.0).cos(); + (other.lon_rad() - self.lon_rad()) * f32::midpoint(other.lat_rad(), self.lat_rad()).cos(); let y = other.lat_rad() - self.lat_rad(); (x.hypot(y) * 6_371_000.0).round() as u64 } diff --git a/tests/grid.rs b/tests/grid.rs index 5dbe8565..16b7820e 100644 --- a/tests/grid.rs +++ b/tests/grid.rs @@ -77,19 +77,16 @@ fn diagonal_mode() { g.enable_diagonal_mode(); let mut ns = g.neighbours((1, 1)); ns.sort_unstable(); - assert_eq!( - ns, - vec![ - (0, 0), - (0, 1), - (0, 2), - (1, 0), - (1, 2), - (2, 0), - (2, 1), - (2, 2), - ] - ); + assert_eq!(ns, vec![ + (0, 0), + (0, 1), + (0, 2), + (1, 0), + (1, 2), + (2, 0), + (2, 1), + (2, 2), + ]); g.disable_diagonal_mode(); let mut ns = g.neighbours((1, 1)); ns.sort_unstable(); @@ -290,10 +287,13 @@ fn neighbours_of_border() { g.enable_diagonal_mode(); assert_eq!(g.neighbours((2, 1)), vec![]); g.fill(); - assert_eq!( - sort(g.neighbours((2, 1))), - vec![(1, 0), (1, 1), (1, 2), (2, 0), (2, 2)] - ); + assert_eq!(sort(g.neighbours((2, 1))), vec![ + (1, 0), + (1, 1), + (1, 2), + (2, 0), + (2, 2) + ]); g.disable_diagonal_mode(); assert_eq!(sort(g.neighbours((2, 1))), vec![(1, 1), (2, 0), (2, 2)]); @@ -302,10 +302,13 @@ fn neighbours_of_border() { g.enable_diagonal_mode(); assert_eq!(g.neighbours((1, 2)), vec![]); g.fill(); - assert_eq!( - sort(g.neighbours((1, 2))), - vec![(0, 1), (0, 2), (1, 1), (2, 1), (2, 2)] - ); + assert_eq!(sort(g.neighbours((1, 2))), vec![ + (0, 1), + (0, 2), + (1, 1), + (2, 1), + (2, 2) + ]); g.disable_diagonal_mode(); assert_eq!(sort(g.neighbours((1, 2))), vec![(0, 2), (1, 1), (2, 2)]); } @@ -467,47 +470,38 @@ fn edges() { g.fill(); let mut edges = g.edges().collect::>(); edges.sort_unstable(); - assert_eq!( - edges, - vec![ - ((0, 0), (0, 1)), - ((0, 0), (1, 0)), - ((0, 1), (1, 1)), - ((1, 0), (1, 1)) - ] - ); + assert_eq!(edges, vec![ + ((0, 0), (0, 1)), + ((0, 0), (1, 0)), + ((0, 1), (1, 1)), + ((1, 0), (1, 1)) + ]); g.enable_diagonal_mode(); let mut edges = g.edges().collect::>(); edges.sort_unstable(); - assert_eq!( - edges, - vec![ - ((0, 0), (0, 1)), - ((0, 0), (1, 0)), - ((0, 0), (1, 1)), - ((0, 1), (1, 1)), - ((1, 0), (0, 1)), - ((1, 0), (1, 1)) - ] - ); + assert_eq!(edges, vec![ + ((0, 0), (0, 1)), + ((0, 0), (1, 0)), + ((0, 0), (1, 1)), + ((0, 1), (1, 1)), + ((1, 0), (0, 1)), + ((1, 0), (1, 1)) + ]); let mut g = Grid::new(3, 3); g.fill(); g.remove_vertex((1, 1)); let mut edges = g.edges().collect::>(); edges.sort_unstable(); - assert_eq!( - edges, - vec![ - ((0, 0), (0, 1)), - ((0, 0), (1, 0)), - ((0, 1), (0, 2)), - ((0, 2), (1, 2)), - ((1, 0), (2, 0)), - ((1, 2), (2, 2)), - ((2, 0), (2, 1)), - ((2, 1), (2, 2)) - ] - ); + assert_eq!(edges, vec![ + ((0, 0), (0, 1)), + ((0, 0), (1, 0)), + ((0, 1), (0, 2)), + ((0, 2), (1, 2)), + ((1, 0), (2, 0)), + ((1, 2), (2, 2)), + ((2, 0), (2, 1)), + ((2, 1), (2, 2)) + ]); } #[test] diff --git a/tests/kruskal.rs b/tests/kruskal.rs index 024e77a5..0c470062 100644 --- a/tests/kruskal.rs +++ b/tests/kruskal.rs @@ -11,14 +11,11 @@ fn grid_lines() { .collect::>(); assert_eq!(weighted_edges.len(), 4); let mst = kruskal(&weighted_edges).sorted().collect_vec(); - assert_eq!( - mst, - vec![ - (&(0, 0), &(0, 1), 0), - (&(0, 0), &(1, 0), 0), - (&(1, 0), &(1, 1), 0) - ] - ); + assert_eq!(mst, vec![ + (&(0, 0), &(0, 1), 0), + (&(0, 0), &(1, 0), 0), + (&(1, 0), &(1, 1), 0) + ]); } #[test] @@ -33,13 +30,10 @@ fn wikipedia() { ('c', 'e', 6), ('d', 'e', 7), ]; - assert_eq!( - kruskal(&edges).collect::>(), - vec![ - (&'a', &'e', 1), - (&'c', &'d', 2), - (&'a', &'b', 3), - (&'b', &'c', 5) - ] - ); + assert_eq!(kruskal(&edges).collect::>(), vec![ + (&'a', &'e', 1), + (&'c', &'d', 2), + (&'a', &'b', 3), + (&'b', &'c', 5) + ]); } diff --git a/tests/kuhn_munkres.rs b/tests/kuhn_munkres.rs index e5ee273a..c92a017a 100644 --- a/tests/kuhn_munkres.rs +++ b/tests/kuhn_munkres.rs @@ -34,12 +34,9 @@ fn tryalgo_examples() { #[test] fn cranes() { // Test from https://s-mat-pcs.oulu.fi/~mpa/matreng/eem1_2-1.htm. - let distances = matrix![ - [90, 75, 75, 80], - [35, 85, 55, 65], - [125, 95, 90, 105], - [45, 110, 95, 115], - ]; + let distances = matrix![[90, 75, 75, 80], [35, 85, 55, 65], [125, 95, 90, 105], [ + 45, 110, 95, 115 + ],]; assert_eq!(kuhn_munkres_min(&distances).0, 275); } @@ -60,12 +57,9 @@ fn mattkrick() { #[test] fn hungarian() { // Test from http://www.hungarianalgorithm.com/examplehungarianalgorithm.php - let weights = matrix![ - [82, 83, 69, 92], - [77, 37, 49, 92], - [11, 69, 5, 86], - [8, 9, 98, 23], - ]; + let weights = matrix![[82, 83, 69, 92], [77, 37, 49, 92], [11, 69, 5, 86], [ + 8, 9, 98, 23 + ],]; assert_eq!(kuhn_munkres_min(&weights).0, 140); } diff --git a/tests/matrix.rs b/tests/matrix.rs index 0fb71e03..d60b2db4 100644 --- a/tests/matrix.rs +++ b/tests/matrix.rs @@ -271,29 +271,17 @@ fn flip_square() { #[test] fn flip_non_square() { - let m1 = Matrix::from_vec( - 4, - 5, - vec![ - 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, - ], - ) + let m1 = Matrix::from_vec(4, 5, vec![ + 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, + ]) .unwrap(); - let m2 = Matrix::from_vec( - 4, - 5, - vec![ - 15, 16, 17, 18, 19, 10, 11, 12, 13, 14, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, - ], - ) + let m2 = Matrix::from_vec(4, 5, vec![ + 15, 16, 17, 18, 19, 10, 11, 12, 13, 14, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, + ]) .unwrap(); - let m3 = Matrix::from_vec( - 4, - 5, - vec![ - 4, 3, 2, 1, 0, 9, 8, 7, 6, 5, 14, 13, 12, 11, 10, 19, 18, 17, 16, 15, - ], - ) + let m3 = Matrix::from_vec(4, 5, vec![ + 4, 3, 2, 1, 0, 9, 8, 7, 6, 5, 14, 13, 12, 11, 10, 19, 18, 17, 16, 15, + ]) .unwrap(); assert_eq!(m1.flipped_ud(), m2); assert_eq!(m1.flipped_lr(), m3); @@ -396,26 +384,18 @@ fn set_slice() { .unwrap(); let m2 = Matrix::from_vec(3, 2, vec![10, 20, 30, 40, 50, 60]).unwrap(); m1.set_slice((2, 3), &m2); - assert_eq!( - m1.to_vec(), - [ - 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 10, 20, 15, 16, 17, 30, 40, 20, 21, 22, 50, - 60, - ] - ); + assert_eq!(m1.to_vec(), [ + 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 10, 20, 15, 16, 17, 30, 40, 20, 21, 22, 50, 60, + ]); let mut m1 = Matrix::square_from_vec(vec![ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, ]) .unwrap(); let m2 = Matrix::from_vec(4, 3, vec![10, 20, 22, 30, 40, 44, 50, 60, 66, 70, 80, 88]).unwrap(); m1.set_slice((2, 3), &m2); - assert_eq!( - m1.to_vec(), - [ - 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 10, 20, 15, 16, 17, 30, 40, 20, 21, 22, 50, - 60, - ] - ); + assert_eq!(m1.to_vec(), [ + 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 10, 20, 15, 16, 17, 30, 40, 20, 21, 22, 50, 60, + ]); } #[test] @@ -534,16 +514,21 @@ fn bfs_reachable() { let m = matrix![[0, 1, 2], [3, 4, 5], [6, 7, 8]]; let indices = m.bfs_reachable((1, 0), false, |n| m[n] % 4 != 0); - assert_eq!( - indices.into_iter().collect::>(), - vec![(1, 0), (2, 0), (2, 1)] - ); + assert_eq!(indices.into_iter().collect::>(), vec![ + (1, 0), + (2, 0), + (2, 1) + ]); let indices = m.bfs_reachable((1, 0), true, |n| m[n] % 4 != 0); - assert_eq!( - indices.into_iter().collect::>(), - vec![(0, 1), (0, 2), (1, 0), (1, 2), (2, 0), (2, 1)] - ); + assert_eq!(indices.into_iter().collect::>(), vec![ + (0, 1), + (0, 2), + (1, 0), + (1, 2), + (2, 0), + (2, 1) + ]); } #[test] @@ -555,10 +540,11 @@ fn bfs_reachable_mut() { counter += 1; m[n] % 4 != 0 }); - assert_eq!( - indices.into_iter().collect::>(), - vec![(1, 0), (2, 0), (2, 1)] - ); + assert_eq!(indices.into_iter().collect::>(), vec![ + (1, 0), + (2, 0), + (2, 1) + ]); assert_eq!(counter, 8); let mut counter = 0; @@ -566,10 +552,14 @@ fn bfs_reachable_mut() { counter += 1; m[n] % 4 != 0 }); - assert_eq!( - indices.into_iter().collect::>(), - vec![(0, 1), (0, 2), (1, 0), (1, 2), (2, 0), (2, 1)] - ); + assert_eq!(indices.into_iter().collect::>(), vec![ + (0, 1), + (0, 2), + (1, 0), + (1, 2), + (2, 0), + (2, 1) + ]); assert_eq!(counter, 26); } @@ -578,16 +568,21 @@ fn dfs_reachable() { let m = matrix![[0, 1, 2], [3, 4, 5], [6, 7, 8]]; let indices = m.dfs_reachable((1, 0), false, |n| m[n] % 4 != 0); - assert_eq!( - indices.into_iter().collect::>(), - vec![(1, 0), (2, 0), (2, 1)] - ); + assert_eq!(indices.into_iter().collect::>(), vec![ + (1, 0), + (2, 0), + (2, 1) + ]); let indices = m.dfs_reachable((1, 0), true, |n| m[n] % 4 != 0); - assert_eq!( - indices.into_iter().collect::>(), - vec![(0, 1), (0, 2), (1, 0), (1, 2), (2, 0), (2, 1)] - ); + assert_eq!(indices.into_iter().collect::>(), vec![ + (0, 1), + (0, 2), + (1, 0), + (1, 2), + (2, 0), + (2, 1) + ]); } #[test] @@ -599,10 +594,11 @@ fn dfs_reachable_mut() { counter += 1; m[n] % 4 != 0 }); - assert_eq!( - indices.into_iter().collect::>(), - vec![(1, 0), (2, 0), (2, 1)] - ); + assert_eq!(indices.into_iter().collect::>(), vec![ + (1, 0), + (2, 0), + (2, 1) + ]); assert_eq!(counter, 8); let mut counter = 0; @@ -610,10 +606,14 @@ fn dfs_reachable_mut() { counter += 1; m[n] % 4 != 0 }); - assert_eq!( - indices.into_iter().collect::>(), - vec![(0, 1), (0, 2), (1, 0), (1, 2), (2, 0), (2, 1)] - ); + assert_eq!(indices.into_iter().collect::>(), vec![ + (0, 1), + (0, 2), + (1, 0), + (1, 2), + (2, 0), + (2, 1) + ]); assert_eq!(counter, 26); } @@ -718,31 +718,38 @@ fn into_iter_is_fused() { } #[test] -#[allow(deprecated)] +#[expect(deprecated)] fn indices() { let m = matrix![[0, 1, 2], [2, 1, 0]]; - assert_eq!( - m.indices().collect::>(), - vec![(0, 0), (0, 1), (0, 2), (1, 0), (1, 1), (1, 2)] - ); + assert_eq!(m.indices().collect::>(), vec![ + (0, 0), + (0, 1), + (0, 2), + (1, 0), + (1, 1), + (1, 2) + ]); } #[test] fn keys() { let m = matrix![[0, 1, 2], [2, 1, 0]]; - assert_eq!( - m.keys().collect::>(), - vec![(0, 0), (0, 1), (0, 2), (1, 0), (1, 1), (1, 2)] - ); + assert_eq!(m.keys().collect::>(), vec![ + (0, 0), + (0, 1), + (0, 2), + (1, 0), + (1, 1), + (1, 2) + ]); } #[test] fn values() { let m = matrix![[0, 1, 2], [2, 1, 0]]; - assert_eq!( - m.values().copied().collect::>(), - vec![0, 1, 2, 2, 1, 0] - ); + assert_eq!(m.values().copied().collect::>(), vec![ + 0, 1, 2, 2, 1, 0 + ]); } #[test] @@ -764,38 +771,32 @@ fn in_direction() { m.in_direction((10, 10), (-1, -1)).collect::>(), vec![] ); - assert_eq!( - m.in_direction((4, 4), (-2, 0)).collect::>(), - vec![(2, 4), (0, 4)] - ); - assert_eq!( - m.in_direction((4, 4), (-3, 0)).collect::>(), - vec![(1, 4)] - ); - assert_eq!( - m.in_direction((4, 4), (2, 0)).collect::>(), - vec![(6, 4)] - ); - assert_eq!( - m.in_direction((4, 4), (3, 0)).collect::>(), - vec![(7, 4)] - ); - assert_eq!( - m.in_direction((4, 4), (0, -2)).collect::>(), - vec![(4, 2), (4, 0)] - ); - assert_eq!( - m.in_direction((4, 4), (0, -3)).collect::>(), - vec![(4, 1)] - ); - assert_eq!( - m.in_direction((4, 4), (0, 2)).collect::>(), - vec![(4, 6)] - ); - assert_eq!( - m.in_direction((4, 4), (0, 3)).collect::>(), - vec![(4, 7)] - ); + assert_eq!(m.in_direction((4, 4), (-2, 0)).collect::>(), vec![ + (2, 4), + (0, 4) + ]); + assert_eq!(m.in_direction((4, 4), (-3, 0)).collect::>(), vec![( + 1, 4 + )]); + assert_eq!(m.in_direction((4, 4), (2, 0)).collect::>(), vec![( + 6, 4 + )]); + assert_eq!(m.in_direction((4, 4), (3, 0)).collect::>(), vec![( + 7, 4 + )]); + assert_eq!(m.in_direction((4, 4), (0, -2)).collect::>(), vec![ + (4, 2), + (4, 0) + ]); + assert_eq!(m.in_direction((4, 4), (0, -3)).collect::>(), vec![( + 4, 1 + )]); + assert_eq!(m.in_direction((4, 4), (0, 2)).collect::>(), vec![( + 4, 6 + )]); + assert_eq!(m.in_direction((4, 4), (0, 3)).collect::>(), vec![( + 4, 7 + )]); } #[test] diff --git a/tests/pathfinding.rs b/tests/pathfinding.rs index 1daff697..5f381665 100644 --- a/tests/pathfinding.rs +++ b/tests/pathfinding.rs @@ -3,8 +3,8 @@ mod ex1 { use lazy_static::lazy_static; use pathfinding::prelude::*; - #[allow(clippy::trivially_copy_pass_by_ref)] - fn successors(node: &u8) -> impl Iterator { + #[expect(clippy::trivially_copy_pass_by_ref)] + fn successors(node: &u8) -> impl Iterator + use<> { lazy_static! { static ref SUCCESSORS: Vec> = vec![ vec![(1, 7), (2, 7), (3, 6)], @@ -225,9 +225,11 @@ mod ex2 { .unwrap(); assert_eq!(cost, 8); assert_eq!(paths.len(), 1); - assert!(paths - .iter() - .all(|path| path.iter().all(|&(nx, ny)| OPEN[ny][nx]))); + assert!( + paths + .iter() + .all(|path| path.iter().all(|&(nx, ny)| OPEN[ny][nx])) + ); assert_eq!(counter, 15); } @@ -247,9 +249,11 @@ mod ex2 { .unwrap(); assert_eq!(cost, 9); assert_eq!(paths.len(), 3); - assert!(paths - .iter() - .all(|path| path.iter().all(|&(nx, ny)| OPEN[ny][nx]))); + assert!( + paths + .iter() + .all(|path| path.iter().all(|&(nx, ny)| OPEN[ny][nx])) + ); assert_eq!(counter, 18); } diff --git a/tests/prim.rs b/tests/prim.rs index f4b1275c..21b244e6 100644 --- a/tests/prim.rs +++ b/tests/prim.rs @@ -12,15 +12,12 @@ fn base_test() { ('c', 'e', 6), ('d', 'e', 7), ]; - assert_eq!( - prim(&edges), - vec![ - (&'a', &'e', 1), - (&'a', &'b', 3), - (&'b', &'c', 5), - (&'c', &'d', 2), - ] - ); + assert_eq!(prim(&edges), vec![ + (&'a', &'e', 1), + (&'a', &'b', 3), + (&'b', &'c', 5), + (&'c', &'d', 2), + ]); } #[test] @@ -42,19 +39,16 @@ fn geeksforgeeks() { (6, 8, 6), (7, 8, 7), ]; - assert_eq!( - prim(&edges), - vec![ - (&0, &1, 4), - (&0, &7, 8), - (&7, &6, 1), - (&6, &5, 2), - (&5, &2, 4), - (&2, &8, 2), - (&2, &3, 7), - (&3, &4, 9), - ] - ); + assert_eq!(prim(&edges), vec![ + (&0, &1, 4), + (&0, &7, 8), + (&7, &6, 1), + (&6, &5, 2), + (&5, &2, 4), + (&2, &8, 2), + (&2, &3, 7), + (&3, &4, 9), + ]); } // Order of edges is not important in the result, except for starting edge, because always @@ -71,13 +65,10 @@ fn another_test() { ('C', 'E', 6), ('D', 'E', 1), ]; - assert_eq!( - prim(&edges), - vec![ - (&'B', &'D', 4), - (&'D', &'E', 1), - (&'D', &'C', 2), - (&'C', &'A', 3), - ] - ); + assert_eq!(prim(&edges), vec![ + (&'B', &'D', 4), + (&'D', &'E', 1), + (&'D', &'C', 2), + (&'C', &'A', 3), + ]); } diff --git a/tests/strongly_connected_components.rs b/tests/strongly_connected_components.rs index 4d408a83..87bae17e 100644 --- a/tests/strongly_connected_components.rs +++ b/tests/strongly_connected_components.rs @@ -5,7 +5,7 @@ use std::collections::hash_map::HashMap; // Tests in this file use the example at // https://en.wikipedia.org/wiki/Strongly_connected_component#/media/File:Graph_Condensation.svg -#[allow(clippy::trivially_copy_pass_by_ref)] +#[expect(clippy::trivially_copy_pass_by_ref)] fn successors(n: &usize) -> Vec { match *n { 0 => vec![2], diff --git a/tests/topological_sort.rs b/tests/topological_sort.rs index ea72438a..32a3dcce 100644 --- a/tests/topological_sort.rs +++ b/tests/topological_sort.rs @@ -38,11 +38,7 @@ fn complexity() { let mut requested = 0; let result = tsort(&ints, |&n| { requested += 1; - if n < 999 { - vec![n + 1] - } else { - vec![] - } + if n < 999 { vec![n + 1] } else { vec![] } }); assert_eq!(result, Ok((1..1000).collect_vec())); assert_eq!(requested, 999); @@ -51,7 +47,7 @@ fn complexity() { // Wrapper around topological_sort_into_groups that sorts each group (since // topological_sort_into_groups makes no guarantees about node order within // each group). -#[allow(clippy::type_complexity)] +#[expect(clippy::type_complexity)] fn tsig(succs: &[&[usize]]) -> Result>, (Vec>, Vec)> { let nodes: Vec = (0..succs.len()).collect(); match topological_sort_into_groups(&nodes, |&n| succs[n].iter().copied()) { diff --git a/tests/version.rs b/tests/version.rs index cfbd94d0..62c759b6 100644 --- a/tests/version.rs +++ b/tests/version.rs @@ -11,7 +11,10 @@ fn check_version() { assert!( trim(VERSION).starts_with(&trim(version)), "Version in README.md ({} - seen as {}) is not compatible with Cargo.toml ({} - seen as {})", - version, trim(version), VERSION, trim(VERSION), + version, + trim(version), + VERSION, + trim(VERSION), ); } diff --git a/tests/yen.rs b/tests/yen.rs index 74010330..4b4f6fe3 100644 --- a/tests/yen.rs +++ b/tests/yen.rs @@ -45,10 +45,9 @@ fn ask_more_than_exist() { ); // we asked for 10 but the graph can only produce 7 - assert_eq!( - result.iter().map(|&(_, c)| c).collect::>(), - vec![5, 7, 8, 8, 8, 11, 11] - ); + assert_eq!(result.iter().map(|&(_, c)| c).collect::>(), vec![ + 5, 7, 8, 8, 8, 11, 11 + ]); } /// Test that we return None in case there is no solution @@ -129,16 +128,13 @@ fn all_paths() { usize::MAX, ); result.sort_unstable(); - assert_eq!( - result, - vec![ - (vec!['a', 'b', 'c', 'd'], 3), - (vec!['a', 'b', 'd'], 2), - (vec!['a', 'c', 'b', 'd'], 3), - (vec!['a', 'c', 'd'], 2), - (vec!['a', 'd'], 1), - ] - ); + assert_eq!(result, vec![ + (vec!['a', 'b', 'c', 'd'], 3), + (vec!['a', 'b', 'd'], 2), + (vec!['a', 'c', 'b', 'd'], 3), + (vec!['a', 'c', 'd'], 2), + (vec!['a', 'd'], 1), + ]); } #[test]