@@ -16,6 +16,7 @@ use rustc_hir::def::{self, CtorKind, CtorOf, DefKind};
1616use rustc_hir:: def_id:: { DefId , CRATE_DEF_INDEX , LOCAL_CRATE } ;
1717use rustc_hir:: PrimTy ;
1818use rustc_session:: parse:: feature_err;
19+ use rustc_span:: edition:: Edition ;
1920use rustc_span:: hygiene:: MacroKind ;
2021use rustc_span:: lev_distance:: find_best_match_for_name;
2122use rustc_span:: symbol:: { kw, sym, Ident , Symbol } ;
@@ -133,7 +134,7 @@ impl<'a: 'ast, 'ast> LateResolutionVisitor<'a, '_, 'ast> {
133134 let is_enum_variant = & |res| matches ! ( res, Res :: Def ( DefKind :: Variant , _) ) ;
134135
135136 // Make the base error.
136- let expected = source. descr_expected ( ) ;
137+ let mut expected = source. descr_expected ( ) ;
137138 let path_str = Segment :: names_to_string ( path) ;
138139 let item_str = path. last ( ) . unwrap ( ) . ident ;
139140 let ( base_msg, fallback_label, base_span, could_be_expr) = if let Some ( res) = res {
@@ -166,6 +167,15 @@ impl<'a: 'ast, 'ast> LateResolutionVisitor<'a, '_, 'ast> {
166167 let ( mod_prefix, mod_str) = if path. len ( ) == 1 {
167168 ( String :: new ( ) , "this scope" . to_string ( ) )
168169 } else if path. len ( ) == 2 && path[ 0 ] . ident . name == kw:: PathRoot {
170+ if self . r . session . edition ( ) > Edition :: Edition2015 {
171+ // In edition 2018 onwards, the `::foo` syntax may only pull from the extern prelude
172+ // which overrides all other expectations of item type
173+ expected = "crate" ;
174+ ( String :: new ( ) , "the list of imported crates" . to_string ( ) )
175+ } else {
176+ ( String :: new ( ) , "the crate root" . to_string ( ) )
177+ }
178+ } else if path. len ( ) == 2 && path[ 0 ] . ident . name == kw:: Crate {
169179 ( String :: new ( ) , "the crate root" . to_string ( ) )
170180 } else {
171181 let mod_path = & path[ ..path. len ( ) - 1 ] ;
0 commit comments