diff --git a/library/core/src/ptr/const_ptr.rs b/library/core/src/ptr/const_ptr.rs index 37679c504b30..d042f22f0266 100644 --- a/library/core/src/ptr/const_ptr.rs +++ b/library/core/src/ptr/const_ptr.rs @@ -1402,6 +1402,27 @@ const fn ctfe_impl(_: *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::().is_aligned()); + /// const _: () = assert!(!CONST_PTR.wrapping_add(1).cast::().is_aligned()); + /// + /// // At runtime, either `runtime_ptr` or `runtime_ptr + 1` is aligned. + /// let runtime_ptr = CONST_PTR; + /// assert_ne!( + /// runtime_ptr.cast::().is_aligned(), + /// runtime_ptr.wrapping_add(1).cast::().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. /// diff --git a/library/core/src/ptr/mut_ptr.rs b/library/core/src/ptr/mut_ptr.rs index 917472886893..764fa9d8ba81 100644 --- a/library/core/src/ptr/mut_ptr.rs +++ b/library/core/src/ptr/mut_ptr.rs @@ -1670,6 +1670,27 @@ const fn ctfe_impl(_: *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::().is_aligned()); + /// const _: () = assert!(!CONST_PTR.wrapping_add(1).cast::().is_aligned()); + /// + /// // At runtime, either `runtime_ptr` or `runtime_ptr + 1` is aligned. + /// let runtime_ptr = CONST_PTR; + /// assert_ne!( + /// runtime_ptr.cast::().is_aligned(), + /// runtime_ptr.wrapping_add(1).cast::().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. ///