Skip to content

Commit

Permalink
test it in core
Browse files Browse the repository at this point in the history
  • Loading branch information
Lukas Markeffsky committed Jan 19, 2024
1 parent 05be0e0 commit 79a600d
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
14 changes: 14 additions & 0 deletions library/core/src/ptr/const_ptr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,24 @@ impl<T: ?Sized> *const T {
#[rustc_const_stable(feature = "const_ptr_cast", since = "1.38.0")]
#[rustc_diagnostic_item = "const_ptr_cast"]
#[inline(always)]
#[cfg(bootstrap)]
pub const fn cast<U>(self) -> *const U {
self as _
}

/// Casts to a pointer of another type.
#[stable(feature = "ptr_cast", since = "1.38.0")]
#[rustc_const_stable(feature = "const_ptr_cast", since = "1.38.0")]
#[rustc_diagnostic_item = "const_ptr_cast"]
#[inline(always)]
#[cfg(not(bootstrap))]
pub const fn cast<U: ?Sized>(self) -> *const U
where
T: PointerCast<U>,
{
self as _
}

/// Use the pointer value in a new pointer of another type.
///
/// In case `meta` is a (fat) pointer to an unsized type, this operation
Expand Down
14 changes: 14 additions & 0 deletions library/core/src/ptr/mut_ptr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,24 @@ impl<T: ?Sized> *mut T {
#[rustc_const_stable(feature = "const_ptr_cast", since = "1.38.0")]
#[rustc_diagnostic_item = "ptr_cast"]
#[inline(always)]
#[cfg(bootstrap)]
pub const fn cast<U>(self) -> *mut U {
self as _
}

/// Casts to a pointer of another type.
#[stable(feature = "ptr_cast", since = "1.38.0")]
#[rustc_const_stable(feature = "const_ptr_cast", since = "1.38.0")]
#[rustc_diagnostic_item = "ptr_cast"]
#[inline(always)]
#[cfg(not(bootstrap))]
pub const fn cast<U: ?Sized>(self) -> *mut U
where
T: PointerCast<U>,
{
self as _
}

/// Use the pointer value in a new pointer of another type.
///
/// In case `meta` is a (fat) pointer to an unsized type, this operation
Expand Down

0 comments on commit 79a600d

Please sign in to comment.