Skip to content

Commit e5d9065

Browse files
committed
Comment on the unsafety code for layout constrained fields
1 parent 55abc0b commit e5d9065

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

src/librustc_mir/transform/check_unsafety.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,12 @@ impl<'a, 'tcx> Visitor<'tcx> for UnsafetyChecker<'a, 'tcx> {
192192
.ty(self.mir, self.tcx)
193193
.to_ty(self.tcx)
194194
.is_freeze(self.tcx, self.param_env, self.source_info.span);
195+
// prevent
196+
// * `&mut x.field`
197+
// * `x.field = y;`
198+
// * `&x.field` if `field`'s type has interior mutability
199+
// because either of these would allow modifying the layout constrained field and
200+
// insert values that violate the layout constraints.
195201
if context.is_mutating_use() || is_borrow_of_interior_mut {
196202
self.check_mut_borrowing_layout_constrained_field(
197203
place, context.is_mutating_use(),

0 commit comments

Comments
 (0)