mirror of
https://github.com/rust-lang/rust.git
synced 2026-05-21 17:52:12 +03:00
Schrödinger's pointer
It's aligned *and* not aligned!
This commit is contained in:
@@ -1402,6 +1402,27 @@ const fn ctfe_impl<T>(_: *const T, _: usize) -> usize {
|
||||
/// };
|
||||
/// ```
|
||||
///
|
||||
/// Due to this behavior, it is possible that a runtime pointer derived from a compiletime
|
||||
/// pointer is aligned, even if the compiletime pointer wasn't aligned.
|
||||
///
|
||||
#[cfg_attr(bootstrap, doc = "```ignore")]
|
||||
#[cfg_attr(not(bootstrap), doc = "```")]
|
||||
/// #![feature(pointer_is_aligned)]
|
||||
/// #![feature(const_pointer_is_aligned)]
|
||||
///
|
||||
/// // At compiletime, neither `CONST_PTR` nor `CONST_PTR + 1` is aligned.
|
||||
/// const CONST_PTR: *const i32 = &42;
|
||||
/// const _: () = assert!(!CONST_PTR.cast::<i64>().is_aligned());
|
||||
/// const _: () = assert!(!CONST_PTR.wrapping_add(1).cast::<i64>().is_aligned());
|
||||
///
|
||||
/// // At runtime, either `runtime_ptr` or `runtime_ptr + 1` is aligned.
|
||||
/// let runtime_ptr = CONST_PTR;
|
||||
/// assert_ne!(
|
||||
/// runtime_ptr.cast::<i64>().is_aligned(),
|
||||
/// runtime_ptr.wrapping_add(1).cast::<i64>().is_aligned(),
|
||||
/// );
|
||||
/// ```
|
||||
///
|
||||
/// If a pointer is created from a fixed address, this function behaves the same during
|
||||
/// runtime and compiletime.
|
||||
///
|
||||
@@ -1492,6 +1513,27 @@ pub const fn is_aligned(self) -> bool
|
||||
/// };
|
||||
/// ```
|
||||
///
|
||||
/// Due to this behavior, it is possible that a runtime pointer derived from a compiletime
|
||||
/// pointer is aligned, even if the compiletime pointer wasn't aligned.
|
||||
///
|
||||
#[cfg_attr(bootstrap, doc = "```ignore")]
|
||||
#[cfg_attr(not(bootstrap), doc = "```")]
|
||||
/// #![feature(pointer_is_aligned)]
|
||||
/// #![feature(const_pointer_is_aligned)]
|
||||
///
|
||||
/// // At compiletime, neither `CONST_PTR` nor `CONST_PTR + 1` is aligned.
|
||||
/// const CONST_PTR: *const i32 = &42;
|
||||
/// const _: () = assert!(!CONST_PTR.is_aligned_to(8));
|
||||
/// const _: () = assert!(!CONST_PTR.wrapping_add(1).is_aligned_to(8));
|
||||
///
|
||||
/// // At runtime, either `runtime_ptr` or `runtime_ptr + 1` is aligned.
|
||||
/// let runtime_ptr = CONST_PTR;
|
||||
/// assert_ne!(
|
||||
/// runtime_ptr.is_aligned_to(8),
|
||||
/// runtime_ptr.wrapping_add(1).is_aligned_to(8),
|
||||
/// );
|
||||
/// ```
|
||||
///
|
||||
/// If a pointer is created from a fixed address, this function behaves the same during
|
||||
/// runtime and compiletime.
|
||||
///
|
||||
|
||||
@@ -1670,6 +1670,27 @@ const fn ctfe_impl<T>(_: *mut T, _: usize) -> usize {
|
||||
/// };
|
||||
/// ```
|
||||
///
|
||||
/// Due to this behavior, it is possible that a runtime pointer derived from a compiletime
|
||||
/// pointer is aligned, even if the compiletime pointer wasn't aligned.
|
||||
///
|
||||
#[cfg_attr(bootstrap, doc = "```ignore")]
|
||||
#[cfg_attr(not(bootstrap), doc = "```")]
|
||||
/// #![feature(pointer_is_aligned)]
|
||||
/// #![feature(const_pointer_is_aligned)]
|
||||
///
|
||||
/// // At compiletime, neither `CONST_PTR` nor `CONST_PTR + 1` is aligned.
|
||||
/// const CONST_PTR: *const i32 = &42;
|
||||
/// const _: () = assert!(!CONST_PTR.cast::<i64>().is_aligned());
|
||||
/// const _: () = assert!(!CONST_PTR.wrapping_add(1).cast::<i64>().is_aligned());
|
||||
///
|
||||
/// // At runtime, either `runtime_ptr` or `runtime_ptr + 1` is aligned.
|
||||
/// let runtime_ptr = CONST_PTR;
|
||||
/// assert_ne!(
|
||||
/// runtime_ptr.cast::<i64>().is_aligned(),
|
||||
/// runtime_ptr.wrapping_add(1).cast::<i64>().is_aligned(),
|
||||
/// );
|
||||
/// ```
|
||||
///
|
||||
/// If a pointer is created from a fixed address, this function behaves the same during
|
||||
/// runtime and compiletime.
|
||||
///
|
||||
@@ -1760,6 +1781,27 @@ pub const fn is_aligned(self) -> bool
|
||||
/// };
|
||||
/// ```
|
||||
///
|
||||
/// Due to this behavior, it is possible that a runtime pointer derived from a compiletime
|
||||
/// pointer is aligned, even if the compiletime pointer wasn't aligned.
|
||||
///
|
||||
#[cfg_attr(bootstrap, doc = "```ignore")]
|
||||
#[cfg_attr(not(bootstrap), doc = "```")]
|
||||
/// #![feature(pointer_is_aligned)]
|
||||
/// #![feature(const_pointer_is_aligned)]
|
||||
///
|
||||
/// // At compiletime, neither `CONST_PTR` nor `CONST_PTR + 1` is aligned.
|
||||
/// const CONST_PTR: *const i32 = &42;
|
||||
/// const _: () = assert!(!CONST_PTR.is_aligned_to(8));
|
||||
/// const _: () = assert!(!CONST_PTR.wrapping_add(1).is_aligned_to(8));
|
||||
///
|
||||
/// // At runtime, either `runtime_ptr` or `runtime_ptr + 1` is aligned.
|
||||
/// let runtime_ptr = CONST_PTR;
|
||||
/// assert_ne!(
|
||||
/// runtime_ptr.is_aligned_to(8),
|
||||
/// runtime_ptr.wrapping_add(1).is_aligned_to(8),
|
||||
/// );
|
||||
/// ```
|
||||
///
|
||||
/// If a pointer is created from a fixed address, this function behaves the same during
|
||||
/// runtime and compiletime.
|
||||
///
|
||||
|
||||
Reference in New Issue
Block a user