@@ -3,6 +3,7 @@ use std::hash::Hash;
3
3
use std:: ops:: RangeInclusive ;
4
4
5
5
use syntax_pos:: symbol:: Symbol ;
6
+ use rustc:: hir;
6
7
use rustc:: ty:: layout:: { self , Size , Align , TyLayout , LayoutOf , VariantIdx } ;
7
8
use rustc:: ty;
8
9
use rustc_data_structures:: fx:: FxHashSet ;
@@ -165,13 +166,28 @@ impl<'rt, 'a, 'mir, 'tcx, M: Machine<'a, 'mir, 'tcx>> ValidityVisitor<'rt, 'a, '
165
166
match layout. ty . sty {
166
167
// generators and closures.
167
168
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
+ }
174
185
}
186
+
187
+ PathElem :: ClosureVar ( name. unwrap_or_else ( || {
188
+ // Fall back to showing the field index.
189
+ Symbol :: intern ( & field. to_string ( ) )
190
+ } ) )
175
191
}
176
192
177
193
// tuples
0 commit comments