1
Fork 0

diagnostics: Differentiate between edition meanings of ::foo in resolve diagnostics (for bare ::foo)

This commit is contained in:
Manish Goregaokar 2021-03-07 13:53:45 -08:00
parent 66ec64ccf3
commit ac7f9ccb6f
8 changed files with 72 additions and 8 deletions

View file

@ -2450,10 +2450,16 @@ impl<'a> Resolver<'a> {
} }
} else { } else {
let parent = path[i - 1].ident.name; let parent = path[i - 1].ident.name;
let parent = if parent == kw::PathRoot { let parent = match parent {
"crate root".to_owned() // ::foo is mounted at the crate root for 2015, and is the extern
} else { // 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) format!("`{}`", parent)
}
}; };
let mut msg = format!("could not find `{}` in {}", ident, parent); let mut msg = format!("could not find `{}` in {}", ident, parent);

View file

@ -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() {
}

View file

@ -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`.

View file

@ -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() {
}

View file

@ -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`.

View file

@ -2,7 +2,7 @@ error[E0432]: unresolved import `E`
--> $DIR/edition-imports-virtual-2015-gated.rs:8:5 --> $DIR/edition-imports-virtual-2015-gated.rs:8:5
| |
LL | gen_gated!(); 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) = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)

View file

@ -2,5 +2,5 @@
fn main() { fn main() {
let s = ::xcrate::S; 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
} }

View file

@ -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 --> $DIR/non-existent-2.rs:4:15
| |
LL | let s = ::xcrate::S; 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 error: aborting due to previous error