@@ -26,21 +26,23 @@ where
26
26
T : ' a + ?Sized + TryFromBytes ,
27
27
Alignment : invariant:: Alignment ,
28
28
{
29
- /// Checks that `Ptr`'s referent is validly initialized for `T`.
29
+ /// Check that `Ptr`'s referent is validly initialized for `T`.
30
30
///
31
31
/// # Panics
32
32
///
33
33
/// This method will panic if
34
34
/// [`T::is_bit_valid`][TryFromBytes::is_bit_valid] panics.
35
35
#[ inline]
36
36
pub ( crate ) fn check_valid ( self ) -> Option < MaybeAligned < ' a , T , Alignment > > {
37
+ let candidate = self ;
37
38
// This call may panic. If that happens, it doesn't cause any soundness
38
39
// issues, as we have not generated any invalid state which we need to
39
40
// fix before returning.
40
- if T :: is_bit_valid ( self . forget_aligned ( ) ) {
41
- // SAFETY: If `T ::is_bit_valid`, code may assume that `self `
41
+ if T :: is_bit_valid ( candidate . forget_aligned ( ) ) {
42
+ // SAFETY: If `Self ::is_bit_valid`, code may assume that `candidate `
42
43
// contains a bit-valid instance of `Self`.
43
- Some ( unsafe { self . assume_valid ( ) } )
44
+ let candidate = unsafe { candidate. assume_valid ( ) } ;
45
+ Some ( candidate)
44
46
} else {
45
47
None
46
48
}
60
62
Alignment : invariant:: Alignment ,
61
63
{
62
64
/// Reads the value from `MaybeAligned`.
65
+ ///
66
+ /// This is only available if `T` is [`Copy`].
63
67
#[ inline]
64
68
pub fn read_unaligned ( self ) -> T
65
69
where
0 commit comments