]> git.lizzy.rs Git - rust.git/commitdiff
Validate removal of AscribeUserType, FakeRead, and Shallow borrow
authorTomasz Miąsko <tomasz.miasko@gmail.com>
Thu, 10 Sep 2020 00:00:00 +0000 (00:00 +0000)
committerTomasz Miąsko <tomasz.miasko@gmail.com>
Thu, 10 Sep 2020 00:00:00 +0000 (00:00 +0000)
Those statements are removed by CleanupNonCodegenStatements pass
in drop lowering phase, and should not occur afterwards.

compiler/rustc_mir/src/transform/validate.rs

index 8f01e9428011663ccf7fc237ef4588fe10558e43..d3ca14abdcab201acbdcc90e0fea91625dd7c3a3 100644 (file)
@@ -4,8 +4,8 @@
 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 @@ fn visit_statement(&mut self, statement: &Statement<'tcx>, location: Location) {
                             )
                         }
                     }
+                    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",
+                    );
+                }
+            }
             _ => {}
         }
     }