Skip to content

Commit 81a0fd9

Browse files
authored
Update SizeEq safety invariant (#2564)
This should have been changed in #2428, where we changed the in-practice safety invariant, but forgot to update the doc comment. Makes progress on #1817 gherrit-pr-id: I910c77e45532313e316ee443f9cf70d0d74cff67
1 parent 09334fd commit 81a0fd9

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

src/pointer/transmute.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -291,8 +291,11 @@ pub unsafe trait TransmuteFrom<Src: ?Sized, SV, DV> {}
291291
/// etc) and have the same size. In particular:
292292
/// - If `T: Sized` and `Self: Sized`, then their sizes must be equal
293293
/// - If `T: ?Sized` and `Self: ?Sized`, then it must be the case that, given
294-
/// any `t: *mut T`, `t as *mut Self` produces a pointer which addresses the
295-
/// same number of bytes as `t`.
294+
/// any `t: PtrInner<'_, T>`, `<Self as SizeEq<T>>::cast_from_raw(t)` produces
295+
/// a pointer which addresses the same number of bytes as `t`. *Note that it
296+
/// is **not** guaranteed that an `as` cast preserves referent size: it may be
297+
/// the case that `cast_from_raw` modifies the pointer's metadata in order to
298+
/// preserve referent size, which an `as` cast does not do.*
296299
pub unsafe trait SizeEq<T: ?Sized> {
297300
fn cast_from_raw(t: PtrInner<'_, T>) -> PtrInner<'_, Self>;
298301
}

0 commit comments

Comments
 (0)