Skip to content

Commit ac7f9cc

Browse files
committed
diagnostics: Differentiate between edition meanings of ::foo in resolve diagnostics (for bare ::foo)
1 parent 66ec64c commit ac7f9cc

File tree

8 files changed

+72
-8
lines changed

8 files changed

+72
-8
lines changed

compiler/rustc_resolve/src/lib.rs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2450,10 +2450,16 @@ impl<'a> Resolver<'a> {
24502450
}
24512451
} else {
24522452
let parent = path[i - 1].ident.name;
2453-
let parent = if parent == kw::PathRoot {
2454-
"crate root".to_owned()
2455-
} else {
2456-
format!("`{}`", parent)
2453+
let parent = match parent {
2454+
// ::foo is mounted at the crate root for 2015, and is the extern
2455+
// prelude for 2018+
2456+
kw::PathRoot if self.session.edition() > Edition::Edition2015 => {
2457+
"the list of imported crates".to_owned()
2458+
}
2459+
kw::PathRoot | kw::Crate => "the crate root".to_owned(),
2460+
_ => {
2461+
format!("`{}`", parent)
2462+
}
24572463
};
24582464

24592465
let mut msg = format!("could not find `{}` in {}", ident, parent);
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// edition:2015
2+
3+
mod inner {
4+
fn global_inner(_: ::nonexistant::Foo) {
5+
//~^ ERROR failed to resolve: maybe a missing crate `nonexistant`?
6+
}
7+
fn crate_inner(_: crate::nonexistant::Foo) {
8+
//~^ ERROR failed to resolve: maybe a missing crate `nonexistant`?
9+
}
10+
}
11+
12+
fn main() {
13+
14+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
error[E0433]: failed to resolve: maybe a missing crate `nonexistant`?
2+
--> $DIR/editions-crate-root-2015.rs:4:26
3+
|
4+
LL | fn global_inner(_: ::nonexistant::Foo) {
5+
| ^^^^^^^^^^^ maybe a missing crate `nonexistant`?
6+
7+
error[E0433]: failed to resolve: maybe a missing crate `nonexistant`?
8+
--> $DIR/editions-crate-root-2015.rs:8:30
9+
|
10+
LL | fn crate_inner(_: crate::nonexistant::Foo) {
11+
| ^^^^^^^^^^^ maybe a missing crate `nonexistant`?
12+
13+
error: aborting due to 2 previous errors
14+
15+
For more information about this error, try `rustc --explain E0433`.
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// edition:2018
2+
3+
mod inner {
4+
fn global_inner(_: ::nonexistant::Foo) {
5+
//~^ ERROR failed to resolve: could not find `nonexistant` in the list of imported crates
6+
}
7+
fn crate_inner(_: crate::nonexistant::Foo) {
8+
//~^ ERROR failed to resolve: maybe a missing crate `nonexistant`?
9+
}
10+
}
11+
12+
fn main() {
13+
14+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
error[E0433]: failed to resolve: could not find `nonexistant` in the list of imported crates
2+
--> $DIR/editions-crate-root-2018.rs:4:26
3+
|
4+
LL | fn global_inner(_: ::nonexistant::Foo) {
5+
| ^^^^^^^^^^^ could not find `nonexistant` in the list of imported crates
6+
7+
error[E0433]: failed to resolve: maybe a missing crate `nonexistant`?
8+
--> $DIR/editions-crate-root-2018.rs:7:30
9+
|
10+
LL | fn crate_inner(_: crate::nonexistant::Foo) {
11+
| ^^^^^^^^^^^ maybe a missing crate `nonexistant`?
12+
13+
error: aborting due to 2 previous errors
14+
15+
For more information about this error, try `rustc --explain E0433`.

src/test/ui/editions/edition-imports-virtual-2015-gated.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ error[E0432]: unresolved import `E`
22
--> $DIR/edition-imports-virtual-2015-gated.rs:8:5
33
|
44
LL | gen_gated!();
5-
| ^^^^^^^^^^^^^ could not find `E` in crate root
5+
| ^^^^^^^^^^^^^ could not find `E` in the list of imported crates
66
|
77
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
88

src/test/ui/rfc-2126-extern-absolute-paths/non-existent-2.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@
22

33
fn main() {
44
let s = ::xcrate::S;
5-
//~^ ERROR failed to resolve: could not find `xcrate` in crate root
5+
//~^ ERROR failed to resolve: could not find `xcrate` in the list of imported crates
66
}

src/test/ui/rfc-2126-extern-absolute-paths/non-existent-2.stderr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
error[E0433]: failed to resolve: could not find `xcrate` in crate root
1+
error[E0433]: failed to resolve: could not find `xcrate` in the list of imported crates
22
--> $DIR/non-existent-2.rs:4:15
33
|
44
LL | let s = ::xcrate::S;
5-
| ^^^^^^ could not find `xcrate` in crate root
5+
| ^^^^^^ could not find `xcrate` in the list of imported crates
66

77
error: aborting due to previous error
88

0 commit comments

Comments
 (0)