diff options
| author | Yuki Okushi <huyuumi.dev@gmail.com> | 2020-10-15 07:32:39 +0900 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-10-15 07:32:39 +0900 |
| commit | ccc86bbb4057ed7d83963f27944402263081a37b (patch) | |
| tree | bb13fc6459b2c7e3afe6974467b96d344afd89e2 | |
| parent | df08fe7214a556b524b927f9af52de8861fe1121 (diff) | |
| parent | 585e737ec1844e13bbf2f50f3dc1057057a52184 (diff) | |
| download | rust-ccc86bbb4057ed7d83963f27944402263081a37b.tar.gz rust-ccc86bbb4057ed7d83963f27944402263081a37b.zip | |
Rollup merge of #77946 - tmiasko:validate-source-scope, r=jonas-schievink
Validate references to source scopes
| -rw-r--r-- | compiler/rustc_mir/src/transform/validate.rs | 17 |
1 files changed, 15 insertions, 2 deletions
diff --git a/compiler/rustc_mir/src/transform/validate.rs b/compiler/rustc_mir/src/transform/validate.rs index 48477f60ef7..beffffa727e 100644 --- a/compiler/rustc_mir/src/transform/validate.rs +++ b/compiler/rustc_mir/src/transform/validate.rs @@ -8,7 +8,7 @@ use super::MirPass; use rustc_middle::mir::visit::{PlaceContext, Visitor}; use rustc_middle::mir::{ AggregateKind, BasicBlock, Body, BorrowKind, Local, Location, MirPhase, Operand, Rvalue, - Statement, StatementKind, Terminator, TerminatorKind, VarDebugInfo, + SourceScope, Statement, StatementKind, Terminator, TerminatorKind, VarDebugInfo, }; use rustc_middle::ty::relate::{Relate, RelateResult, TypeRelation}; use rustc_middle::ty::{self, ParamEnv, Ty, TyCtxt}; @@ -229,9 +229,10 @@ impl<'a, 'tcx> Visitor<'tcx> for TypeChecker<'a, 'tcx> { } } - fn visit_var_debug_info(&mut self, _var_debug_info: &VarDebugInfo<'tcx>) { + fn visit_var_debug_info(&mut self, var_debug_info: &VarDebugInfo<'tcx>) { // Debuginfo can contain field projections, which count as a use of the base local. Skip // debuginfo so that we avoid the storage liveness assertion in that case. + self.visit_source_info(&var_debug_info.source_info); } fn visit_operand(&mut self, operand: &Operand<'tcx>, location: Location) { @@ -432,4 +433,16 @@ impl<'a, 'tcx> Visitor<'tcx> for TypeChecker<'a, 'tcx> { | TerminatorKind::GeneratorDrop => {} } } + + fn visit_source_scope(&mut self, scope: &SourceScope) { + if self.body.source_scopes.get(*scope).is_none() { + self.tcx.sess.diagnostic().delay_span_bug( + self.body.span, + &format!( + "broken MIR in {:?} ({}):\ninvalid source scope {:?}", + self.body.source.instance, self.when, scope, + ), + ); + } + } } |
