From bd9f9b184c19408a0ec2e51672bbc82f10def84d Mon Sep 17 00:00:00 2001 From: Hubert Hirtz Date: Mon, 13 Jun 2022 14:31:47 +0200 Subject: [PATCH] Enable the rust_2018_idioms lint as warning This should become the default in the future: https://github.com/rust-lang/rust/issues/54910 Reason this is put in lib.rs instead of CI: to ensure local invocations of cargo build and cargo clippy pick up the warning. Reason this is made a warning: so that code builds and runs anyway. On the CI, the `-D warnings` clippy argument will treat it as a hard error. --- src/algorithms/fiduccia_mattheyses.rs | 4 ++-- src/algorithms/graph_growth.rs | 4 ++-- src/algorithms/k_means.rs | 6 +++--- src/algorithms/kernighan_lin.rs | 6 +++--- src/algorithms/recursive_bisection.rs | 4 ++-- src/lib.rs | 2 ++ src/topology.rs | 6 +++--- 7 files changed, 17 insertions(+), 15 deletions(-) diff --git a/src/algorithms/fiduccia_mattheyses.rs b/src/algorithms/fiduccia_mattheyses.rs index b5bc7a3e..a4f71ed2 100644 --- a/src/algorithms/fiduccia_mattheyses.rs +++ b/src/algorithms/fiduccia_mattheyses.rs @@ -34,7 +34,7 @@ struct Move { fn fiduccia_mattheyses( partition: &mut [usize], weights: &[W], - adjacency: CsMatView, + adjacency: CsMatView<'_, i64>, max_passes: usize, max_moves_per_pass: usize, max_imbalance: Option, @@ -362,7 +362,7 @@ where fn partition( &mut self, part_ids: &mut [usize], - (adjacency, weights): (CsMatView, &'a [W]), + (adjacency, weights): (CsMatView<'_, i64>, &'a [W]), ) -> Result { if part_ids.is_empty() { return Ok(Metadata::default()); diff --git a/src/algorithms/graph_growth.rs b/src/algorithms/graph_growth.rs index 717c2d9e..9cd78e58 100644 --- a/src/algorithms/graph_growth.rs +++ b/src/algorithms/graph_growth.rs @@ -4,7 +4,7 @@ use sprs::CsMatView; fn graph_growth( initial_ids: &mut [usize], weights: &[f64], - adjacency: CsMatView, + adjacency: CsMatView<'_, f64>, num_parts: usize, ) { let (shape_x, shape_y) = adjacency.shape(); @@ -126,7 +126,7 @@ where fn partition( &mut self, part_ids: &mut [usize], - (adjacency, weights): (CsMatView, W), + (adjacency, weights): (CsMatView<'_, f64>, W), ) -> Result { graph_growth( part_ids, diff --git a/src/algorithms/k_means.rs b/src/algorithms/k_means.rs index d4d37660..97da1f1d 100644 --- a/src/algorithms/k_means.rs +++ b/src/algorithms/k_means.rs @@ -174,10 +174,10 @@ struct AlgorithmState<'a> { // - checking delta threshold // - relaxing lower and upper bounds fn balanced_k_means_iter( - inputs: Inputs, + inputs: Inputs<'_, D>, clusters: Clusters>, &[ClusterId]>, permutation: &mut [usize], - state: AlgorithmState, + state: AlgorithmState<'_>, settings: &BalancedKmeansSettings, current_iter: usize, ) where @@ -300,7 +300,7 @@ fn assign_and_balance( points: &[PointND], weights: &[f64], permutation: &mut [usize], - state: AlgorithmState, + state: AlgorithmState<'_>, clusters: Clusters<&[PointND], &[ClusterId]>, settings: &BalancedKmeansSettings, ) where diff --git a/src/algorithms/kernighan_lin.rs b/src/algorithms/kernighan_lin.rs index 9bbe2bf3..6eca5104 100644 --- a/src/algorithms/kernighan_lin.rs +++ b/src/algorithms/kernighan_lin.rs @@ -9,7 +9,7 @@ use sprs::CsMatView; fn kernighan_lin( part_ids: &mut [usize], weights: &[f64], - adjacency: CsMatView, + adjacency: CsMatView<'_, f64>, max_passes: Option, max_flips_per_pass: Option, max_imbalance_per_flip: Option, @@ -34,7 +34,7 @@ fn kernighan_lin( fn kernighan_lin_2_impl( initial_partition: &mut [usize], weights: &[f64], - adjacency: CsMatView, + adjacency: CsMatView<'_, f64>, max_passes: Option, max_flips_per_pass: Option, _max_imbalance_per_flip: Option, @@ -265,7 +265,7 @@ impl<'a> crate::Partition<(CsMatView<'a, f64>, &'a [f64])> for KernighanLin { fn partition( &mut self, part_ids: &mut [usize], - (adjacency, weights): (CsMatView, &'a [f64]), + (adjacency, weights): (CsMatView<'_, f64>, &'a [f64]), ) -> Result { kernighan_lin( part_ids, diff --git a/src/algorithms/recursive_bisection.rs b/src/algorithms/recursive_bisection.rs index 2f794b1a..d237bbfa 100644 --- a/src/algorithms/recursive_bisection.rs +++ b/src/algorithms/recursive_bisection.rs @@ -151,7 +151,7 @@ where } fn rcb_recurse( - items: &mut [Item], + items: &mut [Item<'_, D, W>], iter_count: usize, iter_id: usize, coord: usize, @@ -576,7 +576,7 @@ mod tests { let sum: u32 = weights.iter().sum(); let part = &AtomicUsize::new(0); - let mut items: Vec> = points + let mut items: Vec> = points .into_iter() .zip(weights) .map(|(point, weight)| Item { diff --git a/src/lib.rs b/src/lib.rs index 5602df14..dab823ad 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -29,6 +29,8 @@ //! - [Fiduccia-Mattheyses][FiducciaMattheyses] //! - [Kernighan-Lin][KernighanLin] +#![warn(rust_2018_idioms)] + mod algorithms; mod geometry; pub mod imbalance; diff --git a/src/topology.rs b/src/topology.rs index 9f97784d..ab34bca0 100644 --- a/src/topology.rs +++ b/src/topology.rs @@ -27,7 +27,7 @@ use std::iter::Sum; /// 1* ┆╲ ╱ /// * 0 /// ``` -pub fn edge_cut(adjacency: CsMatView, partition: &[usize]) -> T +pub fn edge_cut(adjacency: CsMatView<'_, T>, partition: &[usize]) -> T where T: Copy + Sum + Send + Sync + PartialEq, { @@ -53,7 +53,7 @@ where .sum() } -pub fn lambda_cut(adjacency: CsMatView, partition: &[usize]) -> usize { +pub fn lambda_cut(adjacency: CsMatView<'_, T>, partition: &[usize]) -> usize { let indptr = adjacency.indptr().into_raw_storage(); let indices = adjacency.indices(); indptr @@ -92,7 +92,7 @@ pub fn lambda_cut(adjacency: CsMatView, partition: &[usize]) -> usize { /// /// If the entry `(i, j)` is non-zero, then its value is the weight of the edge between `i` /// and `j` (default to `1.0`). -pub fn adjacency_matrix(conn: CsMatView, num_common_nodes: u32) -> CsMat { +pub fn adjacency_matrix(conn: CsMatView<'_, u32>, num_common_nodes: u32) -> CsMat { // currently this matmul operation is very slow let graph = &conn * &conn.transpose_view();