@@ -16,6 +16,7 @@ use rustc_hir::def::{self, CtorKind, CtorOf, DefKind};
16
16
use rustc_hir:: def_id:: { DefId , CRATE_DEF_INDEX , LOCAL_CRATE } ;
17
17
use rustc_hir:: PrimTy ;
18
18
use rustc_session:: parse:: feature_err;
19
+ use rustc_span:: edition:: Edition ;
19
20
use rustc_span:: hygiene:: MacroKind ;
20
21
use rustc_span:: lev_distance:: find_best_match_for_name;
21
22
use rustc_span:: symbol:: { kw, sym, Ident , Symbol } ;
@@ -133,7 +134,7 @@ impl<'a: 'ast, 'ast> LateResolutionVisitor<'a, '_, 'ast> {
133
134
let is_enum_variant = & |res| matches ! ( res, Res :: Def ( DefKind :: Variant , _) ) ;
134
135
135
136
// Make the base error.
136
- let expected = source. descr_expected ( ) ;
137
+ let mut expected = source. descr_expected ( ) ;
137
138
let path_str = Segment :: names_to_string ( path) ;
138
139
let item_str = path. last ( ) . unwrap ( ) . ident ;
139
140
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> {
166
167
let ( mod_prefix, mod_str) = if path. len ( ) == 1 {
167
168
( String :: new ( ) , "this scope" . to_string ( ) )
168
169
} 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 {
169
179
( String :: new ( ) , "the crate root" . to_string ( ) )
170
180
} else {
171
181
let mod_path = & path[ ..path. len ( ) - 1 ] ;
0 commit comments