Skip to content

Commit

Permalink
Adjust justification comment
Browse files Browse the repository at this point in the history
  • Loading branch information
5225225 committed Aug 1, 2022
1 parent 5ee555c commit eb1b384
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions compiler/rustc_middle/src/ty/layout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3553,12 +3553,17 @@ where
// We panic if creating this type with all 0x01 bytes would
// cause LLVM UB.
//
// Therefore, in order for us to not panic,
// * the alignment of the pointer must be 1
// (or we would have an unaligned pointer)
// Therefore, in order for us to not panic, it must either be a
// reference to [T] where T has align 1 (where we don't statically know
// the size, so we don't emit any dereferenceable), or a reference to str
// which acts much like a [u8].
//
// * the statically known size of the pointee must be 0.
// (or we would emit dereferenceable)
// We *do* need to panic for &dyn Trait, even though the layout of dyn Trait is
// size 0 align 1, because &dyn Trait holds a reference to a non-zero sized type,
// which also must be aligned.
//
// This even applies to *const dyn Trait, which holds a reference and therefore
// must be valid, so 1-initialization is not okay there.
//
// If this bypass didn't exist, old versions of `hyper` with no semver compatible
// fix (0.11, 0.12, 0.13) would panic, as they make uninit &[u8] and &str.
Expand Down

0 comments on commit eb1b384

Please sign in to comment.