]> git.lizzy.rs Git - rust.git/commitdiff
Comment on the unsafety code for layout constrained fields
authorOliver Scherer <github35764891676564198441@oli-obk.de>
Mon, 5 Nov 2018 12:29:17 +0000 (13:29 +0100)
committerOliver Scherer <github35764891676564198441@oli-obk.de>
Tue, 4 Dec 2018 09:17:36 +0000 (10:17 +0100)
src/librustc_mir/transform/check_unsafety.rs

index b124f8b1c0be94d5597b53ba09f46041b5cbea1f..671ca355dbfc1ae3914d908dfec6bd6c4d63724e 100644 (file)
@@ -192,6 +192,12 @@ fn visit_place(&mut self,
                     .ty(self.mir, self.tcx)
                     .to_ty(self.tcx)
                     .is_freeze(self.tcx, self.param_env, self.source_info.span);
+                // prevent
+                // * `&mut x.field`
+                // * `x.field = y;`
+                // * `&x.field` if `field`'s type has interior mutability
+                // because either of these would allow modifying the layout constrained field and
+                // insert values that violate the layout constraints.
                 if context.is_mutating_use() || is_borrow_of_interior_mut {
                     self.check_mut_borrowing_layout_constrained_field(
                         place, context.is_mutating_use(),