@@ -1996,22 +1996,27 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
19961996
19971997 fn ambiguity_diagnostic ( & self , ambiguity_error : & AmbiguityError < ' ra > ) -> errors:: Ambiguity {
19981998 let AmbiguityError { kind, ident, b1, b2, scope1, scope2, .. } = * ambiguity_error;
1999- let extern_prelude_ambiguity = || {
2000- // Note: b1 may come from a module scope, as an extern crate item in module.
2001- matches ! ( scope2, Scope :: ExternPreludeFlags )
2002- && self
2003- . extern_prelude
2004- . get ( & Macros20NormalizedIdent :: new ( ident) )
2005- . is_some_and ( |entry| entry. item_decl . map ( |( b, _) | b) == Some ( b1) )
1999+ let extern_prelude_flag = |scope| matches ! ( scope, Scope :: ExternPreludeFlags ) ;
2000+ let extern_prelude_item = |scope, decl| {
2001+ // Declaration comes from extern prelude item scope,
2002+ matches ! ( scope, Scope :: ExternPreludeItems )
2003+ // or from a module scope, as an extern crate item in the root module.
2004+ || matches ! ( scope, Scope :: ModuleNonGlobs ( ..) )
2005+ && self
2006+ . extern_prelude
2007+ . get ( & Macros20NormalizedIdent :: new ( ident) )
2008+ . is_some_and ( |entry| entry. item_decl . map ( |( d, _) | d) == Some ( decl) )
20062009 } ;
2010+ let extern_prelude_ambiguity =
2011+ extern_prelude_flag ( scope2) && extern_prelude_item ( scope1, b1) ;
20072012 let ( b1, b2, scope1, scope2, swapped) = if b2. span . is_dummy ( ) && !b1. span . is_dummy ( ) {
20082013 // We have to print the span-less alternative first, otherwise formatting looks bad.
20092014 ( b2, b1, scope2, scope1, true )
20102015 } else {
20112016 ( b1, b2, scope1, scope2, false )
20122017 } ;
20132018
2014- let could_refer_to = |b : Decl < ' _ > , scope : Scope < ' ra > , also : & str | {
2019+ let could_refer_to = |b : Decl < ' ra > , scope : Scope < ' ra > , also : & str | {
20152020 let what = self . decl_description ( b, ident, scope) ;
20162021 let note_msg = format ! ( "`{ident}` could{also} refer to {what}" ) ;
20172022
@@ -2026,7 +2031,9 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
20262031 "consider adding an explicit import of `{ident}` to disambiguate"
20272032 ) )
20282033 }
2029- if b. is_extern_crate ( ) && ident. span . at_least_rust_2018 ( ) && !extern_prelude_ambiguity ( )
2034+
2035+ if !extern_prelude_ambiguity
2036+ && ( extern_prelude_flag ( scope) || extern_prelude_item ( scope, b) )
20302037 {
20312038 help_msgs. push ( format ! ( "use `::{ident}` to refer to this {thing} unambiguously" ) )
20322039 }
0 commit comments