diagnostics: Differentiate between edition meanings of ::foo in resolve diagnostics (for bare ::foo
)
This commit is contained in:
parent
66ec64ccf3
commit
ac7f9ccb6f
|
@ -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);
|
||||
|
|
14
src/test/ui/editions-crate-root-2015.rs
Normal file
14
src/test/ui/editions-crate-root-2015.rs
Normal 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() {
|
||||
|
||||
}
|
15
src/test/ui/editions-crate-root-2015.stderr
Normal file
15
src/test/ui/editions-crate-root-2015.stderr
Normal 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`.
|
14
src/test/ui/editions-crate-root-2018.rs
Normal file
14
src/test/ui/editions-crate-root-2018.rs
Normal 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() {
|
||||
|
||||
}
|
15
src/test/ui/editions-crate-root-2018.stderr
Normal file
15
src/test/ui/editions-crate-root-2018.stderr
Normal 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`.
|
|
@ -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)
|
||||
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
Loading…
Reference in a new issue