File tree 3 files changed +10
-7
lines changed 3 files changed +10
-7
lines changed Original file line number Diff line number Diff line change @@ -75,13 +75,14 @@ impl<T: ?Sized> *const T {
75
75
///
76
76
/// ```rust
77
77
/// #![feature(pointer_try_cast_aligned)]
78
+ /// use std::ptr;
78
79
///
79
- /// let aligned: *const u8 = 0x1000 as _ ;
80
+ /// let aligned: *const u8 = ptr::without_provenance( 0x1000) ;
80
81
///
81
82
/// // i32 has at most 4-byte alignment, so this will succeed
82
83
/// assert!(aligned.try_cast_aligned::<i32>().is_some());
83
84
///
84
- /// let unaligned: *const u8 = 0x1001 as _ ;
85
+ /// let unaligned: *const u8 = ptr::without_provenance( 0x1001) ;
85
86
///
86
87
/// // i32 has at least 2-byte alignment, so this will fail
87
88
/// assert!(unaligned.try_cast_aligned::<i32>().is_none());
Original file line number Diff line number Diff line change @@ -57,13 +57,14 @@ impl<T: ?Sized> *mut T {
57
57
///
58
58
/// ```rust
59
59
/// #![feature(pointer_try_cast_aligned)]
60
+ /// use std::ptr;
60
61
///
61
- /// let aligned: *mut u8 = 0x1000 as _ ;
62
+ /// let aligned: *mut u8 = ptr::without_provenance_mut( 0x1000) ;
62
63
///
63
64
/// // i32 has at most 4-byte alignment, so this will succeed
64
65
/// assert!(aligned.try_cast_aligned::<i32>().is_some());
65
66
///
66
- /// let unaligned: *mut u8 = 0x1001 as _ ;
67
+ /// let unaligned: *mut u8 = ptr::without_provenance_mut( 0x1001) ;
67
68
///
68
69
/// // i32 has at least 2-byte alignment, so this will fail
69
70
/// assert!(unaligned.try_cast_aligned::<i32>().is_none());
Original file line number Diff line number Diff line change @@ -498,15 +498,16 @@ impl<T: ?Sized> NonNull<T> {
498
498
/// # Examples
499
499
///
500
500
/// ```rust
501
- /// #![feature(pointer_try_cast_aligned)]
501
+ /// #![feature(pointer_try_cast_aligned, nonnull_provenance)]
502
+ /// use std::num::NonZero;
502
503
/// use std::ptr::NonNull;
503
504
///
504
- /// let aligned: NonNull<u8> = NonNull::new(0x1000 as _ ).unwrap();
505
+ /// let aligned: NonNull<u8> = NonNull::without_provenance(NonZero:: new(0x1000).unwrap() );
505
506
///
506
507
/// // i32 has at most 4-byte alignment, so this will succeed
507
508
/// assert!(aligned.try_cast_aligned::<i32>().is_some());
508
509
///
509
- /// let unaligned: NonNull<u8> = NonNull::new(0x1001 as _ ).unwrap();
510
+ /// let unaligned: NonNull<u8> = NonNull::without_provenance(NonZero:: new(0x1001).unwrap() );
510
511
///
511
512
/// // i32 has at least 2-byte alignment, so this will fail
512
513
/// assert!(unaligned.try_cast_aligned::<i32>().is_none());
You can’t perform that action at this time.
0 commit comments