Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit b717a97

Browse files
authored
Unrolled build for rust-lang#141381
Rollup merge of rust-lang#141381 - RalfJung:try_cast_aligned-strict-provenance, r=tgross35 try_cast_aligned: avoid bare int-to-ptr casts This fixes a CI failure in https://github.com/rust-lang/miri-test-libstd caused by strict provenance violations in doctests added in rust-lang#141222. r? `@tgross35` Cc `@mathisbot`
2 parents d423c81 + 09ae053 commit b717a97

File tree

3 files changed

+15
-21
lines changed

3 files changed

+15
-21
lines changed

library/core/src/ptr/const_ptr.rs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -76,15 +76,13 @@ impl<T: ?Sized> *const T {
7676
/// ```rust
7777
/// #![feature(pointer_try_cast_aligned)]
7878
///
79-
/// let aligned: *const u8 = 0x1000 as _;
79+
/// let x = 0u64;
8080
///
81-
/// // i32 has at most 4-byte alignment, so this will succeed
82-
/// assert!(aligned.try_cast_aligned::<i32>().is_some());
81+
/// let aligned: *const u64 = &x;
82+
/// let unaligned = unsafe { aligned.byte_add(1) };
8383
///
84-
/// let unaligned: *const u8 = 0x1001 as _;
85-
///
86-
/// // i32 has at least 2-byte alignment, so this will fail
87-
/// assert!(unaligned.try_cast_aligned::<i32>().is_none());
84+
/// assert!(aligned.try_cast_aligned::<u32>().is_some());
85+
/// assert!(unaligned.try_cast_aligned::<u32>().is_none());
8886
/// ```
8987
#[unstable(feature = "pointer_try_cast_aligned", issue = "141221")]
9088
#[must_use = "this returns the result of the operation, \

library/core/src/ptr/mut_ptr.rs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -58,15 +58,13 @@ impl<T: ?Sized> *mut T {
5858
/// ```rust
5959
/// #![feature(pointer_try_cast_aligned)]
6060
///
61-
/// let aligned: *mut u8 = 0x1000 as _;
61+
/// let mut x = 0u64;
6262
///
63-
/// // i32 has at most 4-byte alignment, so this will succeed
64-
/// assert!(aligned.try_cast_aligned::<i32>().is_some());
63+
/// let aligned: *mut u64 = &mut x;
64+
/// let unaligned = unsafe { aligned.byte_add(1) };
6565
///
66-
/// let unaligned: *mut u8 = 0x1001 as _;
67-
///
68-
/// // i32 has at least 2-byte alignment, so this will fail
69-
/// assert!(unaligned.try_cast_aligned::<i32>().is_none());
66+
/// assert!(aligned.try_cast_aligned::<u32>().is_some());
67+
/// assert!(unaligned.try_cast_aligned::<u32>().is_none());
7068
/// ```
7169
#[unstable(feature = "pointer_try_cast_aligned", issue = "141221")]
7270
#[must_use = "this returns the result of the operation, \

library/core/src/ptr/non_null.rs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -501,15 +501,13 @@ impl<T: ?Sized> NonNull<T> {
501501
/// #![feature(pointer_try_cast_aligned)]
502502
/// use std::ptr::NonNull;
503503
///
504-
/// let aligned: NonNull<u8> = NonNull::new(0x1000 as _).unwrap();
504+
/// let mut x = 0u64;
505505
///
506-
/// // i32 has at most 4-byte alignment, so this will succeed
507-
/// assert!(aligned.try_cast_aligned::<i32>().is_some());
506+
/// let aligned = NonNull::from_mut(&mut x);
507+
/// let unaligned = unsafe { aligned.byte_add(1) };
508508
///
509-
/// let unaligned: NonNull<u8> = NonNull::new(0x1001 as _).unwrap();
510-
///
511-
/// // i32 has at least 2-byte alignment, so this will fail
512-
/// assert!(unaligned.try_cast_aligned::<i32>().is_none());
509+
/// assert!(aligned.try_cast_aligned::<u32>().is_some());
510+
/// assert!(unaligned.try_cast_aligned::<u32>().is_none());
513511
/// ```
514512
#[unstable(feature = "pointer_try_cast_aligned", issue = "141221")]
515513
#[must_use = "this returns the result of the operation, \

0 commit comments

Comments
 (0)