Skip to content

Commit 2384e98

Browse files
committed
rustc_mir: don't use upvar_decls in the miri validity checks.
1 parent c1ec45f commit 2384e98

File tree

1 file changed

+22
-6
lines changed

1 file changed

+22
-6
lines changed

src/librustc_mir/interpret/validity.rs

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ use std::hash::Hash;
33
use std::ops::RangeInclusive;
44

55
use syntax_pos::symbol::Symbol;
6+
use rustc::hir;
67
use rustc::ty::layout::{self, Size, Align, TyLayout, LayoutOf, VariantIdx};
78
use rustc::ty;
89
use rustc_data_structures::fx::FxHashSet;
@@ -165,13 +166,28 @@ impl<'rt, 'a, 'mir, 'tcx, M: Machine<'a, 'mir, 'tcx>> ValidityVisitor<'rt, 'a, '
165166
match layout.ty.sty {
166167
// generators and closures.
167168
ty::Closure(def_id, _) | ty::Generator(def_id, _, _) => {
168-
if let Some(upvar) = self.ecx.tcx.optimized_mir(def_id).upvar_decls.get(field) {
169-
PathElem::ClosureVar(upvar.debug_name)
170-
} else {
171-
// Sometimes the index is beyond the number of freevars (seen
172-
// for a generator).
173-
PathElem::ClosureVar(Symbol::intern(&field.to_string()))
169+
let mut name = None;
170+
if def_id.is_local() {
171+
let tables = self.ecx.tcx.typeck_tables_of(def_id);
172+
if let Some(upvars) = tables.upvar_list.get(&def_id) {
173+
// Sometimes the index is beyond the number of freevars (seen
174+
// for a generator).
175+
if let Some(upvar_id) = upvars.get(field) {
176+
let var_hir_id = upvar_id.var_path.hir_id;
177+
let var_node_id = self.ecx.tcx.hir().hir_to_node_id(var_hir_id);
178+
if let hir::Node::Binding(pat) = self.ecx.tcx.hir().get(var_node_id) {
179+
if let hir::PatKind::Binding(_, _, ident, _) = pat.node {
180+
name = Some(ident.name);
181+
}
182+
}
183+
}
184+
}
174185
}
186+
187+
PathElem::ClosureVar(name.unwrap_or_else(|| {
188+
// Fall back to showing the field index.
189+
Symbol::intern(&field.to_string())
190+
}))
175191
}
176192

177193
// tuples

0 commit comments

Comments
 (0)