Skip to content

Commit bbdeafc

Browse files
committed
clarify what the item is in "not a module" error
1 parent 3750348 commit bbdeafc

15 files changed

+70
-51
lines changed

src/librustc_resolve/lib.rs

+8-1
Original file line numberDiff line numberDiff line change
@@ -3731,9 +3731,16 @@ impl<'a> Resolver<'a> {
37313731
def, path.len() - i - 1
37323732
));
37333733
} else {
3734+
let label = format!(
3735+
"`{}` is {} {}, not a module",
3736+
ident,
3737+
def.article(),
3738+
def.kind_name(),
3739+
);
3740+
37343741
return PathResult::Failed {
37353742
span: ident.span,
3736-
label: format!("not a module `{}`", ident),
3743+
label,
37373744
suggestion: None,
37383745
is_error_from_last_segment: is_last,
37393746
};

src/test/ui/issues/issue-30560.rs

+3-6
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
11
type Alias = ();
2-
use Alias::*;
3-
//~^ ERROR unresolved import `Alias` [E0432]
4-
//~| not a module `Alias`
5-
use std::io::Result::*;
6-
//~^ ERROR unresolved import `std::io::Result` [E0432]
7-
//~| not a module `Result`
2+
use Alias::*; //~ ERROR unresolved import `Alias` [E0432]
3+
4+
use std::io::Result::*; //~ ERROR unresolved import `std::io::Result` [E0432]
85

96
trait T {}
107
use T::*; //~ ERROR items in traits are not importable

src/test/ui/issues/issue-30560.stderr

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error: items in traits are not importable.
2-
--> $DIR/issue-30560.rs:10:5
2+
--> $DIR/issue-30560.rs:7:5
33
|
44
LL | use T::*;
55
| ^^^^
@@ -8,13 +8,13 @@ error[E0432]: unresolved import `Alias`
88
--> $DIR/issue-30560.rs:2:5
99
|
1010
LL | use Alias::*;
11-
| ^^^^^ not a module `Alias`
11+
| ^^^^^ `Alias` is a type alias, not a module
1212

1313
error[E0432]: unresolved import `std::io::Result`
14-
--> $DIR/issue-30560.rs:5:14
14+
--> $DIR/issue-30560.rs:4:14
1515
|
1616
LL | use std::io::Result::*;
17-
| ^^^^^^ not a module `Result`
17+
| ^^^^^^ `Result` is a type alias, not a module
1818

1919
error: aborting due to 3 previous errors
2020

src/test/ui/macros/macro-path-prelude-fail-1.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22

33
mod m {
44
fn check() {
5-
Vec::clone!(); //~ ERROR failed to resolve: not a module `Vec`
6-
u8::clone!(); //~ ERROR failed to resolve: not a module `u8`
5+
Vec::clone!(); //~ ERROR failed to resolve: `Vec` is a struct, not a module
6+
u8::clone!(); //~ ERROR failed to resolve: `u8` is a builtin type, not a module
77
}
88
}
99

src/test/ui/macros/macro-path-prelude-fail-1.stderr

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
1-
error[E0433]: failed to resolve: not a module `Vec`
1+
error[E0433]: failed to resolve: `Vec` is a struct, not a module
22
--> $DIR/macro-path-prelude-fail-1.rs:5:9
33
|
44
LL | Vec::clone!();
5-
| ^^^ not a module `Vec`
5+
| ^^^ `Vec` is a struct, not a module
66

7-
error[E0433]: failed to resolve: not a module `u8`
7+
error[E0433]: failed to resolve: `u8` is a builtin type, not a module
88
--> $DIR/macro-path-prelude-fail-1.rs:6:9
99
|
1010
LL | u8::clone!();
11-
| ^^ not a module `u8`
11+
| ^^ `u8` is a builtin type, not a module
1212

1313
error: aborting due to 2 previous errors
1414

src/test/ui/resolve/resolve-variant-assoc-item.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@ enum E { V }
22
use E::V;
33

44
fn main() {
5-
E::V::associated_item; //~ ERROR failed to resolve: not a module `V`
6-
V::associated_item; //~ ERROR failed to resolve: not a module `V`
5+
E::V::associated_item; //~ ERROR failed to resolve: `V` is a variant, not a module
6+
V::associated_item; //~ ERROR failed to resolve: `V` is a variant, not a module
77
}

src/test/ui/resolve/resolve-variant-assoc-item.stderr

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
1-
error[E0433]: failed to resolve: not a module `V`
1+
error[E0433]: failed to resolve: `V` is a variant, not a module
22
--> $DIR/resolve-variant-assoc-item.rs:5:8
33
|
44
LL | E::V::associated_item;
5-
| ^ not a module `V`
5+
| ^ `V` is a variant, not a module
66

7-
error[E0433]: failed to resolve: not a module `V`
7+
error[E0433]: failed to resolve: `V` is a variant, not a module
88
--> $DIR/resolve-variant-assoc-item.rs:6:5
99
|
1010
LL | V::associated_item;
11-
| ^ not a module `V`
11+
| ^ `V` is a variant, not a module
1212

1313
error: aborting due to 2 previous errors
1414

src/test/ui/rust-2018/uniform-paths/prelude-fail.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ error[E0432]: unresolved import `rustfmt`
88
--> $DIR/prelude-fail.rs:7:5
99
|
1010
LL | use rustfmt::skip as imported_rustfmt_skip;
11-
| ^^^^^^^ not a module `rustfmt`
11+
| ^^^^^^^ `rustfmt` is a tool module, not a module
1212

1313
error: aborting due to 2 previous errors
1414

src/test/ui/ufcs/ufcs-partially-resolved.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,9 @@ fn main() {
4545
<u8 as E::N>::NN; //~ ERROR cannot find method or associated constant `NN` in `E::N`
4646
<u8 as A::N>::NN; //~ ERROR cannot find method or associated constant `NN` in `A::N`
4747
let _: <u8 as Tr::Y>::NN; //~ ERROR cannot find associated type `NN` in `Tr::Y`
48-
let _: <u8 as E::Y>::NN; //~ ERROR failed to resolve: not a module `Y`
48+
let _: <u8 as E::Y>::NN; //~ ERROR failed to resolve: `Y` is a variant, not a module
4949
<u8 as Tr::Y>::NN; //~ ERROR cannot find method or associated constant `NN` in `Tr::Y`
50-
<u8 as E::Y>::NN; //~ ERROR failed to resolve: not a module `Y`
50+
<u8 as E::Y>::NN; //~ ERROR failed to resolve: `Y` is a variant, not a module
5151

5252
let _: <u8 as Dr>::Z; //~ ERROR expected associated type, found method `Dr::Z`
5353
<u8 as Dr>::X; //~ ERROR expected method or associated constant, found associated type `Dr::X`

src/test/ui/ufcs/ufcs-partially-resolved.stderr

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
1-
error[E0433]: failed to resolve: not a module `Y`
1+
error[E0433]: failed to resolve: `Y` is a variant, not a module
22
--> $DIR/ufcs-partially-resolved.rs:48:22
33
|
44
LL | let _: <u8 as E::Y>::NN;
5-
| ^ not a module `Y`
5+
| ^ `Y` is a variant, not a module
66

7-
error[E0433]: failed to resolve: not a module `Y`
7+
error[E0433]: failed to resolve: `Y` is a variant, not a module
88
--> $DIR/ufcs-partially-resolved.rs:50:15
99
|
1010
LL | <u8 as E::Y>::NN;
11-
| ^ not a module `Y`
11+
| ^ `Y` is a variant, not a module
1212

1313
error[E0576]: cannot find associated type `N` in trait `Tr`
1414
--> $DIR/ufcs-partially-resolved.rs:19:24
+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#![allow(unused_imports)]
2+
3+
pub mod foo {
4+
pub struct Foo;
5+
6+
impl Foo {
7+
pub const BAR: i32 = 0;
8+
}
9+
}
10+
11+
use foo::Foo::BAR; //~ ERROR unresolved import `foo::Foo`
12+
13+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
error[E0432]: unresolved import `foo::Foo`
2+
--> $DIR/use-associated-const.rs:11:10
3+
|
4+
LL | use foo::Foo::BAR;
5+
| ^^^ `Foo` is a struct, not a module
6+
7+
error: aborting due to previous error
8+
9+
For more information about this error, try `rustc --explain E0432`.

src/test/ui/use/use-from-trait-xc.stderr

+3-3
Original file line numberDiff line numberDiff line change
@@ -20,19 +20,19 @@ error[E0432]: unresolved import `use_from_trait_xc::Foo`
2020
--> $DIR/use-from-trait-xc.rs:14:24
2121
|
2222
LL | use use_from_trait_xc::Foo::new;
23-
| ^^^ not a module `Foo`
23+
| ^^^ `Foo` is a struct, not a module
2424

2525
error[E0432]: unresolved import `use_from_trait_xc::Foo`
2626
--> $DIR/use-from-trait-xc.rs:17:24
2727
|
2828
LL | use use_from_trait_xc::Foo::C;
29-
| ^^^ not a module `Foo`
29+
| ^^^ `Foo` is a struct, not a module
3030

3131
error[E0432]: unresolved import `use_from_trait_xc::Bar`
3232
--> $DIR/use-from-trait-xc.rs:20:24
3333
|
3434
LL | use use_from_trait_xc::Bar::new as bnew;
35-
| ^^^ not a module `Bar`
35+
| ^^^ `Bar` is a struct, not a module
3636

3737
error[E0432]: unresolved import `use_from_trait_xc::Baz::new`
3838
--> $DIR/use-from-trait-xc.rs:23:5

src/test/ui/use/use-from-trait.rs

+5-12
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,10 @@
1-
use Trait::foo;
2-
//~^ ERROR `foo` is not directly importable
3-
use Trait::Assoc;
4-
//~^ ERROR `Assoc` is not directly importable
5-
use Trait::C;
6-
//~^ ERROR `C` is not directly importable
1+
use Trait::foo; //~ ERROR `foo` is not directly importable
2+
use Trait::Assoc; //~ ERROR `Assoc` is not directly importable
3+
use Trait::C; //~ ERROR `C` is not directly importable
74

8-
use Foo::new;
9-
//~^ ERROR unresolved import `Foo` [E0432]
10-
//~| not a module `Foo`
5+
use Foo::new; //~ ERROR unresolved import `Foo` [E0432]
116

12-
use Foo::C2;
13-
//~^ ERROR unresolved import `Foo` [E0432]
14-
//~| not a module `Foo`
7+
use Foo::C2; //~ ERROR unresolved import `Foo` [E0432]
158

169
pub trait Trait {
1710
fn foo();

src/test/ui/use/use-from-trait.stderr

+6-6
Original file line numberDiff line numberDiff line change
@@ -5,28 +5,28 @@ LL | use Trait::foo;
55
| ^^^^^^^^^^ cannot be imported directly
66

77
error[E0253]: `Assoc` is not directly importable
8-
--> $DIR/use-from-trait.rs:3:5
8+
--> $DIR/use-from-trait.rs:2:5
99
|
1010
LL | use Trait::Assoc;
1111
| ^^^^^^^^^^^^ cannot be imported directly
1212

1313
error[E0253]: `C` is not directly importable
14-
--> $DIR/use-from-trait.rs:5:5
14+
--> $DIR/use-from-trait.rs:3:5
1515
|
1616
LL | use Trait::C;
1717
| ^^^^^^^^ cannot be imported directly
1818

1919
error[E0432]: unresolved import `Foo`
20-
--> $DIR/use-from-trait.rs:8:5
20+
--> $DIR/use-from-trait.rs:5:5
2121
|
2222
LL | use Foo::new;
23-
| ^^^ not a module `Foo`
23+
| ^^^ `Foo` is a struct, not a module
2424

2525
error[E0432]: unresolved import `Foo`
26-
--> $DIR/use-from-trait.rs:12:5
26+
--> $DIR/use-from-trait.rs:7:5
2727
|
2828
LL | use Foo::C2;
29-
| ^^^ not a module `Foo`
29+
| ^^^ `Foo` is a struct, not a module
3030

3131
error: aborting due to 5 previous errors
3232

0 commit comments

Comments
 (0)