@@ -231,7 +231,10 @@ impl<'tcx> MarkSymbolVisitor<'tcx> {
231
231
pats : & [ hir:: PatField < ' _ > ] ,
232
232
) {
233
233
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
+ }
235
238
_ => span_bug ! ( lhs. span, "non-ADT in struct pattern" ) ,
236
239
} ;
237
240
for pat in pats {
@@ -251,7 +254,10 @@ impl<'tcx> MarkSymbolVisitor<'tcx> {
251
254
dotdot : hir:: DotDotPos ,
252
255
) {
253
256
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
+ }
255
261
_ => {
256
262
self . tcx . dcx ( ) . span_delayed_bug ( lhs. span , "non-ADT in tuple struct pattern" ) ;
257
263
return ;
@@ -356,31 +362,6 @@ impl<'tcx> MarkSymbolVisitor<'tcx> {
356
362
return false ;
357
363
}
358
364
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
-
384
365
if let Some ( trait_of) = self . tcx . trait_id_of_impl ( impl_of)
385
366
&& self . tcx . has_attr ( trait_of, sym:: rustc_trivial_field_reads)
386
367
{
@@ -622,6 +603,10 @@ impl<'tcx> Visitor<'tcx> for MarkSymbolVisitor<'tcx> {
622
603
fn visit_pat_expr ( & mut self , expr : & ' tcx rustc_hir:: PatExpr < ' tcx > ) {
623
604
match & expr. kind {
624
605
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
+ }
625
610
let res = self . typeck_results ( ) . qpath_res ( qpath, expr. hir_id ) ;
626
611
self . handle_res ( res) ;
627
612
}
0 commit comments