Skip to content

Commit 30939fe

Browse files
ABorgnaaborgna-q
andauthored
chore: Fix all clippy lints and check them on CI (petgraph#726)
drive-by: Bump edition from `2018` to `2021` --------- Co-authored-by: Agustín Borgna <[email protected]>
1 parent 3fbb808 commit 30939fe

37 files changed

+234
-251
lines changed

.github/workflows/ci.yml

+44-26
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ name: Continuous integration
1212
env:
1313
CARGO_TERM_COLOR: always
1414
CARGO_INCREMENTAL: 0
15+
SCCACHE_GHA_ENABLED: "true"
16+
RUSTC_WRAPPER: "sccache"
1517

1618
jobs:
1719
tests:
@@ -29,58 +31,74 @@ jobs:
2931
features: unstable quickcheck rayon
3032
test_all: --all
3133
bench: true
34+
name: Tests (Rust ${{ matrix.rust }})
3235

3336
steps:
3437
- uses: actions/checkout@v4
35-
- uses: actions-rs/toolchain@v1
38+
- uses: mozilla-actions/[email protected]
39+
- id: toolchain
40+
uses: dtolnay/rust-toolchain@master
3641
with:
37-
profile: minimal
3842
toolchain: ${{ matrix.rust }}
39-
override: true
43+
- name: Configure default rust toolchain
44+
run: rustup override set ${{steps.toolchain.outputs.name}}
45+
4046
- name: MSRV downgrade
4147
if: matrix.rust == '1.64.0'
4248
run: |
4349
cargo generate-lockfile
4450
cargo update -p hashbrown --precise 0.15.0
45-
- name: Build
46-
run: |
47-
cargo build --verbose --no-default-features
48-
cargo build --verbose --features "${{ matrix.features }}"
49-
- name: Tests
50-
run: |
51-
cargo test --verbose --no-default-features
52-
cargo test ${{ matrix.test_all }} --verbose --features "${{ matrix.features }}"
51+
52+
- name: Build with no features
53+
run: cargo build --verbose --no-default-features
54+
- name: Test with no features
55+
run: cargo test --verbose --no-default-features
56+
57+
- name: Build with features "${{ matrix.features }}"
58+
run: cargo build --verbose --features "${{ matrix.features }}"
59+
- name: Test with features "${{ matrix.features }}"
60+
run: cargo test ${{ matrix.test_all }} --verbose --features "${{ matrix.features }}"
61+
5362
- name: Build benchmarks
5463
if: ${{ matrix.bench }}
5564
run: |
5665
cargo bench --verbose --no-run
5766
cargo bench --verbose --no-run --all-features
5867
59-
rustfmt:
68+
check:
69+
name: Lints
6070
runs-on: ubuntu-latest
61-
continue-on-error: true
62-
strategy:
63-
matrix:
64-
include:
65-
- rust: stable
66-
rustfmt: rustfmt
67-
6871
steps:
6972
- uses: actions/checkout@v4
70-
- uses: actions-rs/toolchain@v1
73+
- uses: mozilla-actions/[email protected]
74+
- name: Install stable toolchain
75+
uses: dtolnay/rust-toolchain@stable
7176
with:
72-
profile: minimal
73-
toolchain: ${{ matrix.rust }}
74-
components: ${{ matrix.rustfmt }}
75-
override: true
76-
- name: Rustfmt
77-
if: matrix.rustfmt
77+
components: rustfmt, clippy
78+
79+
- name: Check formatting
7880
run: cargo fmt -- --check
7981

82+
- name: Run clippy
83+
# The benchmarks target require nightly,
84+
# so we cannot use --all-targets here.
85+
run: |
86+
cargo clippy --all-features \
87+
--lib --bins --examples --tests \
88+
-- -D warnings
89+
90+
- name: Build docs
91+
run: cargo doc --no-deps --all-features
92+
env:
93+
RUSTDOCFLAGS: "-Dwarnings"
94+
8095
miri:
96+
name: Unsoundness check
97+
if: github.event_name != 'merge_group'
8198
runs-on: ubuntu-latest
8299
steps:
83100
- uses: actions/checkout@v4
101+
- uses: mozilla-actions/[email protected]
84102
- uses: dtolnay/rust-toolchain@nightly
85103
with:
86104
components: miri

Cargo.toml

+11-7
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ name = "petgraph"
44
version = "0.7.1"
55
readme = "README.md"
66
license = "MIT OR Apache-2.0"
7-
authors = ["bluss", "mitchmindtree"]
7+
authors = { workspace = true }
88

99
description = "Graph data structure library. Provides graph types and graph algorithms."
1010
documentation = "https://docs.rs/petgraph/"
@@ -13,16 +13,23 @@ repository = "https://github.com/petgraph/petgraph"
1313
keywords = ["data-structure", "graph", "unionfind", "graph-algorithms"]
1414
categories = ["data-structures"]
1515

16-
rust-version = "1.64"
17-
18-
edition = "2018"
16+
rust-version = { workspace = true }
17+
edition = { workspace = true }
1918

2019
[package.metadata.docs.rs]
2120
features = ["rayon", "serde-1", "quickcheck"]
2221

2322
[package.metadata.release]
2423
no-dev-version = true
2524

25+
[workspace.package]
26+
rust-version = "1.64"
27+
edition = "2021"
28+
authors = ["bluss", "mitchmindtree"]
29+
30+
[workspace]
31+
members = [".", "serialization-tests"]
32+
2633
[lib]
2734
bench = false
2835

@@ -71,6 +78,3 @@ matrix_graph = []
7178
serde-1 = ["serde", "serde_derive"]
7279
stable_graph = []
7380
unstable = ["generate"]
74-
75-
[workspace]
76-
members = ["serialization-tests"]

benches/articulation_points.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,12 @@ use test::Bencher;
1111
fn bridges_bench(bench: &mut Bencher) {
1212
static NODE_COUNT: usize = 1000;
1313
let mut g = Graph::new_undirected();
14-
let nodes: Vec<NodeIndex<_>> = (0..NODE_COUNT).into_iter().map(|i| g.add_node(i)).collect();
14+
let nodes: Vec<NodeIndex<_>> = (0..NODE_COUNT).map(|i| g.add_node(i)).collect();
1515
for i in 0..NODE_COUNT {
1616
let n1 = nodes[i];
1717
let neighbour_count = i % 8 + 1;
1818

19-
for j in (i % 117)..(i % 117) + neighbour_count {
20-
let n2 = nodes[j];
19+
for &n2 in nodes.iter().skip(i % 117).take(neighbour_count) {
2120
g.add_edge(n1, n2, ());
2221
}
2322
}

benches/coloring.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,14 @@ use petgraph::algo::dsatur_coloring;
1313
fn dsatur_coloring_bench(bench: &mut Bencher) {
1414
static NODE_COUNT: usize = 10_000;
1515
let mut g = Graph::new_undirected();
16-
let nodes: Vec<NodeIndex<_>> = (0..NODE_COUNT).into_iter().map(|i| g.add_node(i)).collect();
16+
let nodes: Vec<NodeIndex<_>> = (0..NODE_COUNT).map(|i| g.add_node(i)).collect();
1717
for i in 0..NODE_COUNT {
1818
let n1 = nodes[i];
1919
let neighbour_count = i % 8 + 3;
2020
let j_from = max(0, i as i32 - neighbour_count as i32 / 2) as usize;
2121
let j_to = min(NODE_COUNT, j_from + neighbour_count);
22+
23+
#[allow(clippy::needless_range_loop)]
2224
for j in j_from..j_to {
2325
let n2 = nodes[j];
2426
g.add_edge(n1, n2, ());

benches/common/factories.rs

+9-10
Original file line numberDiff line numberDiff line change
@@ -177,9 +177,8 @@ const BIPARTITE: &str = "
177177
";
178178

179179
/// Parse a text adjacency matrix format into a directed graph
180-
fn parse_graph<Ty, G>(s: &str) -> G
180+
fn parse_graph<G>(s: &str) -> G
181181
where
182-
Ty: EdgeType,
183182
G: Default + Build<NodeWeight = (), EdgeWeight = ()> + NodeIndexable,
184183
{
185184
let mut g: G = Default::default();
@@ -221,35 +220,35 @@ where
221220
}
222221

223222
pub fn petersen_a(self) -> G {
224-
parse_graph::<Ty, _>(PETERSEN_A)
223+
parse_graph::<_>(PETERSEN_A)
225224
}
226225

227226
pub fn petersen_b(self) -> G {
228-
parse_graph::<Ty, _>(PETERSEN_B)
227+
parse_graph::<_>(PETERSEN_B)
229228
}
230229

231230
pub fn full_a(self) -> G {
232-
parse_graph::<Ty, _>(FULL_A)
231+
parse_graph::<_>(FULL_A)
233232
}
234233

235234
pub fn full_b(self) -> G {
236-
parse_graph::<Ty, _>(FULL_B)
235+
parse_graph::<_>(FULL_B)
237236
}
238237

239238
pub fn praust_a(self) -> G {
240-
parse_graph::<Ty, _>(PRAUST_A)
239+
parse_graph::<_>(PRAUST_A)
241240
}
242241

243242
pub fn praust_b(self) -> G {
244-
parse_graph::<Ty, _>(PRAUST_B)
243+
parse_graph::<_>(PRAUST_B)
245244
}
246245

247246
pub fn bigger(self) -> G {
248-
parse_graph::<Ty, _>(BIGGER)
247+
parse_graph::<_>(BIGGER)
249248
}
250249

251250
pub fn bipartite(self) -> G {
252-
parse_graph::<Ty, _>(BIPARTITE)
251+
parse_graph::<_>(BIPARTITE)
253252
}
254253
}
255254

benches/graphmap.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,12 @@ fn test_nodes() -> Vec<MyStruct> {
3030
}
3131

3232
fn test_graph<H: BuildHasher + Default>(
33-
data: &Vec<MyStruct>,
33+
data: &[MyStruct],
3434
) -> GraphMap<&MyStruct, usize, Directed, H> {
3535
let mut gr = GraphMap::new();
3636

37-
for i in 0..2500 {
38-
gr.add_node(&data[i]);
37+
for val in data {
38+
gr.add_node(val);
3939
}
4040

4141
for i in 0..1_000 {
@@ -76,7 +76,7 @@ fn graphmap_parallel_bench(bench: &mut Bencher) {
7676
let data = test_nodes();
7777
let gr = test_graph::<std::hash::RandomState>(&data);
7878
bench.iter(|| {
79-
let sources: Vec<MyStruct> = gr
79+
let _sources: Vec<MyStruct> = gr
8080
.par_nodes()
8181
.map(|n| {
8282
let mut sources = vec![];

benches/page_rank.rs

-2
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,6 @@ use common::directed_fan;
1313

1414
#[cfg(feature = "rayon")]
1515
use petgraph::algo::page_rank::parallel_page_rank;
16-
#[cfg(feature = "rayon")]
17-
use rayon::prelude::*;
1816

1917
#[bench]
2018
fn page_rank_bench(bench: &mut Bencher) {

clippy.toml

-1
This file was deleted.

serialization-tests/Cargo.toml

+4-3
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,10 @@ name = "petgraph-serialization-tests"
44
version = "0.0.0"
55
publish = false
66
license = "MIT/Apache-2.0"
7-
authors = [
8-
"bluss",
9-
]
7+
authors = ["bluss"]
8+
9+
rust-version = { workspace = true }
10+
edition = { workspace = true }
1011

1112
description = ""
1213
documentation = ""

src/algo/articulation_points.rs

+12-14
Original file line numberDiff line numberDiff line change
@@ -23,23 +23,21 @@ use std::hash::Hash;
2323
/// algo::articulation_points::articulation_points,
2424
/// };
2525
///
26-
/// fn main() {
27-
/// let mut gr = UnGraph::<&str, ()>::new_undirected();
28-
/// let a = gr.add_node("A");
29-
/// let b = gr.add_node("B");
30-
/// let c = gr.add_node("C");
26+
/// let mut gr = UnGraph::<&str, ()>::new_undirected();
27+
/// let a = gr.add_node("A");
28+
/// let b = gr.add_node("B");
29+
/// let c = gr.add_node("C");
3130
///
32-
/// gr.add_edge(a, b, ());
33-
/// gr.add_edge(b, c, ());
31+
/// gr.add_edge(a, b, ());
32+
/// gr.add_edge(b, c, ());
3433
///
35-
/// let articulation_points: Vec<&str> = articulation_points(&gr)
36-
/// .into_iter()
37-
/// .map(|node_idx| gr[node_idx])
38-
/// .collect();
34+
/// let articulation_points: Vec<&str> = articulation_points(&gr)
35+
/// .into_iter()
36+
/// .map(|node_idx| gr[node_idx])
37+
/// .collect();
3938
///
40-
/// // Articulation Points: ["B"]
41-
/// println!("Articulation Points: {:?}", articulation_points);
42-
/// }
39+
/// // Articulation Points: ["B"]
40+
/// println!("Articulation Points: {:?}", articulation_points);
4341
/// ```
4442
pub fn articulation_points<G>(g: G) -> HashSet<G::NodeId>
4543
where

src/algo/coloring.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use crate::scored::MaxScored;
55
use crate::visit::{IntoEdges, IntoNodeIdentifiers, NodeIndexable, VisitMap, Visitable};
66

77
/// \[Generic\] DStatur algorithm to properly color a non weighted undirected graph.
8-
/// https://en.wikipedia.org/wiki/DSatur
8+
/// <https://en.wikipedia.org/wiki/DSatur>
99
///
1010
/// This is a heuristic. So, it does not necessarily return a minimum coloring.
1111
///
@@ -47,7 +47,6 @@ use crate::visit::{IntoEdges, IntoNodeIdentifiers, NodeIndexable, VisitMap, Visi
4747
/// assert_eq!(nb_colors, 2);
4848
/// assert_ne!(coloring[&a], coloring[&b]);
4949
/// ```
50-
5150
pub fn dsatur_coloring<G>(graph: G) -> (HashMap<G::NodeId, usize>, usize)
5251
where
5352
G: IntoEdges + IntoNodeIdentifiers + Visitable + NodeIndexable,

src/algo/dominators.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ where
149149

150150
/// The undefined dominator sentinel, for when we have not yet discovered a
151151
/// node's dominator.
152-
const UNDEFINED: usize = ::std::usize::MAX;
152+
const UNDEFINED: usize = usize::MAX;
153153

154154
/// This is an implementation of the engineered ["Simple, Fast Dominance
155155
/// Algorithm"][0] discovered by Cooper et al.

0 commit comments

Comments
 (0)