@@ -5,6 +5,7 @@ use Namespace::*;
55use rustc_ast:: { self as ast, NodeId } ;
66use rustc_errors:: ErrorGuaranteed ;
77use rustc_hir:: def:: { DefKind , MacroKinds , Namespace , NonMacroAttrKind , PartialRes , PerNS } ;
8+ use rustc_middle:: ty:: Visibility ;
89use rustc_middle:: { bug, span_bug} ;
910use rustc_session:: lint:: builtin:: PROC_MACRO_DERIVE_RESOLUTION_FALLBACK ;
1011use rustc_session:: parse:: feature_err;
@@ -485,9 +486,12 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
485486 // We do not need to report them if we are either in speculative resolution,
486487 // or in late resolution when everything is already imported and expanded
487488 // and no ambiguities exist.
488- if matches ! ( finalize, None | Some ( Finalize { stage: Stage :: Late , .. } ) ) {
489- return ControlFlow :: Break ( Ok ( decl) ) ;
490- }
489+ let import_vis = match finalize {
490+ None | Some ( Finalize { stage : Stage :: Late , .. } ) => {
491+ return ControlFlow :: Break ( Ok ( decl) ) ;
492+ }
493+ Some ( Finalize { import_vis, .. } ) => import_vis,
494+ } ;
491495
492496 if let Some ( & ( innermost_decl, _) ) = innermost_results. first ( ) {
493497 // Found another solution, if the first one was "weak", report an error.
@@ -500,6 +504,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
500504 decl,
501505 scope,
502506 & innermost_results,
507+ import_vis,
503508 ) {
504509 // No need to search for more potential ambiguities, one is enough.
505510 return ControlFlow :: Break ( Ok ( innermost_decl) ) ;
@@ -779,12 +784,22 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
779784 decl : Decl < ' ra > ,
780785 scope : Scope < ' ra > ,
781786 innermost_results : & [ ( Decl < ' ra > , Scope < ' ra > ) ] ,
787+ import_vis : Option < Visibility > ,
782788 ) -> bool {
783789 let ( innermost_decl, innermost_scope) = innermost_results[ 0 ] ;
784790 let ( res, innermost_res) = ( decl. res ( ) , innermost_decl. res ( ) ) ;
785- if res == innermost_res {
791+ let ambig_vis = if res != innermost_res {
792+ None
793+ } else if let Some ( import_vis) = import_vis
794+ && let min =
795+ ( |d : Decl < ' _ > | d. vis ( ) . min ( import_vis. to_def_id ( ) , self . tcx ) . expect_local ( ) )
796+ && let ( min1, min2) = ( min ( decl) , min ( innermost_decl) )
797+ && min1 != min2
798+ {
799+ Some ( ( min1, min2) )
800+ } else {
786801 return false ;
787- }
802+ } ;
788803
789804 // FIXME: Use `scope` instead of `res` to detect built-in attrs and derive helpers,
790805 // it will exclude imports, make slightly more code legal, and will require lang approval.
@@ -871,10 +886,17 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
871886 || ( self . is_specific_builtin_macro ( res, sym:: core_panic)
872887 && self . is_specific_builtin_macro ( innermost_res, sym:: std_panic) ) ) ;
873888
874- let warning = is_issue_147319_hack. then_some ( AmbiguityWarning :: PanicImport ) ;
889+ let warning = if ambig_vis. is_some ( ) {
890+ Some ( AmbiguityWarning :: GlobImport )
891+ } else if is_issue_147319_hack {
892+ Some ( AmbiguityWarning :: PanicImport )
893+ } else {
894+ None
895+ } ;
875896
876897 self . ambiguity_errors . push ( AmbiguityError {
877898 kind,
899+ ambig_vis,
878900 ident : ident. orig ( orig_ident_span) ,
879901 b1 : innermost_decl,
880902 b2 : decl,
0 commit comments