@@ -8,12 +8,12 @@ use rustc_data_structures::fx::FxIndexMap;
88use rustc_data_structures:: unord:: { ExtendUnord , UnordMap , UnordSet } ;
99use rustc_feature:: { EnabledLangFeature , EnabledLibFeature } ;
1010use rustc_hir:: attrs:: { AttributeKind , DeprecatedSince } ;
11- use rustc_hir:: def:: { DefKind , Res } ;
11+ use rustc_hir:: def:: { CtorOf , DefKind , Res } ;
1212use rustc_hir:: def_id:: { CRATE_DEF_ID , LOCAL_CRATE , LocalDefId , LocalModDefId } ;
1313use rustc_hir:: intravisit:: { self , Visitor , VisitorExt } ;
1414use rustc_hir:: {
15- self as hir, AmbigArg , ConstStability , DefaultBodyStability , FieldDef , Item , ItemKind ,
16- Stability , StabilityLevel , StableSince , TraitRef , Ty , TyKind , UnstableReason ,
15+ self as hir, AmbigArg , ConstStability , DefaultBodyStability , FieldDef , HirId , Item , ItemKind ,
16+ Path , Stability , StabilityLevel , StableSince , TraitRef , Ty , TyKind , UnstableReason , UsePath ,
1717 VERSION_PLACEHOLDER , Variant , find_attr,
1818} ;
1919use rustc_middle:: hir:: nested_filter;
@@ -739,6 +739,35 @@ impl<'tcx> Visitor<'tcx> for Checker<'tcx> {
739739 intravisit:: walk_poly_trait_ref ( self , t) ;
740740 }
741741
742+ fn visit_use ( & mut self , path : & ' tcx UsePath < ' tcx > , hir_id : HirId ) {
743+ let UsePath { segments, ref res, span } = * path;
744+
745+ // the first resolution of a path, to deduplicate
746+ let mut first_resolution = None ;
747+
748+ for res in res. present_items ( ) {
749+ // A use item can import something from two namespaces at the same time.
750+ // For deprecation/stability we don't want to warn twice.
751+ // This specifically happens with constructors for unit/tuple structs.
752+ if let Some ( did) = res. opt_def_id ( ) {
753+ // If it's a ctor, we need the parent did.
754+ // The parent defid of a constructor is that of the struct it constructs.
755+ let did = match self . tcx . def_kind ( did) {
756+ DefKind :: Ctor ( CtorOf :: Struct , _) => self . tcx . parent ( did) ,
757+ _ => did,
758+ } ;
759+
760+ // When we've already seen a defid, don't walk this path.
761+ // This avoids the duplicate deprecation warnings.
762+ if first_resolution. replace ( did) . is_some_and ( |first| first == did) {
763+ continue ;
764+ }
765+ }
766+
767+ self . visit_path ( & Path { segments, res, span } , hir_id) ;
768+ }
769+ }
770+
742771 fn visit_path ( & mut self , path : & hir:: Path < ' tcx > , id : hir:: HirId ) {
743772 if let Some ( def_id) = path. res . opt_def_id ( ) {
744773 let method_span = path. segments . last ( ) . map ( |s| s. ident . span ) ;
0 commit comments