@@ -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,28 @@ 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 res = path. res ;
744+
745+ // A use item can import something from two namespaces at the same time.
746+ // For deprecation/stability we don't want to warn twice.
747+ // This specifically happens with constructors for unit/tuple structs.
748+ if let Some ( ty_ns_res) = res. type_ns
749+ && let Some ( value_ns_res) = res. value_ns
750+ && let Some ( type_ns_did) = ty_ns_res. opt_def_id ( )
751+ && let Some ( value_ns_did) = value_ns_res. opt_def_id ( )
752+ && let DefKind :: Ctor ( CtorOf :: Struct , _) = self . tcx . def_kind ( value_ns_did)
753+ && self . tcx . parent ( value_ns_did) == type_ns_did
754+ {
755+ // only visit the value namespace path when we've detected a duplicate
756+ let UsePath { segments, res : _, span } = * path;
757+ self . visit_path ( & Path { segments, res : value_ns_res, span } , hir_id) ;
758+ } else {
759+ // if there's no duplicate, just walk as normal
760+ intravisit:: walk_use ( self , path, hir_id)
761+ }
762+ }
763+
742764 fn visit_path ( & mut self , path : & hir:: Path < ' tcx > , id : hir:: HirId ) {
743765 if let Some ( def_id) = path. res . opt_def_id ( ) {
744766 let method_span = path. segments . last ( ) . map ( |s| s. ident . span ) ;
0 commit comments