about summary refs log tree commit diff
diff options
context:
space:
mode:
authorTomasz Miąsko <tomasz.miasko@gmail.com>2020-09-10 00:00:00 +0000
committerTomasz Miąsko <tomasz.miasko@gmail.com>2020-09-10 00:00:00 +0000
commit00e64ba476fa5bbc515bd6ff11151f8064748e88 (patch)
treea1a3b18d203135c14c341ebb2ae00e7bef912e2e
parente2be5f568d1f60365b825530f5b5cb722460591b (diff)
downloadrust-00e64ba476fa5bbc515bd6ff11151f8064748e88.tar.gz
rust-00e64ba476fa5bbc515bd6ff11151f8064748e88.zip
Validate removal of AscribeUserType, FakeRead, and Shallow borrow
Those statements are removed by CleanupNonCodegenStatements pass
in drop lowering phase, and should not occur afterwards.
-rw-r--r--compiler/rustc_mir/src/transform/validate.rs28
1 files changed, 26 insertions, 2 deletions
diff --git a/compiler/rustc_mir/src/transform/validate.rs b/compiler/rustc_mir/src/transform/validate.rs
index 8f01e942801..d3ca14abdca 100644
--- a/compiler/rustc_mir/src/transform/validate.rs
+++ b/compiler/rustc_mir/src/transform/validate.rs
@@ -4,8 +4,8 @@ use super::{MirPass, MirSource};
 use rustc_middle::mir::visit::Visitor;
 use rustc_middle::{
     mir::{
-        AggregateKind, BasicBlock, Body, Location, MirPhase, Operand, Rvalue, Statement,
-        StatementKind, Terminator, TerminatorKind,
+        AggregateKind, BasicBlock, Body, BorrowKind, Location, MirPhase, Operand, Rvalue,
+        Statement, StatementKind, Terminator, TerminatorKind,
     },
     ty::{
         self,
@@ -274,9 +274,33 @@ impl<'a, 'tcx> Visitor<'tcx> for TypeChecker<'a, 'tcx> {
                             )
                         }
                     }
+                    Rvalue::Ref(_, BorrowKind::Shallow, _) => {
+                        if self.mir_phase > MirPhase::DropLowering {
+                            self.fail(
+                                location,
+                                "`Assign` statement with a `Shallow` borrow should have been removed after drop lowering phase",
+                            );
+                        }
+                    }
                     _ => {}
                 }
             }
+            StatementKind::AscribeUserType(..) => {
+                if self.mir_phase > MirPhase::DropLowering {
+                    self.fail(
+                        location,
+                        "`AscribeUserType` should have been removed after drop lowering phase",
+                    );
+                }
+            }
+            StatementKind::FakeRead(..) => {
+                if self.mir_phase > MirPhase::DropLowering {
+                    self.fail(
+                        location,
+                        "`FakeRead` should have been removed after drop lowering phase",
+                    );
+                }
+            }
             _ => {}
         }
     }