strict provenance conformance
This commit is contained in:
parent
41bb03966e
commit
63c28955aa
|
@ -117,6 +117,8 @@
|
|||
//! [`unsize_stable`]: Vec::unsize_stable
|
||||
|
||||
#![cfg_attr(feature = "unstable", feature(coerce_unsized))]
|
||||
#![cfg_attr(feature = "unstable", feature(set_ptr_value))]
|
||||
#![cfg_attr(feature = "unstable", feature(pointer_byte_offsets))]
|
||||
#![warn(missing_docs)]
|
||||
#![warn(clippy::pedantic)]
|
||||
#![warn(clippy::nursery)]
|
||||
|
|
|
@ -1,9 +1,11 @@
|
|||
use std::{
|
||||
alloc::{alloc, Layout},
|
||||
mem::size_of_val,
|
||||
ptr::addr_of_mut,
|
||||
};
|
||||
|
||||
#[cfg(not(feature = "unstable"))]
|
||||
use std::ptr::addr_of_mut;
|
||||
|
||||
use self::__priv::Sealed;
|
||||
|
||||
mod __priv {
|
||||
|
@ -52,10 +54,18 @@ impl<T: ?Sized> PtrExt for *const T {
|
|||
self.with_addr(addr.addr())
|
||||
}
|
||||
|
||||
fn with_addr(mut self, addr: usize) -> Self {
|
||||
// TODO: aaaaand this is cheating. sorry yall, cant do this until `set_ptr_value` lands
|
||||
unsafe { *addr_of_mut!(self).cast() = addr }
|
||||
self
|
||||
fn with_addr(self, addr: usize) -> Self {
|
||||
#[cfg(feature = "unstable")]
|
||||
{
|
||||
self.wrapping_byte_sub(self.addr()).wrapping_byte_add(addr)
|
||||
}
|
||||
#[cfg(not(feature = "unstable"))]
|
||||
{
|
||||
let mut this = self;
|
||||
// TODO: aaaaand this is cheating. sorry yall, cant do this until `set_ptr_value` lands
|
||||
unsafe { *addr_of_mut!(this).cast() = addr }
|
||||
this
|
||||
}
|
||||
}
|
||||
|
||||
unsafe fn get_end(self) -> Self {
|
||||
|
@ -103,10 +113,18 @@ impl<T: ?Sized> PtrExt for *mut T {
|
|||
self.with_addr(addr.addr())
|
||||
}
|
||||
|
||||
fn with_addr(mut self, addr: usize) -> Self {
|
||||
// TODO: aaaaand this is cheating. sorry yall, cant do this until `set_ptr_value` lands
|
||||
unsafe { *addr_of_mut!(self).cast() = addr }
|
||||
self
|
||||
fn with_addr(self, addr: usize) -> Self {
|
||||
#[cfg(feature = "unstable")]
|
||||
{
|
||||
self.wrapping_byte_sub(self.addr()).wrapping_byte_add(addr)
|
||||
}
|
||||
#[cfg(not(feature = "unstable"))]
|
||||
{
|
||||
let mut this = self;
|
||||
// TODO: aaaaand this is cheating. sorry yall, cant do this until `set_ptr_value` lands
|
||||
unsafe { *addr_of_mut!(this).cast() = addr }
|
||||
this
|
||||
}
|
||||
}
|
||||
|
||||
unsafe fn get_end(self) -> Self {
|
||||
|
@ -156,7 +174,14 @@ impl<T: ?Sized> ConstPtrExt for *const T {
|
|||
// }
|
||||
|
||||
fn with_meta_from<U: ?Sized>(self, ptr: *const U) -> *const U {
|
||||
ptr.with_addr_from(self)
|
||||
#[cfg(feature = "unstable")]
|
||||
{
|
||||
self.with_metadata_of(ptr)
|
||||
}
|
||||
#[cfg(not(feature = "unstable"))]
|
||||
{
|
||||
ptr.with_addr_from(self)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -179,6 +204,13 @@ impl<T: ?Sized> MutPtrExt for *mut T {
|
|||
// }
|
||||
|
||||
fn with_meta_from<U: ?Sized>(self, ptr: *const U) -> *mut U {
|
||||
ptr.with_addr_from(self) as _
|
||||
#[cfg(feature = "unstable")]
|
||||
{
|
||||
self.with_metadata_of(ptr as _)
|
||||
}
|
||||
#[cfg(not(feature = "unstable"))]
|
||||
{
|
||||
ptr.with_addr_from(self) as _
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
//! Always use `cargo miri test`, and never just `cargo test`.
|
||||
//! Always use `cargo miri test --all-features`, and never just `cargo test`.
|
||||
|
||||
use rand::{thread_rng, Rng};
|
||||
|
||||
|
|
Loading…
Reference in a new issue