diff --git a/nalgebra-macros/src/lib.rs b/nalgebra-macros/src/lib.rs index c00a538f..5b1dd677 100644 --- a/nalgebra-macros/src/lib.rs +++ b/nalgebra-macros/src/lib.rs @@ -5,14 +5,14 @@ extern crate proc_macro; -use syn::{Expr}; -use syn::parse::{Parse, ParseStream, Result, Error}; -use syn::punctuated::{Punctuated}; -use syn::{parse_macro_input, Token}; -use quote::{quote, TokenStreamExt, ToTokens}; use proc_macro::TokenStream; +use quote::{quote, ToTokens, TokenStreamExt}; +use syn::parse::{Error, Parse, ParseStream, Result}; +use syn::punctuated::Punctuated; +use syn::Expr; +use syn::{parse_macro_input, Token}; -use proc_macro2::{TokenStream as TokenStream2, Delimiter, TokenTree, Spacing}; +use proc_macro2::{Delimiter, Spacing, TokenStream as TokenStream2, TokenTree}; use proc_macro2::{Group, Punct}; struct Matrix { @@ -33,10 +33,9 @@ impl Matrix { /// Produces a stream of tokens representing this matrix as a column-major nested array. fn to_col_major_nested_array_tokens(&self) -> TokenStream2 { let mut result = TokenStream2::new(); - for j in 0 .. self.ncols() { + for j in 0..self.ncols() { let mut col = TokenStream2::new(); - let col_iter = (0 .. self.nrows()) - .map(move |i| &self.rows[i][j]); + let col_iter = (0..self.nrows()).map(move |i| &self.rows[i][j]); col.append_separated(col_iter, Punct::new(',', Spacing::Alone)); result.append(Group::new(Delimiter::Bracket, col)); result.append(Punct::new(',', Spacing::Alone)); @@ -48,8 +47,8 @@ impl Matrix { /// (suitable for representing e.g. a `DMatrix`). fn to_col_major_flat_array_tokens(&self) -> TokenStream2 { let mut data = TokenStream2::new(); - for j in 0 .. self.ncols() { - for i in 0 .. self.nrows() { + for j in 0..self.ncols() { + for i in 0..self.nrows() { self.rows[i][j].to_tokens(&mut data); data.append(Punct::new(',', Spacing::Alone)); } @@ -76,7 +75,8 @@ impl Parse for Matrix { "Unexpected number of entries in row {}. Expected {}, found {} entries.", row_idx, ncols, - row.len()); + row.len() + ); return Err(Error::new(row_span, error_msg)); } } else { @@ -93,7 +93,7 @@ impl Parse for Matrix { Ok(Self { rows, - ncols: ncols.unwrap_or(0) + ncols: ncols.unwrap_or(0), }) } } @@ -209,13 +209,13 @@ impl Parse for Vector { // The syntax of a vector is just the syntax of a single matrix row if input.is_empty() { Ok(Self { - elements: Vec::new() + elements: Vec::new(), }) } else { - let elements = MatrixRowSyntax::parse_separated_nonempty(input)?.into_iter().collect(); - Ok(Self { - elements - }) + let elements = MatrixRowSyntax::parse_separated_nonempty(input)? + .into_iter() + .collect(); + Ok(Self { elements }) } } } @@ -279,4 +279,4 @@ pub fn dvector(stream: TokenStream) -> TokenStream { vec!#array_tokens)) }; proc_macro::TokenStream::from(output) -} \ No newline at end of file +} diff --git a/nalgebra-macros/tests/tests.rs b/nalgebra-macros/tests/tests.rs index c9d64d91..88fbb9ae 100644 --- a/nalgebra-macros/tests/tests.rs +++ b/nalgebra-macros/tests/tests.rs @@ -1,5 +1,9 @@ +use nalgebra::{ + DMatrix, DVector, Matrix1x2, Matrix1x3, Matrix1x4, Matrix2, Matrix2x1, Matrix2x3, Matrix2x4, + Matrix3, Matrix3x1, Matrix3x2, Matrix3x4, Matrix4, Matrix4x1, Matrix4x2, Matrix4x3, SMatrix, + SVector, Vector1, Vector2, Vector3, Vector4, Vector5, Vector6, +}; use nalgebra_macros::{dmatrix, dvector, matrix, vector}; -use nalgebra::{DMatrix, DVector, SMatrix, Matrix3x2, Matrix1x2, Matrix1x3, Matrix1x4, Matrix2x1, Matrix2, Matrix2x3, Matrix2x4, Matrix3x1, Matrix3, Matrix3x4, Matrix4x1, Matrix4x2, Matrix4x3, Matrix4, Vector1, Vector2, Vector3, Vector4, Vector5, SVector, Vector6}; fn check_statically_same_type(_: &T, _: &T) {} @@ -11,6 +15,8 @@ macro_rules! assert_eq_and_type { }; } +// Skip rustfmt because it just makes the test bloated without making it more readable +#[rustfmt::skip] #[test] fn matrix_small_dims_exhaustive() { // 0x0 @@ -52,6 +58,8 @@ fn matrix_const_fn() { const _: SMatrix = matrix![1, 2, 3; 4, 5, 6]; } +// Skip rustfmt because it just makes the test bloated without making it more readable +#[rustfmt::skip] #[test] fn dmatrix_small_dims_exhaustive() { // 0x0 @@ -85,6 +93,8 @@ fn dmatrix_small_dims_exhaustive() { DMatrix::from_row_slice(4, 4, &[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16])); } +// Skip rustfmt because it just makes the test bloated without making it more readable +#[rustfmt::skip] #[test] fn vector_small_dims_exhaustive() { assert_eq_and_type!(vector![], SVector::::zeros()); @@ -105,6 +115,8 @@ fn vector_const_fn() { const _: Vector6 = vector![1, 2, 3, 4, 5, 6]; } +// Skip rustfmt because it just makes the test bloated without making it more readable +#[rustfmt::skip] #[test] fn dvector_small_dims_exhaustive() { assert_eq_and_type!(dvector![], DVector::::zeros(0)); @@ -130,4 +142,4 @@ fn dmatrix_trybuild_tests() { // Verify error message when we give a matrix with mismatched dimensions t.compile_fail("tests/trybuild/dmatrix_mismatched_dimensions.rs"); -} \ No newline at end of file +} diff --git a/src/base/vec_storage.rs b/src/base/vec_storage.rs index 15ea9237..f8d28769 100644 --- a/src/base/vec_storage.rs +++ b/src/base/vec_storage.rs @@ -13,9 +13,9 @@ use crate::base::storage::{ }; use crate::base::{Scalar, Vector}; +use crate::{DMatrix, DVector}; #[cfg(feature = "abomonation-serialize")] use abomonation::Abomonation; -use crate::{DMatrix, DVector}; /* * @@ -412,8 +412,7 @@ impl Extend for VecStorage { } } -impl DMatrix -{ +impl DMatrix { /// Creates a new heap-allocated matrix from the given [VecStorage]. pub const fn from_vec_storage(storage: VecStorage) -> Self { // This is sound because the dimensions of the matrix and the storage are guaranteed @@ -422,8 +421,7 @@ impl DMatrix } } -impl DVector -{ +impl DVector { /// Creates a new heap-allocated matrix from the given [VecStorage]. pub const fn from_vec_storage(storage: VecStorage) -> Self { // This is sound because the dimensions of the matrix and the storage are guaranteed diff --git a/tests/core/macros.rs b/tests/core/macros.rs index cdc4de03..eaa134ff 100644 --- a/tests/core/macros.rs +++ b/tests/core/macros.rs @@ -8,4 +8,4 @@ fn sanity_test() { let _ = dmatrix![1, 2, 3; 4, 5, 6]; let _ = vector![1, 2, 3, 4, 5, 6]; let _ = dvector![1, 2, 3, 4, 5, 6]; -} \ No newline at end of file +} diff --git a/tests/core/mod.rs b/tests/core/mod.rs index aa005264..c03461dc 100644 --- a/tests/core/mod.rs +++ b/tests/core/mod.rs @@ -18,4 +18,4 @@ mod matrixcompare; pub mod helper; #[cfg(feature = "macros")] -mod macros; \ No newline at end of file +mod macros; diff --git a/tests/lib.rs b/tests/lib.rs index d08f4807..20d38d7a 100644 --- a/tests/lib.rs +++ b/tests/lib.rs @@ -1,4 +1,9 @@ -#[cfg(not(all(feature = "debug", feature = "compare", feature = "rand", feature = "macros")))] +#[cfg(not(all( + feature = "debug", + feature = "compare", + feature = "rand", + feature = "macros" +)))] compile_error!( "Please enable the `debug`, `compare`, `rand` and `macros` features in order to compile and run the tests. Example: `cargo test --features debug,compare,rand,macros`"