]> git.lizzy.rs Git - rust.git/commitdiff
Treat `Rvalue::AddressOf` the same as `Rvalue::Ref`
authorDylan MacKenzie <ecstaticmorse@gmail.com>
Mon, 3 Feb 2020 18:37:36 +0000 (10:37 -0800)
committerDylan MacKenzie <ecstaticmorse@gmail.com>
Mon, 3 Feb 2020 18:38:32 +0000 (10:38 -0800)
src/librustc_mir/transform/check_consts/validation.rs

index 1728037ad43b8114dee11a1b39a2008cff1ff69d..5abc5eb154fbf8fc274b5a7742c3a5582f5e37b5 100644 (file)
@@ -233,18 +233,6 @@ fn check_static(&mut self, def_id: DefId, span: Span) {
             self.check_op_spanned(ops::StaticAccess, span)
         }
     }
-
-    fn check_immutable_borrow_like(&mut self, location: Location, place: &Place<'tcx>) {
-        let borrowed_place_has_mut_interior = HasMutInterior::in_place(
-            &self.item,
-            &mut |local| self.qualifs.has_mut_interior(local, location),
-            place.as_ref(),
-        );
-
-        if borrowed_place_has_mut_interior {
-            self.check_op(ops::CellBorrow);
-        }
-    }
 }
 
 impl Visitor<'tcx> for Validator<'_, 'mir, 'tcx> {
@@ -350,12 +338,17 @@ fn visit_rvalue(&mut self, rvalue: &Rvalue<'tcx>, location: Location) {
             Rvalue::AddressOf(Mutability::Mut, _) => self.check_op(ops::MutAddressOf),
 
             Rvalue::Ref(_, BorrowKind::Shared, ref place)
-            | Rvalue::Ref(_, BorrowKind::Shallow, ref place) => {
-                self.check_immutable_borrow_like(location, place)
-            }
-
-            Rvalue::AddressOf(Mutability::Not, ref place) => {
-                self.check_immutable_borrow_like(location, place)
+            | Rvalue::Ref(_, BorrowKind::Shallow, ref place)
+            | Rvalue::AddressOf(Mutability::Not, ref place) => {
+                let borrowed_place_has_mut_interior = HasMutInterior::in_place(
+                    &self.item,
+                    &mut |local| self.qualifs.has_mut_interior(local, location),
+                    place.as_ref(),
+                );
+
+                if borrowed_place_has_mut_interior {
+                    self.check_op(ops::CellBorrow);
+                }
             }
 
             Rvalue::Cast(CastKind::Misc, ref operand, cast_ty) => {