-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Use strict provenance APIs * Allow compiling on stable again * Enable nightly feature for miri CI * Add more backports for MSRV
- Loading branch information
Showing
5 changed files
with
82 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
#[cfg(feature = "nightly")] | ||
mod implementation { | ||
pub use core::ptr::without_provenance_mut; | ||
|
||
pub fn with_metadata_of<T: ?Sized, U: ?Sized>(ptr: *const T, meta: *const U) -> *const U { | ||
ptr.with_metadata_of(meta) | ||
} | ||
|
||
pub fn with_metadata_of_mut<T: ?Sized, U: ?Sized>(ptr: *mut T, meta: *const U) -> *mut U { | ||
ptr.with_metadata_of(meta) | ||
} | ||
} | ||
|
||
#[cfg(not(feature = "nightly"))] | ||
#[allow(clippy::as_conversions)] | ||
mod implementation { | ||
use core::ptr::addr_of_mut; | ||
|
||
fn cast_to_mut<T: ?Sized>(ptr: *const T) -> *mut T { | ||
ptr as _ | ||
} | ||
|
||
pub fn without_provenance_mut<T>(addr: usize) -> *mut T { | ||
addr as _ | ||
} | ||
|
||
pub fn with_metadata_of<T: ?Sized, U: ?Sized>(ptr: *const T, meta: *const U) -> *const U { | ||
with_metadata_of_mut(cast_to_mut(ptr), meta) | ||
} | ||
|
||
pub fn with_metadata_of_mut<T: ?Sized, U: ?Sized>(ptr: *mut T, mut meta: *const U) -> *mut U { | ||
let meta_ptr = addr_of_mut!(meta).cast::<usize>(); | ||
unsafe { meta_ptr.write(ptr.cast::<u8>() as usize) } | ||
cast_to_mut(meta) | ||
} | ||
} | ||
|
||
pub fn from_ref<T: ?Sized>(val: &T) -> *const T { | ||
val | ||
} | ||
|
||
pub use implementation::*; |