diff options
| author | bors <bors@rust-lang.org> | 2022-05-30 20:06:25 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2022-05-30 20:06:25 +0000 |
| commit | c35035cefc709abddabfb28ecc6a326458d46ce2 (patch) | |
| tree | afccff3d4b4125c7d0419a3bedb5736eaa5bc51c /compiler/rustc_const_eval/src/transform/validate.rs | |
| parent | 4a8d2e3856c0c75c71998b6c85937203839b946d (diff) | |
| parent | e71913e847666ae9c35417c9590091d72ec6a5e9 (diff) | |
| download | rust-c35035cefc709abddabfb28ecc6a326458d46ce2.tar.gz rust-c35035cefc709abddabfb28ecc6a326458d46ce2.zip | |
Auto merge of #97025 - ouz-a:mini-derefer-generator, r=davidtwco
Add validation layer for Derefer _Follow up work to #96549 #96116 #95857 #95649_ This adds validation for Derefer making sure it is always the first projection. r? rust-lang/mir-opt
Diffstat (limited to 'compiler/rustc_const_eval/src/transform/validate.rs')
| -rw-r--r-- | compiler/rustc_const_eval/src/transform/validate.rs | 11 |
1 files changed, 10 insertions, 1 deletions
diff --git a/compiler/rustc_const_eval/src/transform/validate.rs b/compiler/rustc_const_eval/src/transform/validate.rs index 54c2daf9ac2..665b07c9f89 100644 --- a/compiler/rustc_const_eval/src/transform/validate.rs +++ b/compiler/rustc_const_eval/src/transform/validate.rs @@ -4,6 +4,7 @@ use rustc_data_structures::fx::FxHashSet; use rustc_index::bit_set::BitSet; use rustc_infer::infer::TyCtxtInferExt; use rustc_middle::mir::interpret::Scalar; +use rustc_middle::mir::visit::NonUseContext::VarDebugInfo; use rustc_middle::mir::visit::{PlaceContext, Visitor}; use rustc_middle::mir::{ traversal, AggregateKind, BasicBlock, BinOp, Body, BorrowKind, Local, Location, MirPass, @@ -302,9 +303,17 @@ impl<'a, 'tcx> Visitor<'tcx> for TypeChecker<'a, 'tcx> { self.super_projection_elem(local, proj_base, elem, context, location); } - fn visit_place(&mut self, place: &Place<'tcx>, _: PlaceContext, _: Location) { + fn visit_place(&mut self, place: &Place<'tcx>, cntxt: PlaceContext, location: Location) { // Set off any `bug!`s in the type computation code let _ = place.ty(&self.body.local_decls, self.tcx); + + if self.mir_phase >= MirPhase::Derefered + && place.projection.len() > 1 + && cntxt != PlaceContext::NonUse(VarDebugInfo) + && place.projection[1..].contains(&ProjectionElem::Deref) + { + self.fail(location, format!("{:?}, has deref at the wrong place", place)); + } } fn visit_rvalue(&mut self, rvalue: &Rvalue<'tcx>, location: Location) { |
