diff --git a/compiler/rustc_resolve/src/lib.rs b/compiler/rustc_resolve/src/lib.rs index 7aee718bfa9..11b0ade1e83 100644 --- a/compiler/rustc_resolve/src/lib.rs +++ b/compiler/rustc_resolve/src/lib.rs @@ -2450,10 +2450,16 @@ impl<'a> Resolver<'a> { } } else { let parent = path[i - 1].ident.name; - let parent = if parent == kw::PathRoot { - "crate root".to_owned() - } else { - format!("`{}`", parent) + let parent = match parent { + // ::foo is mounted at the crate root for 2015, and is the extern + // prelude for 2018+ + kw::PathRoot if self.session.edition() > Edition::Edition2015 => { + "the list of imported crates".to_owned() + } + kw::PathRoot | kw::Crate => "the crate root".to_owned(), + _ => { + format!("`{}`", parent) + } }; let mut msg = format!("could not find `{}` in {}", ident, parent); diff --git a/src/test/ui/editions-crate-root-2015.rs b/src/test/ui/editions-crate-root-2015.rs new file mode 100644 index 00000000000..71b7112804d --- /dev/null +++ b/src/test/ui/editions-crate-root-2015.rs @@ -0,0 +1,14 @@ +// edition:2015 + +mod inner { + fn global_inner(_: ::nonexistant::Foo) { + //~^ ERROR failed to resolve: maybe a missing crate `nonexistant`? + } + fn crate_inner(_: crate::nonexistant::Foo) { + //~^ ERROR failed to resolve: maybe a missing crate `nonexistant`? + } +} + +fn main() { + +} \ No newline at end of file diff --git a/src/test/ui/editions-crate-root-2015.stderr b/src/test/ui/editions-crate-root-2015.stderr new file mode 100644 index 00000000000..94c972227d0 --- /dev/null +++ b/src/test/ui/editions-crate-root-2015.stderr @@ -0,0 +1,15 @@ +error[E0433]: failed to resolve: maybe a missing crate `nonexistant`? + --> $DIR/editions-crate-root-2015.rs:4:26 + | +LL | fn global_inner(_: ::nonexistant::Foo) { + | ^^^^^^^^^^^ maybe a missing crate `nonexistant`? + +error[E0433]: failed to resolve: maybe a missing crate `nonexistant`? + --> $DIR/editions-crate-root-2015.rs:8:30 + | +LL | fn crate_inner(_: crate::nonexistant::Foo) { + | ^^^^^^^^^^^ maybe a missing crate `nonexistant`? + +error: aborting due to 2 previous errors + +For more information about this error, try `rustc --explain E0433`. diff --git a/src/test/ui/editions-crate-root-2018.rs b/src/test/ui/editions-crate-root-2018.rs new file mode 100644 index 00000000000..7e65f00920e --- /dev/null +++ b/src/test/ui/editions-crate-root-2018.rs @@ -0,0 +1,14 @@ +// edition:2018 + +mod inner { + fn global_inner(_: ::nonexistant::Foo) { + //~^ ERROR failed to resolve: could not find `nonexistant` in the list of imported crates + } + fn crate_inner(_: crate::nonexistant::Foo) { + //~^ ERROR failed to resolve: maybe a missing crate `nonexistant`? + } +} + +fn main() { + +} \ No newline at end of file diff --git a/src/test/ui/editions-crate-root-2018.stderr b/src/test/ui/editions-crate-root-2018.stderr new file mode 100644 index 00000000000..95a36907448 --- /dev/null +++ b/src/test/ui/editions-crate-root-2018.stderr @@ -0,0 +1,15 @@ +error[E0433]: failed to resolve: could not find `nonexistant` in the list of imported crates + --> $DIR/editions-crate-root-2018.rs:4:26 + | +LL | fn global_inner(_: ::nonexistant::Foo) { + | ^^^^^^^^^^^ could not find `nonexistant` in the list of imported crates + +error[E0433]: failed to resolve: maybe a missing crate `nonexistant`? + --> $DIR/editions-crate-root-2018.rs:7:30 + | +LL | fn crate_inner(_: crate::nonexistant::Foo) { + | ^^^^^^^^^^^ maybe a missing crate `nonexistant`? + +error: aborting due to 2 previous errors + +For more information about this error, try `rustc --explain E0433`. diff --git a/src/test/ui/editions/edition-imports-virtual-2015-gated.stderr b/src/test/ui/editions/edition-imports-virtual-2015-gated.stderr index 06605c6f208..1cde0f72140 100644 --- a/src/test/ui/editions/edition-imports-virtual-2015-gated.stderr +++ b/src/test/ui/editions/edition-imports-virtual-2015-gated.stderr @@ -2,7 +2,7 @@ error[E0432]: unresolved import `E` --> $DIR/edition-imports-virtual-2015-gated.rs:8:5 | LL | gen_gated!(); - | ^^^^^^^^^^^^^ could not find `E` in crate root + | ^^^^^^^^^^^^^ could not find `E` in the list of imported crates | = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/src/test/ui/rfc-2126-extern-absolute-paths/non-existent-2.rs b/src/test/ui/rfc-2126-extern-absolute-paths/non-existent-2.rs index 61212f299be..def60feb5a6 100644 --- a/src/test/ui/rfc-2126-extern-absolute-paths/non-existent-2.rs +++ b/src/test/ui/rfc-2126-extern-absolute-paths/non-existent-2.rs @@ -2,5 +2,5 @@ fn main() { let s = ::xcrate::S; - //~^ ERROR failed to resolve: could not find `xcrate` in crate root + //~^ ERROR failed to resolve: could not find `xcrate` in the list of imported crates } diff --git a/src/test/ui/rfc-2126-extern-absolute-paths/non-existent-2.stderr b/src/test/ui/rfc-2126-extern-absolute-paths/non-existent-2.stderr index 8b2a6933f37..7df4f06d1c7 100644 --- a/src/test/ui/rfc-2126-extern-absolute-paths/non-existent-2.stderr +++ b/src/test/ui/rfc-2126-extern-absolute-paths/non-existent-2.stderr @@ -1,8 +1,8 @@ -error[E0433]: failed to resolve: could not find `xcrate` in crate root +error[E0433]: failed to resolve: could not find `xcrate` in the list of imported crates --> $DIR/non-existent-2.rs:4:15 | LL | let s = ::xcrate::S; - | ^^^^^^ could not find `xcrate` in crate root + | ^^^^^^ could not find `xcrate` in the list of imported crates error: aborting due to previous error