-
Notifications
You must be signed in to change notification settings - Fork 129
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix Nightly warnings #1080
Fix Nightly warnings #1080
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -252,7 +252,7 @@ mod x86; | |
|
||
use core::{ | ||
marker::{PhantomData, PhantomPinned}, | ||
mem::{self, MaybeUninit}, | ||
mem::{size_of, MaybeUninit}, | ||
num::{ | ||
self, NonZeroI128, NonZeroI16, NonZeroI32, NonZeroI64, NonZeroI8, NonZeroIsize, | ||
NonZeroU128, NonZeroU16, NonZeroU32, NonZeroU64, NonZeroU8, NonZeroUsize, | ||
|
@@ -409,10 +409,10 @@ where | |
// | ||
// Safety: | ||
// | ||
// The memory pointed to by `self` is valid for `mem::size_of::<Self>()` bytes. | ||
// The memory pointed to by `self` is valid for `size_of::<Self>()` bytes. | ||
// It is also properly aligned, because `u8` has an alignment of `1`. | ||
unsafe { | ||
volatile_set((self as *mut Self).cast::<u8>(), 0, mem::size_of::<Self>()); | ||
volatile_set((self as *mut Self).cast::<u8>(), 0, size_of::<Self>()); | ||
} | ||
|
||
// Ensures self is overwritten with the `None` bit pattern. volatile_write can't be | ||
|
@@ -457,7 +457,7 @@ impl<Z> Zeroize for MaybeUninit<Z> { | |
impl<Z> Zeroize for [MaybeUninit<Z>] { | ||
fn zeroize(&mut self) { | ||
let ptr = self.as_mut_ptr().cast::<MaybeUninit<u8>>(); | ||
let size = self.len().checked_mul(mem::size_of::<Z>()).unwrap(); | ||
let size = self.len().checked_mul(size_of::<Z>()).unwrap(); | ||
assert!(size <= isize::MAX as usize); | ||
|
||
// Safety: | ||
|
@@ -595,6 +595,8 @@ impl Zeroize for String { | |
#[cfg(feature = "std")] | ||
impl Zeroize for CString { | ||
fn zeroize(&mut self) { | ||
use core::mem; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think you can continue to import There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This import would need to be gated on |
||
|
||
// mem::take uses replace internally to swap the pointer | ||
// Unfortunately this results in an allocation for a Box::new(&[0]) as CString must | ||
// contain a trailing zero byte | ||
|
@@ -767,7 +769,7 @@ fn volatile_write<T: Copy + Sized>(dst: &mut T, src: T) { | |
/// The memory pointed to by `dst` must be a single allocated object that is valid for `count` | ||
/// contiguous elements of `T`. | ||
/// `count` must not be larger than an `isize`. | ||
/// `dst` being offset by `mem::size_of::<T> * count` bytes must not wrap around the address space. | ||
/// `dst` being offset by `size_of::<T> * count` bytes must not wrap around the address space. | ||
/// Also `dst` must be properly aligned. | ||
#[inline(always)] | ||
unsafe fn volatile_set<T: Copy + Sized>(dst: *mut T, src: T, count: usize) { | ||
|
@@ -783,7 +785,7 @@ unsafe fn volatile_set<T: Copy + Sized>(dst: *mut T, src: T, count: usize) { | |
// Safety: | ||
// | ||
// This is safe, because the pointer is valid and because `dst` is well aligned for `T` and | ||
// `ptr` is an offset of `dst` by a multiple of `mem::size_of::<T>()` bytes. | ||
// `ptr` is an offset of `dst` by a multiple of `size_of::<T>()` bytes. | ||
ptr::write_volatile(ptr, src); | ||
} | ||
} | ||
|
@@ -837,10 +839,10 @@ unsafe fn volatile_set<T: Copy + Sized>(dst: *mut T, src: T, count: usize) { | |
/// ``` | ||
#[inline(always)] | ||
pub unsafe fn zeroize_flat_type<F: Sized>(data: *mut F) { | ||
let size = mem::size_of::<F>(); | ||
let size = size_of::<F>(); | ||
// Safety: | ||
// | ||
// This is safe because `mem::size_of<T>()` returns the exact size of the object in memory, and | ||
// This is safe because `size_of<T>()` returns the exact size of the object in memory, and | ||
// `data_ptr` points directly to the first byte of the data. | ||
volatile_set(data as *mut u8, 0, size); | ||
atomic_fence() | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am not sure why exactly compiler complains about
mem::size_of
. Was it added to the prelude?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, it was. Just encountered that here too: RustCrypto/traits#1589