Skip to content

Commit

Permalink
avoid using unstable ptr::invalid_mut
Browse files Browse the repository at this point in the history
  • Loading branch information
RalfJung committed Nov 7, 2023
1 parent 778e235 commit f13a05a
Showing 1 changed file with 4 additions and 6 deletions.
10 changes: 4 additions & 6 deletions src/raw/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,14 +57,12 @@ use core::convert::identity as unlikely;
#[cfg(feature = "nightly")]
use core::intrinsics::{likely, unlikely};

// Use strict provenance functions if available.
#[cfg(feature = "nightly")]
use core::ptr::invalid_mut;
// Implement it with a cast otherwise.
#[cfg(not(feature = "nightly"))]
// FIXME: use strict provenance functions once they are stable.
// Implement it with a transmute for now.
#[inline(always)]
#[allow(clippy::useless_transmute)] // clippy is wrong, cast and transmute are different here
fn invalid_mut<T>(addr: usize) -> *mut T {
addr as *mut T
unsafe { core::mem::transmute(addr) }
}

#[inline]
Expand Down

0 comments on commit f13a05a

Please sign in to comment.