Skip to content

Commit 28b0c87

Browse files
committed
update MIR place semantics UB comment
1 parent b131fc1 commit 28b0c87

File tree

1 file changed

+9
-12
lines changed

1 file changed

+9
-12
lines changed

compiler/rustc_middle/src/mir/syntax.rs

+9-12
Original file line numberDiff line numberDiff line change
@@ -986,18 +986,15 @@ pub type AssertMessage<'tcx> = AssertKind<Operand<'tcx>>;
986986
/// pointee's type. The resulting address is the address that was stored in the pointer. If the
987987
/// pointee type is unsized, the pointer additionally stored the value of the metadata.
988988
///
989-
/// Computing a place may cause UB. One possibility is that the pointer used for a `Deref` may not
990-
/// be suitably aligned. Another possibility is that the place is not in bounds, meaning it does not
991-
/// point to an actual allocation.
992-
///
993-
/// However, if this is actually UB and when the UB kicks in is undecided. This is being discussed
994-
/// in [UCG#319]. The options include that every place must obey those rules, that only some places
995-
/// must obey them, or that places impose no rules of their own.
996-
///
997-
/// [UCG#319]: https://github.com/rust-lang/unsafe-code-guidelines/issues/319
998-
///
999-
/// Rust currently requires that every place obey those two rules. This is checked by Miri and taken
1000-
/// advantage of by codegen (via `gep inbounds`). That is possibly subject to change.
989+
/// The "validity invariant" of places is the same as that of raw pointers, meaning that e.g.
990+
/// `*ptr` on a dangling or unaligned pointer is never UB. (Later doing a load/store on that place
991+
/// or turning it into a reference can be UB though!) The only ways for a place computation can
992+
/// cause UB are:
993+
/// - On a `Deref` projection, we do an actual load of the inner place, with all the usual
994+
/// consequences (the inner place must be based on an aligned pointer, it must point to allocated
995+
/// memory, the aliasig model must allow reads, this must not be a data race).
996+
/// - For the projections that perform pointer arithmetic, the offset must in-bounds of an
997+
/// allocation (i.e., the preconditions of `ptr::offset` must be met).
1001998
#[derive(Copy, Clone, PartialEq, Eq, Hash, TyEncodable, HashStable, TypeFoldable, TypeVisitable)]
1002999
pub struct Place<'tcx> {
10031000
pub local: Local,

0 commit comments

Comments
 (0)