Skip to content

Commit 7eb1a1a

Browse files
committed
Validate that locals have a corresponding LocalDecl
1 parent f2a11a2 commit 7eb1a1a

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

compiler/rustc_mir/src/transform/validate.rs

+7
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,13 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
183183

184184
impl<'a, 'tcx> Visitor<'tcx> for TypeChecker<'a, 'tcx> {
185185
fn visit_local(&mut self, local: &Local, context: PlaceContext, location: Location) {
186+
if self.body.local_decls.get(*local).is_none() {
187+
self.fail(
188+
location,
189+
format!("local {:?} has no corresponding declaration in `body.local_decls`", local),
190+
);
191+
}
192+
186193
if self.reachable_blocks.contains(location.block) && context.is_use() {
187194
// Uses of locals must occur while the local's storage is allocated.
188195
self.storage_liveness.seek_after_primary_effect(location);

0 commit comments

Comments
 (0)