@@ -190,20 +190,18 @@ impl<'a, 'tcx> MarkSymbolVisitor<'a, 'tcx> {
190190 self . inherited_pub_visibility = had_inherited_pub_visibility;
191191 }
192192
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 > ) {
194194 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 ( ) {
200200 self . live_symbols . insert ( field. id ) ;
201201 }
202202 }
203203 }
204- _ => { }
205- } ,
206- _ => { }
204+ }
207205 }
208206 }
209207 }
@@ -239,11 +237,6 @@ impl<'a, 'tcx> Visitor<'tcx> for MarkSymbolVisitor<'a, 'tcx> {
239237 hir:: ExprPath ( ref qpath @ hir:: QPath :: TypeRelative ( ..) ) => {
240238 let def = self . tables . qpath_def ( qpath, expr. id ) ;
241239 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 ( ) ) ;
247240 }
248241 hir:: ExprMethodCall ( ..) => {
249242 self . lookup_and_handle_method ( expr. id ) ;
@@ -254,6 +247,10 @@ impl<'a, 'tcx> Visitor<'tcx> for MarkSymbolVisitor<'a, 'tcx> {
254247 hir:: ExprTupField ( ref lhs, idx) => {
255248 self . handle_tup_field_access ( & lhs, idx. node ) ;
256249 }
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+ }
257254 _ => ( )
258255 }
259256
0 commit comments