@@ -231,7 +231,10 @@ impl<'tcx> MarkSymbolVisitor<'tcx> {
231231 pats : & [ hir:: PatField < ' _ > ] ,
232232 ) {
233233 let variant = match self . typeck_results ( ) . node_type ( lhs. hir_id ) . kind ( ) {
234- ty:: Adt ( adt, _) => adt. variant_of_res ( res) ,
234+ ty:: Adt ( adt, _) => {
235+ self . check_def_id ( adt. did ( ) ) ;
236+ adt. variant_of_res ( res)
237+ }
235238 _ => span_bug ! ( lhs. span, "non-ADT in struct pattern" ) ,
236239 } ;
237240 for pat in pats {
@@ -251,7 +254,10 @@ impl<'tcx> MarkSymbolVisitor<'tcx> {
251254 dotdot : hir:: DotDotPos ,
252255 ) {
253256 let variant = match self . typeck_results ( ) . node_type ( lhs. hir_id ) . kind ( ) {
254- ty:: Adt ( adt, _) => adt. variant_of_res ( res) ,
257+ ty:: Adt ( adt, _) => {
258+ self . check_def_id ( adt. did ( ) ) ;
259+ adt. variant_of_res ( res)
260+ }
255261 _ => {
256262 self . tcx . dcx ( ) . span_delayed_bug ( lhs. span , "non-ADT in tuple struct pattern" ) ;
257263 return ;
@@ -356,31 +362,6 @@ impl<'tcx> MarkSymbolVisitor<'tcx> {
356362 return false ;
357363 }
358364
359- // don't ignore impls for Enums and pub Structs whose methods don't have self receiver,
360- // cause external crate may call such methods to construct values of these types
361- if let Some ( local_impl_of) = impl_of. as_local ( )
362- && let Some ( local_def_id) = def_id. as_local ( )
363- && let Some ( fn_sig) =
364- self . tcx . hir_fn_sig_by_hir_id ( self . tcx . local_def_id_to_hir_id ( local_def_id) )
365- && matches ! ( fn_sig. decl. implicit_self, hir:: ImplicitSelfKind :: None )
366- && let TyKind :: Path ( hir:: QPath :: Resolved ( _, path) ) =
367- self . tcx . hir_expect_item ( local_impl_of) . expect_impl ( ) . self_ty . kind
368- && let Res :: Def ( def_kind, did) = path. res
369- {
370- match def_kind {
371- // for example, #[derive(Default)] pub struct T(i32);
372- // external crate can call T::default() to construct T,
373- // so that don't ignore impl Default for pub Enum and Structs
374- DefKind :: Struct | DefKind :: Union if self . tcx . visibility ( did) . is_public ( ) => {
375- return false ;
376- }
377- // don't ignore impl Default for Enums,
378- // cause we don't know which variant is constructed
379- DefKind :: Enum => return false ,
380- _ => ( ) ,
381- } ;
382- }
383-
384365 if let Some ( trait_of) = self . tcx . trait_id_of_impl ( impl_of)
385366 && self . tcx . has_attr ( trait_of, sym:: rustc_trivial_field_reads)
386367 {
@@ -622,6 +603,10 @@ impl<'tcx> Visitor<'tcx> for MarkSymbolVisitor<'tcx> {
622603 fn visit_pat_expr ( & mut self , expr : & ' tcx rustc_hir:: PatExpr < ' tcx > ) {
623604 match & expr. kind {
624605 rustc_hir:: PatExprKind :: Path ( qpath) => {
606+ // mark the type of variant live when meeting E::V in expr
607+ if let ty:: Adt ( adt, _) = self . typeck_results ( ) . node_type ( expr. hir_id ) . kind ( ) {
608+ self . check_def_id ( adt. did ( ) ) ;
609+ }
625610 let res = self . typeck_results ( ) . qpath_res ( qpath, expr. hir_id ) ;
626611 self . handle_res ( res) ;
627612 }
0 commit comments