From 42a2c745714f3d481a1ed99119a94ac730571e92 Mon Sep 17 00:00:00 2001 From: Malte Tammena Date: Sun, 6 Jun 2021 15:28:37 +0200 Subject: [PATCH] Finish initial must_use annotations --- nalgebra-lapack/src/cholesky.rs | 2 ++ nalgebra-lapack/src/eigen.rs | 1 + nalgebra-lapack/src/hessenberg.rs | 2 ++ nalgebra-lapack/src/lu.rs | 4 ++++ nalgebra-lapack/src/qr.rs | 2 ++ nalgebra-lapack/src/schur.rs | 2 ++ nalgebra-lapack/src/svd.rs | 2 ++ nalgebra-lapack/src/symmetric_eigen.rs | 2 ++ nalgebra-sparse/src/coo.rs | 6 +++++ nalgebra-sparse/src/cs.rs | 13 +++++++++++ nalgebra-sparse/src/csc.rs | 22 +++++++++++++++++++ nalgebra-sparse/src/csr.rs | 22 +++++++++++++++++++ nalgebra-sparse/src/factorization/cholesky.rs | 3 +++ nalgebra-sparse/src/lib.rs | 1 + nalgebra-sparse/src/ops/mod.rs | 2 ++ nalgebra-sparse/src/ops/serial/mod.rs | 2 ++ nalgebra-sparse/src/pattern.rs | 9 ++++++++ 17 files changed, 97 insertions(+) diff --git a/nalgebra-lapack/src/cholesky.rs b/nalgebra-lapack/src/cholesky.rs index fbbf6fd4..b271ca51 100644 --- a/nalgebra-lapack/src/cholesky.rs +++ b/nalgebra-lapack/src/cholesky.rs @@ -80,6 +80,7 @@ where } /// Retrieves the lower-triangular factor of the cholesky decomposition. + #[must_use = "This function does not mutate self. You should use the return value."] pub fn l(&self) -> OMatrix { let mut res = self.l.clone(); res.fill_upper_triangle(Zero::zero(), 1); @@ -91,6 +92,7 @@ where /// /// This is an allocation-less version of `self.l()`. The values of the strict upper-triangular /// part are garbage and should be ignored by further computations. + #[must_use = "This function does not mutate self. You should use the return value."] pub fn l_dirty(&self) -> &OMatrix { &self.l } diff --git a/nalgebra-lapack/src/eigen.rs b/nalgebra-lapack/src/eigen.rs index cbe1555a..993f8987 100644 --- a/nalgebra-lapack/src/eigen.rs +++ b/nalgebra-lapack/src/eigen.rs @@ -302,6 +302,7 @@ where /// The determinant of the decomposed matrix. #[inline] + #[must_use = "This function does not mutate self. You should use the return value."] pub fn determinant(&self) -> T { let mut det = T::one(); for e in self.eigenvalues.iter() { diff --git a/nalgebra-lapack/src/hessenberg.rs b/nalgebra-lapack/src/hessenberg.rs index b025a8bf..47018004 100644 --- a/nalgebra-lapack/src/hessenberg.rs +++ b/nalgebra-lapack/src/hessenberg.rs @@ -89,6 +89,7 @@ where /// Computes the hessenberg matrix of this decomposition. #[inline] + #[must_use = "This function does not mutate self. You should use the return value."] pub fn h(&self) -> OMatrix { let mut h = self.h.clone_owned(); h.fill_lower_triangle(T::zero(), 2); @@ -109,6 +110,7 @@ where /// Computes the unitary matrix `Q` of this decomposition. #[inline] + #[must_use = "This function does not mutate self. You should use the return value."] pub fn q(&self) -> OMatrix { let n = self.h.nrows() as i32; let mut q = self.h.clone_owned(); diff --git a/nalgebra-lapack/src/lu.rs b/nalgebra-lapack/src/lu.rs index 5ca5f143..a163629d 100644 --- a/nalgebra-lapack/src/lu.rs +++ b/nalgebra-lapack/src/lu.rs @@ -85,6 +85,7 @@ where /// Gets the lower-triangular matrix part of the decomposition. #[inline] + #[must_use = "This function does not mutate self. You should use the return value."] pub fn l(&self) -> OMatrix> { let (nrows, ncols) = self.lu.data.shape(); let mut res = self.lu.columns_generic(0, nrows.min(ncols)).into_owned(); @@ -97,6 +98,7 @@ where /// Gets the upper-triangular matrix part of the decomposition. #[inline] + #[must_use = "This function does not mutate self. You should use the return value."] pub fn u(&self) -> OMatrix, C> { let (nrows, ncols) = self.lu.data.shape(); let mut res = self.lu.rows_generic(0, nrows.min(ncols)).into_owned(); @@ -111,6 +113,7 @@ where /// Computing the permutation matrix explicitly is costly and usually not necessary. /// To permute rows of a matrix or vector, use the method `self.permute(...)` instead. #[inline] + #[must_use = "This function does not mutate self. You should use the return value."] pub fn p(&self) -> OMatrix { let (dim, _) = self.lu.data.shape(); let mut id = Matrix::identity_generic(dim, dim); @@ -124,6 +127,7 @@ where /// Gets the LAPACK permutation indices. #[inline] + #[must_use = "This function does not mutate self. You should use the return value."] pub fn permutation_indices(&self) -> &OVector> { &self.p } diff --git a/nalgebra-lapack/src/qr.rs b/nalgebra-lapack/src/qr.rs index b58c3f35..8c32b299 100644 --- a/nalgebra-lapack/src/qr.rs +++ b/nalgebra-lapack/src/qr.rs @@ -92,6 +92,7 @@ where /// Retrieves the upper trapezoidal submatrix `R` of this decomposition. #[inline] + #[must_use = "This function does not mutate self. You should use the return value."] pub fn r(&self) -> OMatrix, C> { let (nrows, ncols) = self.qr.data.shape(); self.qr.rows_generic(0, nrows.min(ncols)).upper_triangle() @@ -117,6 +118,7 @@ where /// Computes the orthogonal matrix `Q` of this decomposition. #[inline] + #[must_use = "This function does not mutate self. You should use the return value."] pub fn q(&self) -> OMatrix> { let (nrows, ncols) = self.qr.data.shape(); let min_nrows_ncols = nrows.min(ncols); diff --git a/nalgebra-lapack/src/schur.rs b/nalgebra-lapack/src/schur.rs index a850f01d..602e0ec1 100644 --- a/nalgebra-lapack/src/schur.rs +++ b/nalgebra-lapack/src/schur.rs @@ -138,6 +138,7 @@ where /// Computes the real eigenvalues of the decomposed matrix. /// /// Return `None` if some eigenvalues are complex. + #[must_use = "This function does not mutate self. You should use the return value."] pub fn eigenvalues(&self) -> Option> { if self.im.iter().all(|e| e.is_zero()) { Some(self.re.clone()) @@ -147,6 +148,7 @@ where } /// Computes the complex eigenvalues of the decomposed matrix. + #[must_use = "This function does not mutate self. You should use the return value."] pub fn complex_eigenvalues(&self) -> OVector, D> where DefaultAllocator: Allocator, D>, diff --git a/nalgebra-lapack/src/svd.rs b/nalgebra-lapack/src/svd.rs index f6b907b6..7256e984 100644 --- a/nalgebra-lapack/src/svd.rs +++ b/nalgebra-lapack/src/svd.rs @@ -175,6 +175,7 @@ macro_rules! svd_impl( /// /// All singular value below epsilon will be set to zero instead of being inverted. #[inline] + #[must_use = "This function does not mutate self. You should use the return value."] pub fn pseudo_inverse(&self, epsilon: $t) -> OMatrix<$t, C, R> { let nrows = self.u.data.shape().0; let ncols = self.vt.data.shape().1; @@ -207,6 +208,7 @@ macro_rules! svd_impl( /// This is the number of singular values that are not too small (i.e. greater than /// the given `epsilon`). #[inline] + #[must_use = "This function does not mutate self. You should use the return value."] pub fn rank(&self, epsilon: $t) -> usize { let mut i = 0; diff --git a/nalgebra-lapack/src/symmetric_eigen.rs b/nalgebra-lapack/src/symmetric_eigen.rs index 0cd6bfc1..d2150598 100644 --- a/nalgebra-lapack/src/symmetric_eigen.rs +++ b/nalgebra-lapack/src/symmetric_eigen.rs @@ -138,6 +138,7 @@ where /// The determinant of the decomposed matrix. #[inline] + #[must_use = "This function does not mutate self. You should use the return value."] pub fn determinant(&self) -> T { let mut det = T::one(); for e in self.eigenvalues.iter() { @@ -150,6 +151,7 @@ where /// Rebuild the original matrix. /// /// This is useful if some of the eigenvalues have been manually modified. + #[must_use = "This function does not mutate self. You should use the return value."] pub fn recompose(&self) -> OMatrix { let mut u_t = self.eigenvectors.clone(); for i in 0..self.eigenvalues.len() { diff --git a/nalgebra-sparse/src/coo.rs b/nalgebra-sparse/src/coo.rs index 364083a9..820e4e38 100644 --- a/nalgebra-sparse/src/coo.rs +++ b/nalgebra-sparse/src/coo.rs @@ -173,12 +173,14 @@ impl CooMatrix { /// The number of rows in the matrix. #[inline] + #[must_use = "This function does not mutate self. You should use the return value."] pub fn nrows(&self) -> usize { self.nrows } /// The number of columns in the matrix. #[inline] + #[must_use = "This function does not mutate self. You should use the return value."] pub fn ncols(&self) -> usize { self.ncols } @@ -189,21 +191,25 @@ impl CooMatrix { /// entries, then it may have a different number of non-zeros as reported by `nnz()` compared /// to its CSR representation. #[inline] + #[must_use = "This function does not mutate self. You should use the return value."] pub fn nnz(&self) -> usize { self.values.len() } /// The row indices of the explicitly stored entries. + #[must_use = "This function does not mutate self. You should use the return value."] pub fn row_indices(&self) -> &[usize] { &self.row_indices } /// The column indices of the explicitly stored entries. + #[must_use = "This function does not mutate self. You should use the return value."] pub fn col_indices(&self) -> &[usize] { &self.col_indices } /// The values of the explicitly stored entries. + #[must_use = "This function does not mutate self. You should use the return value."] pub fn values(&self) -> &[T] { &self.values } diff --git a/nalgebra-sparse/src/cs.rs b/nalgebra-sparse/src/cs.rs index d6f9b229..10492801 100644 --- a/nalgebra-sparse/src/cs.rs +++ b/nalgebra-sparse/src/cs.rs @@ -32,11 +32,13 @@ impl CsMatrix { } #[inline] + #[must_use = "This function does not mutate self. You should use the return value."] pub fn pattern(&self) -> &SparsityPattern { &self.sparsity_pattern } #[inline] + #[must_use = "This function does not mutate self. You should use the return value."] pub fn values(&self) -> &[T] { &self.values } @@ -48,6 +50,7 @@ impl CsMatrix { /// Returns the raw data represented as a tuple `(major_offsets, minor_indices, values)`. #[inline] + #[must_use = "This function does not mutate self. You should use the return value."] pub fn cs_data(&self) -> (&[usize], &[usize], &[T]) { let pattern = self.pattern(); ( @@ -88,6 +91,7 @@ impl CsMatrix { /// Internal method for simplifying access to a lane's data #[inline] + #[must_use = "This function does not mutate self. You should use the return value."] pub fn get_index_range(&self, row_index: usize) -> Option> { let row_begin = *self.sparsity_pattern.major_offsets().get(row_index)?; let row_end = *self.sparsity_pattern.major_offsets().get(row_index + 1)?; @@ -111,6 +115,7 @@ impl CsMatrix { /// Returns an entry for the given major/minor indices, or `None` if the indices are out /// of bounds. + #[must_use = "This function does not mutate self. You should use the return value."] pub fn get_entry(&self, major_index: usize, minor_index: usize) -> Option> { let row_range = self.get_index_range(major_index)?; let (_, minor_indices, values) = self.cs_data(); @@ -139,6 +144,7 @@ impl CsMatrix { get_mut_entry_from_slices(minor_dim, minor_indices, values, minor_index) } + #[must_use = "This function does not mutate self. You should use the return value."] pub fn get_lane(&self, index: usize) -> Option> { let range = self.get_index_range(index)?; let (_, minor_indices, values) = self.cs_data(); @@ -172,6 +178,7 @@ impl CsMatrix { } #[inline] + #[must_use = "This function does not mutate self. You should use the return value."] pub fn filter

(&self, predicate: P) -> Self where T: Clone, @@ -207,6 +214,7 @@ impl CsMatrix { } /// Returns the diagonal of the matrix as a sparse matrix. + #[must_use = "This function does not mutate self. You should use the return value."] pub fn diagonal_as_matrix(&self) -> Self where T: Clone, @@ -372,26 +380,31 @@ macro_rules! impl_cs_lane_common_methods { ($name:ty) => { impl<'a, T> $name { #[inline] + #[must_use = "This function does not mutate self. You should use the return value."] pub fn minor_dim(&self) -> usize { self.minor_dim } #[inline] + #[must_use = "This function does not mutate self. You should use the return value."] pub fn nnz(&self) -> usize { self.minor_indices.len() } #[inline] + #[must_use = "This function does not mutate self. You should use the return value."] pub fn minor_indices(&self) -> &[usize] { self.minor_indices } #[inline] + #[must_use = "This function does not mutate self. You should use the return value."] pub fn values(&self) -> &[T] { self.values } #[inline] + #[must_use = "This function does not mutate self. You should use the return value."] pub fn get_entry(&self, global_col_index: usize) -> Option> { get_entry_from_slices( self.minor_dim, diff --git a/nalgebra-sparse/src/csc.rs b/nalgebra-sparse/src/csc.rs index 6a88c1d5..e5fb9465 100644 --- a/nalgebra-sparse/src/csc.rs +++ b/nalgebra-sparse/src/csc.rs @@ -192,12 +192,14 @@ impl CscMatrix { /// The number of rows in the matrix. #[inline] + #[must_use = "This function does not mutate self. You should use the return value."] pub fn nrows(&self) -> usize { self.cs.pattern().minor_dim() } /// The number of columns in the matrix. #[inline] + #[must_use = "This function does not mutate self. You should use the return value."] pub fn ncols(&self) -> usize { self.cs.pattern().major_dim() } @@ -208,24 +210,28 @@ impl CscMatrix { /// number of algebraically zero entries in the matrix. Explicitly stored entries can still /// be zero. Corresponds to the number of entries in the sparsity pattern. #[inline] + #[must_use = "This function does not mutate self. You should use the return value."] pub fn nnz(&self) -> usize { self.pattern().nnz() } /// The column offsets defining part of the CSC format. #[inline] + #[must_use = "This function does not mutate self. You should use the return value."] pub fn col_offsets(&self) -> &[usize] { self.pattern().major_offsets() } /// The row indices defining part of the CSC format. #[inline] + #[must_use = "This function does not mutate self. You should use the return value."] pub fn row_indices(&self) -> &[usize] { self.pattern().minor_indices() } /// The non-zero values defining part of the CSC format. #[inline] + #[must_use = "This function does not mutate self. You should use the return value."] pub fn values(&self) -> &[T] { self.cs.values() } @@ -298,6 +304,7 @@ impl CscMatrix { /// ------ /// Panics if column index is out of bounds. #[inline] + #[must_use = "This function does not mutate self. You should use the return value."] pub fn col(&self, index: usize) -> CscCol { self.get_col(index).expect("Row index must be in bounds") } @@ -315,6 +322,7 @@ impl CscMatrix { /// Return the column at the given column index, or `None` if out of bounds. #[inline] + #[must_use = "This function does not mutate self. You should use the return value."] pub fn get_col(&self, index: usize) -> Option> { self.cs.get_lane(index).map(|lane| CscCol { lane }) } @@ -381,6 +389,7 @@ impl CscMatrix { } /// Returns a reference to the underlying sparsity pattern. + #[must_use = "This function does not mutate self. You should use the return value."] pub fn pattern(&self) -> &SparsityPattern { self.cs.pattern() } @@ -397,6 +406,7 @@ impl CscMatrix { /// /// Each call to this function incurs the cost of a binary search among the explicitly /// stored row entries for the given column. + #[must_use = "This function does not mutate self. You should use the return value."] pub fn get_entry(&self, row_index: usize, col_index: usize) -> Option> { self.cs.get_entry(col_index, row_index) } @@ -422,6 +432,7 @@ impl CscMatrix { /// Panics /// ------ /// Panics if `row_index` or `col_index` is out of bounds. + #[must_use = "This function does not mutate self. You should use the return value."] pub fn index_entry(&self, row_index: usize, col_index: usize) -> SparseEntry { self.get_entry(row_index, col_index) .expect("Out of bounds matrix indices encountered") @@ -441,6 +452,7 @@ impl CscMatrix { } /// Returns a triplet of slices `(col_offsets, row_indices, values)` that make up the CSC data. + #[must_use = "This function does not mutate self. You should use the return value."] pub fn csc_data(&self) -> (&[usize], &[usize], &[T]) { self.cs.cs_data() } @@ -453,6 +465,7 @@ impl CscMatrix { /// Creates a sparse matrix that contains only the explicit entries decided by the /// given predicate. + #[must_use = "This function does not mutate self. You should use the return value."] pub fn filter

(&self, predicate: P) -> Self where T: Clone, @@ -470,6 +483,7 @@ impl CscMatrix { /// Returns a new matrix representing the upper triangular part of this matrix. /// /// The result includes the diagonal of the matrix. + #[must_use = "This function does not mutate self. You should use the return value."] pub fn upper_triangle(&self) -> Self where T: Clone, @@ -480,6 +494,7 @@ impl CscMatrix { /// Returns a new matrix representing the lower triangular part of this matrix. /// /// The result includes the diagonal of the matrix. + #[must_use = "This function does not mutate self. You should use the return value."] pub fn lower_triangle(&self) -> Self where T: Clone, @@ -488,6 +503,7 @@ impl CscMatrix { } /// Returns the diagonal of the matrix as a sparse matrix. + #[must_use = "This function does not mutate self. You should use the return value."] pub fn diagonal_as_csc(&self) -> Self where T: Clone, @@ -498,6 +514,7 @@ impl CscMatrix { } /// Compute the transpose of the matrix. + #[must_use = "This function does not mutate self. You should use the return value."] pub fn transpose(&self) -> CscMatrix where T: Scalar, @@ -617,24 +634,28 @@ macro_rules! impl_csc_col_common_methods { impl<'a, T> $name { /// The number of global rows in the column. #[inline] + #[must_use = "This function does not mutate self. You should use the return value."] pub fn nrows(&self) -> usize { self.lane.minor_dim() } /// The number of non-zeros in this column. #[inline] + #[must_use = "This function does not mutate self. You should use the return value."] pub fn nnz(&self) -> usize { self.lane.nnz() } /// The row indices corresponding to explicitly stored entries in this column. #[inline] + #[must_use = "This function does not mutate self. You should use the return value."] pub fn row_indices(&self) -> &[usize] { self.lane.minor_indices() } /// The values corresponding to explicitly stored entries in this column. #[inline] + #[must_use = "This function does not mutate self. You should use the return value."] pub fn values(&self) -> &[T] { self.lane.values() } @@ -643,6 +664,7 @@ macro_rules! impl_csc_col_common_methods { /// /// Each call to this function incurs the cost of a binary search among the explicitly /// stored row entries. + #[must_use = "This function does not mutate self. You should use the return value."] pub fn get_entry(&self, global_row_index: usize) -> Option> { self.lane.get_entry(global_row_index) } diff --git a/nalgebra-sparse/src/csr.rs b/nalgebra-sparse/src/csr.rs index ded189eb..f5d64627 100644 --- a/nalgebra-sparse/src/csr.rs +++ b/nalgebra-sparse/src/csr.rs @@ -192,12 +192,14 @@ impl CsrMatrix { /// The number of rows in the matrix. #[inline] + #[must_use = "This function does not mutate self. You should use the return value."] pub fn nrows(&self) -> usize { self.cs.pattern().major_dim() } /// The number of columns in the matrix. #[inline] + #[must_use = "This function does not mutate self. You should use the return value."] pub fn ncols(&self) -> usize { self.cs.pattern().minor_dim() } @@ -208,12 +210,14 @@ impl CsrMatrix { /// number of algebraically zero entries in the matrix. Explicitly stored entries can still /// be zero. Corresponds to the number of entries in the sparsity pattern. #[inline] + #[must_use = "This function does not mutate self. You should use the return value."] pub fn nnz(&self) -> usize { self.cs.pattern().nnz() } /// The row offsets defining part of the CSR format. #[inline] + #[must_use = "This function does not mutate self. You should use the return value."] pub fn row_offsets(&self) -> &[usize] { let (offsets, _, _) = self.cs.cs_data(); offsets @@ -221,6 +225,7 @@ impl CsrMatrix { /// The column indices defining part of the CSR format. #[inline] + #[must_use = "This function does not mutate self. You should use the return value."] pub fn col_indices(&self) -> &[usize] { let (_, indices, _) = self.cs.cs_data(); indices @@ -228,6 +233,7 @@ impl CsrMatrix { /// The non-zero values defining part of the CSR format. #[inline] + #[must_use = "This function does not mutate self. You should use the return value."] pub fn values(&self) -> &[T] { self.cs.values() } @@ -300,6 +306,7 @@ impl CsrMatrix { /// ------ /// Panics if row index is out of bounds. #[inline] + #[must_use = "This function does not mutate self. You should use the return value."] pub fn row(&self, index: usize) -> CsrRow { self.get_row(index).expect("Row index must be in bounds") } @@ -317,6 +324,7 @@ impl CsrMatrix { /// Return the row at the given row index, or `None` if out of bounds. #[inline] + #[must_use = "This function does not mutate self. You should use the return value."] pub fn get_row(&self, index: usize) -> Option> { self.cs.get_lane(index).map(|lane| CsrRow { lane }) } @@ -383,6 +391,7 @@ impl CsrMatrix { } /// Returns a reference to the underlying sparsity pattern. + #[must_use = "This function does not mutate self. You should use the return value."] pub fn pattern(&self) -> &SparsityPattern { self.cs.pattern() } @@ -399,6 +408,7 @@ impl CsrMatrix { /// /// Each call to this function incurs the cost of a binary search among the explicitly /// stored column entries for the given row. + #[must_use = "This function does not mutate self. You should use the return value."] pub fn get_entry(&self, row_index: usize, col_index: usize) -> Option> { self.cs.get_entry(row_index, col_index) } @@ -424,6 +434,7 @@ impl CsrMatrix { /// Panics /// ------ /// Panics if `row_index` or `col_index` is out of bounds. + #[must_use = "This function does not mutate self. You should use the return value."] pub fn index_entry(&self, row_index: usize, col_index: usize) -> SparseEntry { self.get_entry(row_index, col_index) .expect("Out of bounds matrix indices encountered") @@ -443,6 +454,7 @@ impl CsrMatrix { } /// Returns a triplet of slices `(row_offsets, col_indices, values)` that make up the CSR data. + #[must_use = "This function does not mutate self. You should use the return value."] pub fn csr_data(&self) -> (&[usize], &[usize], &[T]) { self.cs.cs_data() } @@ -455,6 +467,7 @@ impl CsrMatrix { /// Creates a sparse matrix that contains only the explicit entries decided by the /// given predicate. + #[must_use = "This function does not mutate self. You should use the return value."] pub fn filter

(&self, predicate: P) -> Self where T: Clone, @@ -470,6 +483,7 @@ impl CsrMatrix { /// Returns a new matrix representing the upper triangular part of this matrix. /// /// The result includes the diagonal of the matrix. + #[must_use = "This function does not mutate self. You should use the return value."] pub fn upper_triangle(&self) -> Self where T: Clone, @@ -480,6 +494,7 @@ impl CsrMatrix { /// Returns a new matrix representing the lower triangular part of this matrix. /// /// The result includes the diagonal of the matrix. + #[must_use = "This function does not mutate self. You should use the return value."] pub fn lower_triangle(&self) -> Self where T: Clone, @@ -488,6 +503,7 @@ impl CsrMatrix { } /// Returns the diagonal of the matrix as a sparse matrix. + #[must_use = "This function does not mutate self. You should use the return value."] pub fn diagonal_as_csr(&self) -> Self where T: Clone, @@ -498,6 +514,7 @@ impl CsrMatrix { } /// Compute the transpose of the matrix. + #[must_use = "This function does not mutate self. You should use the return value."] pub fn transpose(&self) -> CsrMatrix where T: Scalar, @@ -617,24 +634,28 @@ macro_rules! impl_csr_row_common_methods { impl<'a, T> $name { /// The number of global columns in the row. #[inline] + #[must_use = "This function does not mutate self. You should use the return value."] pub fn ncols(&self) -> usize { self.lane.minor_dim() } /// The number of non-zeros in this row. #[inline] + #[must_use = "This function does not mutate self. You should use the return value."] pub fn nnz(&self) -> usize { self.lane.nnz() } /// The column indices corresponding to explicitly stored entries in this row. #[inline] + #[must_use = "This function does not mutate self. You should use the return value."] pub fn col_indices(&self) -> &[usize] { self.lane.minor_indices() } /// The values corresponding to explicitly stored entries in this row. #[inline] + #[must_use = "This function does not mutate self. You should use the return value."] pub fn values(&self) -> &[T] { self.lane.values() } @@ -644,6 +665,7 @@ macro_rules! impl_csr_row_common_methods { /// Each call to this function incurs the cost of a binary search among the explicitly /// stored column entries. #[inline] + #[must_use = "This function does not mutate self. You should use the return value."] pub fn get_entry(&self, global_col_index: usize) -> Option> { self.lane.get_entry(global_col_index) } diff --git a/nalgebra-sparse/src/factorization/cholesky.rs b/nalgebra-sparse/src/factorization/cholesky.rs index a18761c9..662d82ae 100644 --- a/nalgebra-sparse/src/factorization/cholesky.rs +++ b/nalgebra-sparse/src/factorization/cholesky.rs @@ -42,6 +42,7 @@ impl CscSymbolicCholesky { } /// The pattern of the Cholesky factor `L`. + #[must_use = "This function does not mutate self. You should use the return value."] pub fn l_pattern(&self) -> &SparsityPattern { &self.l_pattern } @@ -171,6 +172,7 @@ impl CscCholesky { } /// Returns a reference to the Cholesky factor `L`. + #[must_use = "This function does not mutate self. You should use the return value."] pub fn l(&self) -> &CscMatrix { &self.l_factor } @@ -260,6 +262,7 @@ impl CscCholesky { /// # Panics /// /// Panics if `B` is not square. + #[must_use = "Did you mean to use solve_mut()?"] pub fn solve<'a>(&'a self, b: impl Into>) -> DMatrix { let b = b.into(); let mut output = b.clone_owned(); diff --git a/nalgebra-sparse/src/lib.rs b/nalgebra-sparse/src/lib.rs index 4b96717c..a56d0f46 100644 --- a/nalgebra-sparse/src/lib.rs +++ b/nalgebra-sparse/src/lib.rs @@ -170,6 +170,7 @@ pub struct SparseFormatError { impl SparseFormatError { /// The type of error. + #[must_use = "This function does not mutate self. You should use the return value."] pub fn kind(&self) -> &SparseFormatErrorKind { &self.kind } diff --git a/nalgebra-sparse/src/ops/mod.rs b/nalgebra-sparse/src/ops/mod.rs index a6a21fbc..1e65ea36 100644 --- a/nalgebra-sparse/src/ops/mod.rs +++ b/nalgebra-sparse/src/ops/mod.rs @@ -140,11 +140,13 @@ pub enum Op { impl Op { /// Returns a reference to the inner value that the operation applies to. + #[must_use = "This function does not mutate self. You should use the return value."] pub fn inner_ref(&self) -> &T { self.as_ref().into_inner() } /// Returns an `Op` applied to a reference of the inner value. + #[must_use = "This function does not mutate self. You should use the return value."] pub fn as_ref(&self) -> Op<&T> { match self { Op::NoOp(obj) => Op::NoOp(&obj), diff --git a/nalgebra-sparse/src/ops/serial/mod.rs b/nalgebra-sparse/src/ops/serial/mod.rs index 82285e86..4a89daa1 100644 --- a/nalgebra-sparse/src/ops/serial/mod.rs +++ b/nalgebra-sparse/src/ops/serial/mod.rs @@ -96,11 +96,13 @@ impl OperationError { } /// The operation error kind. + #[must_use = "This function does not mutate self. You should use the return value."] pub fn kind(&self) -> &OperationErrorKind { &self.error_kind } /// The underlying error message. + #[must_use = "This function does not mutate self. You should use the return value."] pub fn message(&self) -> &str { self.message.as_str() } diff --git a/nalgebra-sparse/src/pattern.rs b/nalgebra-sparse/src/pattern.rs index 08552d6a..59eedc4c 100644 --- a/nalgebra-sparse/src/pattern.rs +++ b/nalgebra-sparse/src/pattern.rs @@ -60,18 +60,21 @@ impl SparsityPattern { /// The offsets for the major dimension. #[inline] + #[must_use = "This function does not mutate self. You should use the return value."] pub fn major_offsets(&self) -> &[usize] { &self.major_offsets } /// The indices for the minor dimension. #[inline] + #[must_use = "This function does not mutate self. You should use the return value."] pub fn minor_indices(&self) -> &[usize] { &self.minor_indices } /// The number of major lanes in the pattern. #[inline] + #[must_use = "This function does not mutate self. You should use the return value."] pub fn major_dim(&self) -> usize { assert!(self.major_offsets.len() > 0); self.major_offsets.len() - 1 @@ -79,12 +82,14 @@ impl SparsityPattern { /// The number of minor lanes in the pattern. #[inline] + #[must_use = "This function does not mutate self. You should use the return value."] pub fn minor_dim(&self) -> usize { self.minor_dim } /// The number of "non-zeros", i.e. explicitly stored entries in the pattern. #[inline] + #[must_use = "This function does not mutate self. You should use the return value."] pub fn nnz(&self) -> usize { self.minor_indices.len() } @@ -96,12 +101,14 @@ impl SparsityPattern { /// /// Panics if `major_index` is out of bounds. #[inline] + #[must_use = "This function does not mutate self. You should use the return value."] pub fn lane(&self, major_index: usize) -> &[usize] { self.get_lane(major_index).unwrap() } /// Get the lane at the given index, or `None` if out of bounds. #[inline] + #[must_use = "This function does not mutate self. You should use the return value."] pub fn get_lane(&self, major_index: usize) -> Option<&[usize]> { let offset_begin = *self.major_offsets().get(major_index)?; let offset_end = *self.major_offsets().get(major_index + 1)?; @@ -197,6 +204,7 @@ impl SparsityPattern { /// assert_eq!(entries, vec![(0, 0), (0, 2), (1, 1), (2, 0)]); /// ``` /// + #[must_use = "This function does not mutate self. You should use the return value."] pub fn entries(&self) -> SparsityPatternIter { SparsityPatternIter::from_pattern(self) } @@ -228,6 +236,7 @@ impl SparsityPattern { /// /// This is analogous to matrix transposition, i.e. an entry `(i, j)` becomes `(j, i)` in the /// new pattern. + #[must_use = "This function does not mutate self. You should use the return value."] pub fn transpose(&self) -> Self { // By using unit () values, we can use the same routines as for CSR/CSC matrices let values = vec![(); self.nnz()];