Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Changes to be merged with MSRV 1.81 #626

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
7 changes: 4 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ authors = ["Samuel Tardieu <sam@rfc1149.net>"]
categories = ["algorithms"]
readme = "README.md"
edition = "2021"
rust-version = "1.77.2"
rust-version = "1.81.0"

[package.metadata.release]
sign-commit = true
Expand All @@ -32,7 +32,6 @@ deprecate-until = "0.1.1"
[dev-dependencies]
codspeed-criterion-compat = "2.7.2"
itertools = "0.14.0"
lazy_static = "1.5.0"
movingai = "1.3.1"
noisy_float = "0.2.0"
rand = "0.8.5"
Expand All @@ -47,7 +46,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"
Expand Down
4 changes: 2 additions & 2 deletions benches/matrices.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use codspeed_criterion_compat::{criterion_group, criterion_main, Criterion};
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<i32> = (0..100 * 100).collect();
Expand All @@ -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<i32> = (0..100 * 100).collect();
Expand Down
4 changes: 2 additions & 2 deletions benches/movingai.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ 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(|| {
Expand Down
49 changes: 23 additions & 26 deletions examples/sliding-puzzle.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use itertools::Itertools;
use lazy_static::lazy_static;
use pathfinding::prelude::{astar, idastar};
use rand::prelude::*;
use rand::rngs::OsRng;
use std::sync::LazyLock;
use std::thread;
use std::time::Instant;

Expand All @@ -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
Expand All @@ -30,30 +30,27 @@ impl PartialEq for Game {

impl Eq for Game {}

lazy_static! {
static ref GOAL: Game = Game {
positions: {
let mut p = [0u8; LIMIT];
for (i, e) in p.iter_mut().enumerate() {
*e = u8::try_from(i).unwrap();
}
p
},
hole_idx: 0,
weight: 0,
};
static ref SUCCESSORS: Vec<Vec<u8>> = (0..SIDE * SIDE)
.map(|idx| (0..4)
.filter_map(|dir| match dir {
0 if idx % SIDE > 0 => Some(idx - 1),
1 if idx >= SIDE => Some(idx - SIDE),
2 if idx % SIDE < SIDE - 1 => Some(idx + 1),
3 if idx < SIDE * SIDE - SIDE => Some(idx + SIDE),
_ => None,
})
.collect::<Vec<_>>())
.collect();
}
static GOAL: LazyLock<Game> = LazyLock::new(|| Game {
positions: (0..(SIDE * SIDE)).collect::<Vec<_>>().try_into().unwrap(),
hole_idx: 0,
weight: 0,
});

static SUCCESSORS: LazyLock<Vec<Vec<u8>>> = LazyLock::new(|| {
(0..SIDE * SIDE)
.map(|idx| {
(0..4)
.filter_map(|dir| match dir {
0 if idx % SIDE > 0 => Some(idx - 1),
1 if idx >= SIDE => Some(idx - SIDE),
2 if idx % SIDE < SIDE - 1 => Some(idx + 1),
3 if idx < SIDE * SIDE - SIDE => Some(idx + SIDE),
_ => None,
})
.collect::<Vec<_>>()
})
.collect()
});

impl Game {
/// Move the hole to the given index.
Expand Down
4 changes: 2 additions & 2 deletions src/directed/astar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<N, C, FN, IN, FH, FS>(
start: &N,
mut successors: FN,
Expand Down Expand Up @@ -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<N, C, FN, IN, FH, FS>(
start: &N,
mut successors: FN,
Expand Down
4 changes: 2 additions & 2 deletions src/directed/dijkstra.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<N, C, FN, IN, FS>(
start: &N,
mut successors: FN,
Expand Down Expand Up @@ -283,7 +283,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<N, C>(target: &N, parents: &HashMap<N, (N, C)>) -> Vec<N>
where
N: Eq + Hash + Clone,
Expand Down
2 changes: 1 addition & 1 deletion src/directed/fringe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<N, C, FN, IN, FH, FS>(
start: &N,
mut successors: FN,
Expand Down
2 changes: 1 addition & 1 deletion src/directed/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<N, V, F>(parents: &FxIndexMap<N, V>, mut parent: F, start: usize) -> Vec<N>
where
N: Eq + Hash + Clone,
Expand Down
2 changes: 1 addition & 1 deletion src/directed/strongly_connected_components.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<N, FN, IN>(node: &N, successors: FN) -> Vec<N>
where
N: Clone + Hash + Eq,
Expand Down
4 changes: 2 additions & 2 deletions src/directed/topological_sort.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<N, FN, IN>(
nodes: &[N],
mut successors: FN,
Expand Down
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.81.0.
//!
//! [A*]: https://en.wikipedia.org/wiki/A*_search_algorithm
//! [BFS]: https://en.wikipedia.org/wiki/Breadth-first_search
Expand Down
2 changes: 1 addition & 1 deletion src/undirected/connected_components.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<N>(components: &[HashSet<N>]) -> HashMap<N, usize>
where
N: Clone + Hash + Eq,
Expand Down
4 changes: 2 additions & 2 deletions src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down Expand Up @@ -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
Expand Down
26 changes: 14 additions & 12 deletions tests/aoc-2017-12-12.rs
Original file line number Diff line number Diff line change
@@ -1,20 +1,22 @@
// Test from https://adventofcode.com/, 2017-12-12

use lazy_static::lazy_static;
use pathfinding::prelude::*;
use std::{
collections::{HashMap, HashSet},
sync::LazyLock,
};

use std::collections::{HashMap, HashSet};

lazy_static! {
static ref PIPES: Vec<Vec<usize>> = include_str!("aoc-2017-12-12.txt")
static PIPES: LazyLock<Vec<Vec<usize>>> = LazyLock::new(|| {
include_str!("aoc-2017-12-12.txt")
.lines()
.map(|line| line
.replace(" <->", ",")
.split(", ")
.map(|w| w.parse::<usize>().unwrap())
.collect::<Vec<_>>())
.collect::<Vec<_>>();
}
.map(|line| {
line.replace(" <->", ",")
.split(", ")
.map(|w| w.parse::<usize>().unwrap())
.collect::<Vec<_>>()
})
.collect::<Vec<_>>()
});

#[test]
fn method1() {
Expand Down
4 changes: 2 additions & 2 deletions tests/codejam-2017-a.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down Expand Up @@ -99,7 +99,7 @@ fn test<EK: EdmondsKarp<i32>>(n: usize, file: &mut dyn BufRead) -> Result<String
loop {
let (_, n, _) = ek.augment();
debug_assert!(n >= 0);
#[allow(clippy::cast_sign_loss)]
#[expect(clippy::cast_sign_loss)]
let n = n as usize;
if n > max {
max = n;
Expand Down
2 changes: 1 addition & 1 deletion tests/edmondskarp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ fn wikipedia_example_sparse() {
wikipedia_example::<SparseCapacity<_>>();
}

#[allow(clippy::cast_possible_truncation)]
#[expect(clippy::cast_possible_truncation)]
fn wikipedia_progressive_example<EK: EdmondsKarp<i32>>() {
let successors = successors_wikipedia();
let size = successors.len();
Expand Down
2 changes: 1 addition & 1 deletion tests/gps.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ 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();
Expand Down
2 changes: 1 addition & 1 deletion tests/matrix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -718,7 +718,7 @@ fn into_iter_is_fused() {
}

#[test]
#[allow(deprecated)]
#[expect(deprecated)]
fn indices() {
let m = matrix![[0, 1, 2], [2, 1, 0]];
assert_eq!(
Expand Down
38 changes: 17 additions & 21 deletions tests/pathfinding.rs
Original file line number Diff line number Diff line change
@@ -1,23 +1,20 @@
mod ex1 {

use lazy_static::lazy_static;
use pathfinding::prelude::*;

#[allow(clippy::trivially_copy_pass_by_ref)]
#[expect(clippy::trivially_copy_pass_by_ref)]
fn successors(node: &u8) -> impl Iterator<Item = (u8, usize)> {
lazy_static! {
static ref SUCCESSORS: Vec<Vec<(u8, usize)>> = vec![
vec![(1, 7), (2, 7), (3, 6)],
vec![(0, 8), (6, 7)],
vec![(5, 7)],
vec![(7, 7)],
vec![(4, 2)],
vec![(1, 1)],
vec![(2, 5), (4, 5), (5, 2)],
vec![(5, 8)],
vec![],
];
}
const SUCCESSORS: &[&[(u8, usize)]] = &[
&[(1, 7), (2, 7), (3, 6)],
&[(0, 8), (6, 7)],
&[(5, 7)],
&[(7, 7)],
&[(4, 2)],
&[(1, 1)],
&[(2, 5), (4, 5), (5, 2)],
&[(5, 8)],
&[],
];
SUCCESSORS[*node as usize].iter().copied()
}

Expand Down Expand Up @@ -158,8 +155,8 @@ mod ex1 {

mod ex2 {

use lazy_static::lazy_static;
use pathfinding::prelude::*;
use std::sync::LazyLock;

const MAZE: &str = "\
#########
Expand All @@ -172,12 +169,11 @@ mod ex2 {
#########
";

lazy_static! {
static ref OPEN: Vec<Vec<bool>> = MAZE
.lines()
static OPEN: LazyLock<Vec<Vec<bool>>> = LazyLock::new(|| {
MAZE.lines()
.map(|l| l.chars().map(|c| c == '.').collect())
.collect();
}
.collect()
});

fn successors(&(x, y): &(usize, usize)) -> Vec<((usize, usize), usize)> {
vec![(x - 1, y), (x + 1, y), (x, y - 1), (x, y + 1)]
Expand Down
Loading
Loading