Skip to content

Commit ccc86bb

Browse files
authored
Rollup merge of #77946 - tmiasko:validate-source-scope, r=jonas-schievink
Validate references to source scopes
2 parents df08fe7 + 585e737 commit ccc86bb

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

compiler/rustc_mir/src/transform/validate.rs

+15-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use super::MirPass;
88
use rustc_middle::mir::visit::{PlaceContext, Visitor};
99
use rustc_middle::mir::{
1010
AggregateKind, BasicBlock, Body, BorrowKind, Local, Location, MirPhase, Operand, Rvalue,
11-
Statement, StatementKind, Terminator, TerminatorKind, VarDebugInfo,
11+
SourceScope, Statement, StatementKind, Terminator, TerminatorKind, VarDebugInfo,
1212
};
1313
use rustc_middle::ty::relate::{Relate, RelateResult, TypeRelation};
1414
use rustc_middle::ty::{self, ParamEnv, Ty, TyCtxt};
@@ -229,9 +229,10 @@ impl<'a, 'tcx> Visitor<'tcx> for TypeChecker<'a, 'tcx> {
229229
}
230230
}
231231

232-
fn visit_var_debug_info(&mut self, _var_debug_info: &VarDebugInfo<'tcx>) {
232+
fn visit_var_debug_info(&mut self, var_debug_info: &VarDebugInfo<'tcx>) {
233233
// Debuginfo can contain field projections, which count as a use of the base local. Skip
234234
// debuginfo so that we avoid the storage liveness assertion in that case.
235+
self.visit_source_info(&var_debug_info.source_info);
235236
}
236237

237238
fn visit_operand(&mut self, operand: &Operand<'tcx>, location: Location) {
@@ -432,4 +433,16 @@ impl<'a, 'tcx> Visitor<'tcx> for TypeChecker<'a, 'tcx> {
432433
| TerminatorKind::GeneratorDrop => {}
433434
}
434435
}
436+
437+
fn visit_source_scope(&mut self, scope: &SourceScope) {
438+
if self.body.source_scopes.get(*scope).is_none() {
439+
self.tcx.sess.diagnostic().delay_span_bug(
440+
self.body.span,
441+
&format!(
442+
"broken MIR in {:?} ({}):\ninvalid source scope {:?}",
443+
self.body.source.instance, self.when, scope,
444+
),
445+
);
446+
}
447+
}
435448
}

0 commit comments

Comments
 (0)