Skip to content

Commit b366415

Browse files
committed
Add a couple more tests + address review comments
1 parent 10ac957 commit b366415

14 files changed

+161
-5
lines changed

src/librustc_resolve/resolve_imports.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,7 @@ impl<'a, 'crateloader> Resolver<'a, 'crateloader> {
192192
ident.name == keywords::SelfValue.name() {
193193
// FIXME: Implement these with renaming requirements so that e.g.
194194
// `use super;` doesn't work, but `use super as name;` does.
195+
// Fall through here to get an error from `early_resolve_...`.
195196
}
196197
}
197198

@@ -938,7 +939,12 @@ impl<'a, 'b:'a, 'c: 'b> ImportResolver<'a, 'b, 'c> {
938939
}
939940
}
940941
Err(..) => {
941-
assert!(result[ns].get().is_err());
942+
// FIXME: This assert may fire if public glob is later shadowed by a private
943+
// single import (see test `issue-55884-2.rs`). In theory single imports should
944+
// always block globs, even if they are not yet resolved, so that this kind of
945+
// self-inconsistent resolution never happens.
946+
// Reenable the assert when the issue is fixed.
947+
// assert!(result[ns].get().is_err());
942948
}
943949
}
944950
});
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
mod m1 {
2+
pub fn f() {}
3+
}
4+
mod m2 {
5+
pub fn f(_: u8) {}
6+
}
7+
8+
pub use m1::*;
9+
pub use m2::*;
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// aux-build:glob-conflict.rs
2+
3+
extern crate glob_conflict;
4+
5+
fn main() {
6+
glob_conflict::f(); //~ ERROR cannot find function `f` in module `glob_conflict`
7+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
error[E0425]: cannot find function `f` in module `glob_conflict`
2+
--> $DIR/glob-conflict-cross-crate.rs:6:20
3+
|
4+
LL | glob_conflict::f(); //~ ERROR cannot find function `f` in module `glob_conflict`
5+
| ^ not found in `glob_conflict`
6+
7+
error: aborting due to previous error
8+
9+
For more information about this error, try `rustc --explain E0425`.

src/test/ui/imports/issue-55884-1.rs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
mod m {
2+
mod m1 {
3+
pub struct S {}
4+
}
5+
mod m2 {
6+
// Note this derive, it makes this struct macro-expanded,
7+
// so it doesn't appear in time to participate in the initial resolution of `use m::S`,
8+
// only in the later validation pass.
9+
#[derive(Default)]
10+
pub struct S {}
11+
}
12+
13+
// Create a glob vs glob ambiguity
14+
pub use self::m1::*;
15+
pub use self::m2::*;
16+
}
17+
18+
fn main() {
19+
use m::S; //~ ERROR `S` is ambiguous
20+
let s = S {};
21+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
error[E0659]: `S` is ambiguous (glob import vs glob import in the same module)
2+
--> $DIR/issue-55884-1.rs:19:12
3+
|
4+
LL | use m::S; //~ ERROR `S` is ambiguous
5+
| ^ ambiguous name
6+
|
7+
note: `S` could refer to the struct imported here
8+
--> $DIR/issue-55884-1.rs:14:13
9+
|
10+
LL | pub use self::m1::*;
11+
| ^^^^^^^^^^^
12+
= help: consider adding an explicit import of `S` to disambiguate
13+
note: `S` could also refer to the struct imported here
14+
--> $DIR/issue-55884-1.rs:15:13
15+
|
16+
LL | pub use self::m2::*;
17+
| ^^^^^^^^^^^
18+
= help: consider adding an explicit import of `S` to disambiguate
19+
20+
error: aborting due to previous error
21+
22+
For more information about this error, try `rustc --explain E0659`.

src/test/ui/imports/issue-55884-2.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
mod options {
2+
pub struct ParseOptions {}
3+
}
4+
5+
mod parser {
6+
pub use options::*;
7+
// Private single import shadows public glob import, but arrives too late for initial
8+
// resolution of `use parser::ParseOptions` because it depends on that resolution itself.
9+
use ParseOptions;
10+
}
11+
12+
pub use parser::ParseOptions; //~ ERROR struct `ParseOptions` is private
13+
14+
fn main() {}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
error[E0603]: struct `ParseOptions` is private
2+
--> $DIR/issue-55884-2.rs:12:17
3+
|
4+
LL | pub use parser::ParseOptions; //~ ERROR struct `ParseOptions` is private
5+
| ^^^^^^^^^^^^
6+
7+
error: aborting due to previous error
8+
9+
For more information about this error, try `rustc --explain E0603`.

src/test/ui/rust-2018/local-path-suggestions-2018.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ mod foo {
1919
}
2020

2121
mod bazz {
22-
use foo::Bar;
22+
use foo::Bar; //~ ERROR unresolved import `foo`
2323

2424
fn baz() {
2525
let x: Bar = 22;
@@ -28,6 +28,6 @@ mod bazz {
2828

2929
use foo::Bar;
3030

31-
use foobar::Baz;
31+
use foobar::Baz; //~ ERROR unresolved import `foobar`
3232

3333
fn main() { }

src/test/ui/rust-2018/local-path-suggestions-2018.stderr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
error[E0432]: unresolved import `foo`
22
--> $DIR/local-path-suggestions-2018.rs:22:9
33
|
4-
LL | use foo::Bar;
4+
LL | use foo::Bar; //~ ERROR unresolved import `foo`
55
| ^^^ did you mean `crate::foo`?
66
|
77
= note: `use` statements changed in Rust 2018; read more at <https://doc.rust-lang.org/edition-guide/rust-2018/module-system/path-clarity.html>
88

99
error[E0432]: unresolved import `foobar`
1010
--> $DIR/local-path-suggestions-2018.rs:31:5
1111
|
12-
LL | use foobar::Baz;
12+
LL | use foobar::Baz; //~ ERROR unresolved import `foobar`
1313
| ^^^^^^ did you mean `baz::foobar`?
1414

1515
error: aborting due to 2 previous errors

0 commit comments

Comments
 (0)