@@ -101,19 +101,11 @@ safety_comment! {
101
101
/// - Given `t: *mut bool` and `let r = *mut u8`, `r` refers to an object
102
102
/// of the same size as that referred to by `t`. This is true because
103
103
/// `bool` and `u8` have the same size (1 byte) [1]. Neither `r` nor `t`
104
- /// contain `UnsafeCell`s because neither `bool` nor `u8` do [4].
105
- /// - Since the closure takes a `&u8` argument, given a `Maybe<'a,
106
- /// bool>` which satisfies the preconditions of
107
- /// `TryFromBytes::<bool>::is_bit_valid`, it must be guaranteed that the
108
- /// memory referenced by that `MaybeValid` always contains a valid `u8`.
109
- /// Since `bool`'s single byte is always initialized, `is_bit_valid`'s
110
- /// precondition requires that the same is true of its argument. Since
111
- /// `u8`'s only bit validity invariant is that its single byte must be
112
- /// initialized, this memory is guaranteed to contain a valid `u8`.
104
+ /// contain `UnsafeCell`s because neither `bool` nor `u8` do [3].
113
105
/// - The impl must only return `true` for its argument if the original
114
- /// `Maybe<bool>` refers to a valid `bool`. We only return true if
115
- /// the `u8` value is 0 or 1, and both of these are valid values for
116
- /// `bool`. [3 ]
106
+ /// `Maybe<bool>` refers to a valid `bool`. We only return true if the
107
+ /// `u8` value is 0 or 1, and both of these are valid values for `bool`.
108
+ /// [2 ]
117
109
///
118
110
/// [1] Per https://doc.rust-lang.org/1.81.0/reference/type-layout.html#primitive-data-layout:
119
111
///
@@ -124,16 +116,12 @@ safety_comment! {
124
116
/// | `bool` | 1 |
125
117
/// | `u8`/`i8` | 1 |
126
118
///
127
- /// [2] Per https://doc.rust-lang.org/1.81.0/reference/type-layout.html#size-and-alignment:
128
- ///
129
- /// The size of a value is always a multiple of its alignment.
130
- ///
131
- /// [3] Per https://doc.rust-lang.org/1.81.0/reference/types/boolean.html:
119
+ /// [2] Per https://doc.rust-lang.org/1.81.0/reference/types/boolean.html:
132
120
///
133
121
/// The value false has the bit pattern 0x00 and the value true has the
134
122
/// bit pattern 0x01.
135
123
///
136
- /// [4 ] TODO(#429): Justify this claim.
124
+ /// [3 ] TODO(#429): Justify this claim.
137
125
unsafe_impl!( bool : TryFromBytes ; |byte: MaybeAligned <u8 >| * byte. unaligned_as_ref( ) < 2 ) ;
138
126
}
139
127
safety_comment ! {
@@ -155,20 +143,10 @@ safety_comment! {
155
143
/// - Given `t: *mut char` and `let r = *mut u32`, `r` refers to an object
156
144
/// of the same size as that referred to by `t`. This is true because
157
145
/// `char` and `u32` have the same size [1]. Neither `r` nor `t` contain
158
- /// `UnsafeCell`s because neither `char` nor `u32` do [4].
159
- /// - Since the closure takes a `&u32` argument, given a `Maybe<'a,
160
- /// char>` which satisfies the preconditions of
161
- /// `TryFromBytes::<char>::is_bit_valid`, it must be guaranteed that the
162
- /// memory referenced by that `MaybeValid` always contains a valid
163
- /// `u32`. Since `char`'s bytes are always initialized [2],
164
- /// `is_bit_valid`'s precondition requires that the same is true of its
165
- /// argument. Since `u32`'s only bit validity invariant is that its
166
- /// bytes must be initialized, this memory is guaranteed to contain a
167
- /// valid `u32`.
146
+ /// `UnsafeCell`s because neither `char` nor `u32` do [3].
168
147
/// - The impl must only return `true` for its argument if the original
169
- /// `Maybe<char>` refers to a valid `char`. `char::from_u32`
170
- /// guarantees that it returns `None` if its input is not a valid
171
- /// `char`. [3]
148
+ /// `Maybe<char>` refers to a valid `char`. `char::from_u32` guarantees
149
+ /// that it returns `None` if its input is not a valid `char`. [2]
172
150
///
173
151
/// [1] Per https://doc.rust-lang.org/nightly/reference/types/textual.html#layout-and-bit-validity:
174
152
///
@@ -177,14 +155,10 @@ safety_comment! {
177
155
///
178
156
/// [2] Per https://doc.rust-lang.org/core/primitive.char.html#method.from_u32:
179
157
///
180
- /// Every byte of a `char` is guaranteed to be initialized.
181
- ///
182
- /// [3] Per https://doc.rust-lang.org/core/primitive.char.html#method.from_u32:
183
- ///
184
158
/// `from_u32()` will return `None` if the input is not a valid value for
185
159
/// a `char`.
186
160
///
187
- /// [4 ] TODO(#429): Justify this claim.
161
+ /// [3 ] TODO(#429): Justify this claim.
188
162
unsafe_impl!( char : TryFromBytes ; |candidate: MaybeAligned <u32 >| {
189
163
let candidate = candidate. read_unaligned:: <BecauseImmutable >( ) ;
190
164
char :: from_u32( candidate) . is_some( )
@@ -215,19 +189,9 @@ safety_comment! {
215
189
/// `str` and `[u8]` have the same representation. [1] Neither `t` nor
216
190
/// `r` contain `UnsafeCell`s because `[u8]` doesn't, and both `t` and
217
191
/// `r` have that representation.
218
- /// - Since the closure takes a `&[u8]` argument, given a `Maybe<'a,
219
- /// str>` which satisfies the preconditions of
220
- /// `TryFromBytes::<str>::is_bit_valid`, it must be guaranteed that the
221
- /// memory referenced by that `MaybeValid` always contains a valid
222
- /// `[u8]`. Since `str`'s bytes are always initialized [1],
223
- /// `is_bit_valid`'s precondition requires that the same is true of its
224
- /// argument. Since `[u8]`'s only bit validity invariant is that its
225
- /// bytes must be initialized, this memory is guaranteed to contain a
226
- /// valid `[u8]`.
227
192
/// - The impl must only return `true` for its argument if the original
228
- /// `Maybe<str>` refers to a valid `str`. `str::from_utf8`
229
- /// guarantees that it returns `Err` if its input is not a valid `str`.
230
- /// [2]
193
+ /// `Maybe<str>` refers to a valid `str`. `str::from_utf8` guarantees
194
+ /// that it returns `Err` if its input is not a valid `str`. [2]
231
195
///
232
196
/// [1] Per https://doc.rust-lang.org/1.81.0/reference/types/textual.html:
233
197
///
@@ -296,18 +260,9 @@ safety_comment! {
296
260
/// because `NonZeroXxx` and `xxx` have the same size. [1] Neither `r`
297
261
/// nor `t` refer to any `UnsafeCell`s because neither `NonZeroXxx` [2]
298
262
/// nor `xxx` do.
299
- /// - Since the closure takes a `&xxx` argument, given a `Maybe<'a,
300
- /// NonZeroXxx>` which satisfies the preconditions of
301
- /// `TryFromBytes::<NonZeroXxx>::is_bit_valid`, it must be guaranteed
302
- /// that the memory referenced by that `MabyeValid` always contains a
303
- /// valid `xxx`. Since `NonZeroXxx`'s bytes are always initialized [1],
304
- /// `is_bit_valid`'s precondition requires that the same is true of its
305
- /// argument. Since `xxx`'s only bit validity invariant is that its
306
- /// bytes must be initialized, this memory is guaranteed to contain a
307
- /// valid `xxx`.
308
263
/// - The impl must only return `true` for its argument if the original
309
- /// `Maybe<NonZeroXxx>` refers to a valid `NonZeroXxx`. The only
310
- /// `xxx` which is not also a valid `NonZeroXxx` is 0. [1]
264
+ /// `Maybe<NonZeroXxx>` refers to a valid `NonZeroXxx`. The only `xxx`
265
+ /// which is not also a valid `NonZeroXxx` is 0. [1]
311
266
///
312
267
/// [1] Per https://doc.rust-lang.org/1.81.0/core/num/type.NonZeroU16.html:
313
268
///
0 commit comments