From fe75c6032587e57e7ff127ebaa7d87e20ff6d15c Mon Sep 17 00:00:00 2001 From: Fan Jiang Date: Tue, 10 Mar 2020 18:20:52 -0400 Subject: [PATCH 1/5] Fix warnings on latest rustc --- src/base/conversion.rs | 4 ++-- src/base/default_allocator.rs | 2 +- src/base/dimension.rs | 1 - src/base/storage.rs | 3 --- tests/core/matrix.rs | 3 --- tests/linalg/inverse.rs | 2 +- 6 files changed, 4 insertions(+), 11 deletions(-) diff --git a/src/base/conversion.rs b/src/base/conversion.rs index e52a0c5d..cf68b024 100644 --- a/src/base/conversion.rs +++ b/src/base/conversion.rs @@ -119,7 +119,7 @@ macro_rules! impl_from_into_asref_1D( #[inline] fn into(self) -> [N; $SZ] { unsafe { - let mut res: [N; $SZ] = mem::uninitialized(); + let mut res: [N; $SZ] = mem::MaybeUninit::uninit().assume_init(); ptr::copy_nonoverlapping(self.data.ptr(), &mut res[0], $SZ); res @@ -186,7 +186,7 @@ macro_rules! impl_from_into_asref_2D( #[inline] fn into(self) -> [[N; $SZRows]; $SZCols] { unsafe { - let mut res: [[N; $SZRows]; $SZCols] = mem::uninitialized(); + let mut res: [[N; $SZRows]; $SZCols] = mem::MaybeUninit::uninit().assume_init(); ptr::copy_nonoverlapping(self.data.ptr(), &mut res[0][0], $SZRows * $SZCols); res diff --git a/src/base/default_allocator.rs b/src/base/default_allocator.rs index c07c8708..a15b0b7c 100644 --- a/src/base/default_allocator.rs +++ b/src/base/default_allocator.rs @@ -46,7 +46,7 @@ where #[inline] unsafe fn allocate_uninitialized(_: R, _: C) -> Self::Buffer { - mem::uninitialized() + mem::MaybeUninit::uninit().assume_init() } #[inline] diff --git a/src/base/dimension.rs b/src/base/dimension.rs index 112996d3..e7150e65 100644 --- a/src/base/dimension.rs +++ b/src/base/dimension.rs @@ -190,7 +190,6 @@ pub trait DimName: Dim { type Value: NamedDim; /// The name of this dimension, i.e., the singleton `Self`. - #[inline] fn name() -> Self; // FIXME: this is not a very idiomatic name. diff --git a/src/base/storage.rs b/src/base/storage.rs index e7439552..8e472e1e 100644 --- a/src/base/storage.rs +++ b/src/base/storage.rs @@ -94,13 +94,11 @@ pub unsafe trait Storage: Debug + Sized { } /// Indicates whether this data buffer stores its elements contiguously. - #[inline] fn is_contiguous(&self) -> bool; /// Retrieves the data buffer as a contiguous slice. /// /// The matrix components may not be stored in a contiguous way, depending on the strides. - #[inline] fn as_slice(&self) -> &[N]; /// Builds a matrix data storage that does not contain any reference. @@ -166,7 +164,6 @@ pub unsafe trait StorageMut: Storage { /// Retrieves the mutable data buffer as a contiguous slice. /// /// Matrix components may not be contiguous, depending on its strides. - #[inline] fn as_mut_slice(&mut self) -> &mut [N]; } diff --git a/tests/core/matrix.rs b/tests/core/matrix.rs index 6fad5e8c..4f61ce6e 100644 --- a/tests/core/matrix.rs +++ b/tests/core/matrix.rs @@ -7,9 +7,6 @@ use na::{ Matrix4x3, Matrix4x5, Matrix5, Matrix6, MatrixMN, RowVector3, RowVector4, RowVector5, Vector1, Vector2, Vector3, Vector4, Vector5, Vector6, }; -use typenum::{UInt, UTerm}; -use serde_json::error::Category::Data; -use typenum::bit::{B0, B1}; #[test] fn iter() { diff --git a/tests/linalg/inverse.rs b/tests/linalg/inverse.rs index 61f43324..f0be4dd7 100644 --- a/tests/linalg/inverse.rs +++ b/tests/linalg/inverse.rs @@ -130,7 +130,7 @@ fn matrix5_try_inverse_scaled_identity() { 0.0, 1.0e+20, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0e+20, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0e+20, 0.0, - 0.0, 0.0, 0.0, 0.0, 1.0e+20);; + 0.0, 0.0, 0.0, 0.0, 1.0e+20); let a_inv = a.try_inverse().expect("Matrix should be invertible"); assert_relative_eq!(a_inv, expected_inverse); From 74bfd9cad6d37d2c8d278ebdfd56fd88eb8c6916 Mon Sep 17 00:00:00 2001 From: Fan Jiang Date: Tue, 31 Mar 2020 16:50:26 -0400 Subject: [PATCH 2/5] Change to the recommended style of using MaybeUninit --- src/base/conversion.rs | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/src/base/conversion.rs b/src/base/conversion.rs index cf68b024..15c0bf9d 100644 --- a/src/base/conversion.rs +++ b/src/base/conversion.rs @@ -118,12 +118,13 @@ macro_rules! impl_from_into_asref_1D( S: ContiguousStorage { #[inline] fn into(self) -> [N; $SZ] { - unsafe { - let mut res: [N; $SZ] = mem::MaybeUninit::uninit().assume_init(); - ptr::copy_nonoverlapping(self.data.ptr(), &mut res[0], $SZ); + let mut res = mem::MaybeUninit::<[N; $SZ]>::uninit(); - res - } + unsafe { ptr::copy_nonoverlapping(self.data.ptr(), res.as_mut_ptr() as *mut N, $SZ); } + + let res: [N; $SZ] = unsafe { res.assume_init() }; + + res } } @@ -185,12 +186,13 @@ macro_rules! impl_from_into_asref_2D( where S: ContiguousStorage { #[inline] fn into(self) -> [[N; $SZRows]; $SZCols] { - unsafe { - let mut res: [[N; $SZRows]; $SZCols] = mem::MaybeUninit::uninit().assume_init(); - ptr::copy_nonoverlapping(self.data.ptr(), &mut res[0][0], $SZRows * $SZCols); + let mut res = mem::MaybeUninit::<[[N; $SZRows]; $SZCols]>::uninit(); - res - } + unsafe { ptr::copy_nonoverlapping(self.data.ptr(), res.as_mut_ptr() as *mut N, $SZRows * $SZCols); } + + let res: [[N; $SZRows]; $SZCols] = unsafe { res.assume_init() }; + + res } } From 526dac1914ddc221034a38b52042258c7ec0d6a7 Mon Sep 17 00:00:00 2001 From: Fan Jiang Date: Tue, 31 Mar 2020 17:03:07 -0400 Subject: [PATCH 3/5] Be more specific on what is happening here --- src/base/default_allocator.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/base/default_allocator.rs b/src/base/default_allocator.rs index a15b0b7c..2435c4eb 100644 --- a/src/base/default_allocator.rs +++ b/src/base/default_allocator.rs @@ -46,7 +46,7 @@ where #[inline] unsafe fn allocate_uninitialized(_: R, _: C) -> Self::Buffer { - mem::MaybeUninit::uninit().assume_init() + mem::MaybeUninit::::uninit().assume_init() } #[inline] From 451c61e293784b00b3cb6202187c0988a9c67902 Mon Sep 17 00:00:00 2001 From: Fan Jiang Date: Tue, 31 Mar 2020 17:04:10 -0400 Subject: [PATCH 4/5] Add TODO notice and reference to issue --- src/base/default_allocator.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/base/default_allocator.rs b/src/base/default_allocator.rs index 2435c4eb..cbfb5f61 100644 --- a/src/base/default_allocator.rs +++ b/src/base/default_allocator.rs @@ -46,6 +46,7 @@ where #[inline] unsafe fn allocate_uninitialized(_: R, _: C) -> Self::Buffer { + // TODO: Undefined behavior, see #556 mem::MaybeUninit::::uninit().assume_init() } From 0e69df29997165d4629255a40fa03ba0bc646823 Mon Sep 17 00:00:00 2001 From: Fan Jiang Date: Wed, 1 Apr 2020 01:14:32 -0400 Subject: [PATCH 5/5] Update format --- src/base/conversion.rs | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/src/base/conversion.rs b/src/base/conversion.rs index 15c0bf9d..30b68bb7 100644 --- a/src/base/conversion.rs +++ b/src/base/conversion.rs @@ -120,11 +120,9 @@ macro_rules! impl_from_into_asref_1D( fn into(self) -> [N; $SZ] { let mut res = mem::MaybeUninit::<[N; $SZ]>::uninit(); - unsafe { ptr::copy_nonoverlapping(self.data.ptr(), res.as_mut_ptr() as *mut N, $SZ); } + unsafe { ptr::copy_nonoverlapping(self.data.ptr(), res.as_mut_ptr() as *mut N, $SZ) }; - let res: [N; $SZ] = unsafe { res.assume_init() }; - - res + unsafe { res.assume_init() } } } @@ -188,11 +186,9 @@ macro_rules! impl_from_into_asref_2D( fn into(self) -> [[N; $SZRows]; $SZCols] { let mut res = mem::MaybeUninit::<[[N; $SZRows]; $SZCols]>::uninit(); - unsafe { ptr::copy_nonoverlapping(self.data.ptr(), res.as_mut_ptr() as *mut N, $SZRows * $SZCols); } + unsafe { ptr::copy_nonoverlapping(self.data.ptr(), res.as_mut_ptr() as *mut N, $SZRows * $SZCols) }; - let res: [[N; $SZRows]; $SZCols] = unsafe { res.assume_init() }; - - res + unsafe { res.assume_init() } } }