@@ -156,7 +156,12 @@ impl<'tcx> MarkSymbolVisitor<'tcx> {
156
156
fn handle_res ( & mut self , res : Res ) {
157
157
match res {
158
158
Res :: Def (
159
- DefKind :: Const | DefKind :: AssocConst | DefKind :: AssocTy | DefKind :: TyAlias ,
159
+ DefKind :: Struct
160
+ | DefKind :: Enum
161
+ | DefKind :: Const
162
+ | DefKind :: AssocConst
163
+ | DefKind :: AssocTy
164
+ | DefKind :: TyAlias ,
160
165
def_id,
161
166
) => {
162
167
self . check_def_id ( def_id) ;
@@ -402,31 +407,6 @@ impl<'tcx> MarkSymbolVisitor<'tcx> {
402
407
return false ;
403
408
}
404
409
405
- // don't ignore impls for Enums and pub Structs whose methods don't have self receiver,
406
- // cause external crate may call such methods to construct values of these types
407
- if let Some ( local_impl_of) = impl_of. as_local ( )
408
- && let Some ( local_def_id) = def_id. as_local ( )
409
- && let Some ( fn_sig) =
410
- self . tcx . hir ( ) . fn_sig_by_hir_id ( self . tcx . local_def_id_to_hir_id ( local_def_id) )
411
- && matches ! ( fn_sig. decl. implicit_self, hir:: ImplicitSelfKind :: None )
412
- && let TyKind :: Path ( hir:: QPath :: Resolved ( _, path) ) =
413
- self . tcx . hir ( ) . expect_item ( local_impl_of) . expect_impl ( ) . self_ty . kind
414
- && let Res :: Def ( def_kind, did) = path. res
415
- {
416
- match def_kind {
417
- // for example, #[derive(Default)] pub struct T(i32);
418
- // external crate can call T::default() to construct T,
419
- // so that don't ignore impl Default for pub Enum and Structs
420
- DefKind :: Struct | DefKind :: Union if self . tcx . visibility ( did) . is_public ( ) => {
421
- return false ;
422
- }
423
- // don't ignore impl Default for Enums,
424
- // cause we don't know which variant is constructed
425
- DefKind :: Enum => return false ,
426
- _ => ( ) ,
427
- } ;
428
- }
429
-
430
410
if let Some ( trait_of) = self . tcx . trait_id_of_impl ( impl_of)
431
411
&& self . tcx . has_attr ( trait_of, sym:: rustc_trivial_field_reads)
432
412
{
@@ -687,6 +667,7 @@ impl<'tcx> Visitor<'tcx> for MarkSymbolVisitor<'tcx> {
687
667
match pat. kind {
688
668
PatKind :: Struct ( ref path, fields, _) => {
689
669
let res = self . typeck_results ( ) . qpath_res ( path, pat. hir_id ) ;
670
+ self . handle_res ( res) ;
690
671
self . handle_field_pattern_match ( pat, res, fields) ;
691
672
}
692
673
PatKind :: Path ( ref qpath) => {
@@ -845,7 +826,7 @@ fn check_item<'tcx>(
845
826
// mark the method live if the self_ty is public,
846
827
// or the method is public and may construct self
847
828
if tcx. visibility ( local_def_id) . is_public ( )
848
- && ( ty_and_all_fields_are_public || may_construct_self)
829
+ && ( ty_and_all_fields_are_public || ( ty_is_public && may_construct_self) )
849
830
{
850
831
// if the impl item is public,
851
832
// and the ty may be constructed or can be constructed in foreign crates,
0 commit comments