This repository was archived by the owner on May 28, 2025. It is now read-only.
File tree 3 files changed +15
-21
lines changed
3 files changed +15
-21
lines changed Original file line number Diff line number Diff line change @@ -76,15 +76,13 @@ impl<T: ?Sized> *const T {
76
76
/// ```rust
77
77
/// #![feature(pointer_try_cast_aligned)]
78
78
///
79
- /// let aligned: *const u8 = 0x1000 as _ ;
79
+ /// let x = 0u64 ;
80
80
///
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) } ;
83
83
///
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());
88
86
/// ```
89
87
#[ unstable( feature = "pointer_try_cast_aligned" , issue = "141221" ) ]
90
88
#[ must_use = "this returns the result of the operation, \
Original file line number Diff line number Diff line change @@ -58,15 +58,13 @@ impl<T: ?Sized> *mut T {
58
58
/// ```rust
59
59
/// #![feature(pointer_try_cast_aligned)]
60
60
///
61
- /// let aligned: * mut u8 = 0x1000 as _ ;
61
+ /// let mut x = 0u64 ;
62
62
///
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) } ;
65
65
///
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());
70
68
/// ```
71
69
#[ unstable( feature = "pointer_try_cast_aligned" , issue = "141221" ) ]
72
70
#[ must_use = "this returns the result of the operation, \
Original file line number Diff line number Diff line change @@ -501,15 +501,13 @@ impl<T: ?Sized> NonNull<T> {
501
501
/// #![feature(pointer_try_cast_aligned)]
502
502
/// use std::ptr::NonNull;
503
503
///
504
- /// let aligned: NonNull<u8> = NonNull::new(0x1000 as _).unwrap() ;
504
+ /// let mut x = 0u64 ;
505
505
///
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) } ;
508
508
///
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());
513
511
/// ```
514
512
#[ unstable( feature = "pointer_try_cast_aligned" , issue = "141221" ) ]
515
513
#[ must_use = "this returns the result of the operation, \
You can’t perform that action at this time.
0 commit comments