@@ -190,20 +190,18 @@ impl<'a, 'tcx> MarkSymbolVisitor<'a, 'tcx> {
190
190
self . inherited_pub_visibility = had_inherited_pub_visibility;
191
191
}
192
192
193
- fn mark_as_used_if_union ( & mut self , did : DefId ) {
193
+ fn mark_as_used_if_union ( & mut self , did : DefId , fields : & hir :: HirVec < hir :: Field > ) {
194
194
if let Some ( node_id) = self . tcx . hir . as_local_node_id ( did) {
195
- match self . tcx . hir . find ( node_id) {
196
- Some ( hir_map :: NodeItem ( item ) ) => match item. node {
197
- Item_ :: ItemUnion ( ref variant, _ ) => {
198
- if variant. fields ( ) . len ( ) > 1 {
199
- for field in variant . fields ( ) {
195
+ if let Some ( hir_map :: NodeItem ( item ) ) = self . tcx . hir . find ( node_id) {
196
+ if let Item_ :: ItemUnion ( ref variant , _ ) = item. node {
197
+ if variant. fields ( ) . len ( ) > 1 {
198
+ for field in variant. fields ( ) {
199
+ if fields . iter ( ) . find ( |x| x . name . node == field . name ) . is_some ( ) {
200
200
self . live_symbols . insert ( field. id ) ;
201
201
}
202
202
}
203
203
}
204
- _ => { }
205
- } ,
206
- _ => { }
204
+ }
207
205
}
208
206
}
209
207
}
@@ -239,11 +237,6 @@ impl<'a, 'tcx> Visitor<'tcx> for MarkSymbolVisitor<'a, 'tcx> {
239
237
hir:: ExprPath ( ref qpath @ hir:: QPath :: TypeRelative ( ..) ) => {
240
238
let def = self . tables . qpath_def ( qpath, expr. id ) ;
241
239
self . handle_definition ( def) ;
242
- self . mark_as_used_if_union ( def. def_id ( ) ) ;
243
- }
244
- hir:: ExprPath ( ref qpath @ hir:: QPath :: Resolved ( ..) ) => {
245
- let def = self . tables . qpath_def ( qpath, expr. id ) ;
246
- self . mark_as_used_if_union ( def. def_id ( ) ) ;
247
240
}
248
241
hir:: ExprMethodCall ( ..) => {
249
242
self . lookup_and_handle_method ( expr. id ) ;
@@ -254,6 +247,10 @@ impl<'a, 'tcx> Visitor<'tcx> for MarkSymbolVisitor<'a, 'tcx> {
254
247
hir:: ExprTupField ( ref lhs, idx) => {
255
248
self . handle_tup_field_access ( & lhs, idx. node ) ;
256
249
}
250
+ hir:: ExprStruct ( ref qpath, ref fields, _) => {
251
+ let def = self . tables . qpath_def ( qpath, expr. id ) ;
252
+ self . mark_as_used_if_union ( def. def_id ( ) , fields) ;
253
+ }
257
254
_ => ( )
258
255
}
259
256
0 commit comments