diff --git a/src/librustc_resolve/resolve_imports.rs b/src/librustc_resolve/resolve_imports.rs index 6dad1426ea363a86900b903a2070d3db984547cb..9e5036b6e500e25d43b0fd51926247596f2adf77 100644 --- a/src/librustc_resolve/resolve_imports.rs +++ b/src/librustc_resolve/resolve_imports.rs @@ -192,6 +192,7 @@ fn resolution(&self, module: Module<'a>, ident: Ident, ns: Namespace) ident.name == keywords::SelfValue.name() { // FIXME: Implement these with renaming requirements so that e.g. // `use super;` doesn't work, but `use super as name;` does. + // Fall through here to get an error from `early_resolve_...`. } } @@ -940,7 +941,12 @@ fn finalize_import( } } Err(..) => { - assert!(result[ns].get().is_err()); + // FIXME: This assert may fire if public glob is later shadowed by a private + // single import (see test `issue-55884-2.rs`). In theory single imports should + // always block globs, even if they are not yet resolved, so that this kind of + // self-inconsistent resolution never happens. + // Reenable the assert when the issue is fixed. + // assert!(result[ns].get().is_err()); } } }); diff --git a/src/test/ui/imports/auxiliary/glob-conflict.rs b/src/test/ui/imports/auxiliary/glob-conflict.rs new file mode 100644 index 0000000000000000000000000000000000000000..ac12ed9c81c77c29aaccf50a660477767152e295 --- /dev/null +++ b/src/test/ui/imports/auxiliary/glob-conflict.rs @@ -0,0 +1,9 @@ +mod m1 { + pub fn f() {} +} +mod m2 { + pub fn f(_: u8) {} +} + +pub use m1::*; +pub use m2::*; diff --git a/src/test/ui/imports/glob-conflict-cross-crate.rs b/src/test/ui/imports/glob-conflict-cross-crate.rs new file mode 100644 index 0000000000000000000000000000000000000000..e02148b19f786e52bdbf359efa65d997867ed873 --- /dev/null +++ b/src/test/ui/imports/glob-conflict-cross-crate.rs @@ -0,0 +1,7 @@ +// aux-build:glob-conflict.rs + +extern crate glob_conflict; + +fn main() { + glob_conflict::f(); //~ ERROR cannot find function `f` in module `glob_conflict` +} diff --git a/src/test/ui/imports/glob-conflict-cross-crate.stderr b/src/test/ui/imports/glob-conflict-cross-crate.stderr new file mode 100644 index 0000000000000000000000000000000000000000..f64637fd6f625c9cc83591b8375a7ff1f29ea75f --- /dev/null +++ b/src/test/ui/imports/glob-conflict-cross-crate.stderr @@ -0,0 +1,9 @@ +error[E0425]: cannot find function `f` in module `glob_conflict` + --> $DIR/glob-conflict-cross-crate.rs:6:20 + | +LL | glob_conflict::f(); //~ ERROR cannot find function `f` in module `glob_conflict` + | ^ not found in `glob_conflict` + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0425`. diff --git a/src/test/ui/imports/issue-55884-1.rs b/src/test/ui/imports/issue-55884-1.rs new file mode 100644 index 0000000000000000000000000000000000000000..21744aa5d7bfa51b73a2ccf7f9dc7fff7409a31b --- /dev/null +++ b/src/test/ui/imports/issue-55884-1.rs @@ -0,0 +1,21 @@ +mod m { + mod m1 { + pub struct S {} + } + mod m2 { + // Note this derive, it makes this struct macro-expanded, + // so it doesn't appear in time to participate in the initial resolution of `use m::S`, + // only in the later validation pass. + #[derive(Default)] + pub struct S {} + } + + // Create a glob vs glob ambiguity + pub use self::m1::*; + pub use self::m2::*; +} + +fn main() { + use m::S; //~ ERROR `S` is ambiguous + let s = S {}; +} diff --git a/src/test/ui/imports/issue-55884-1.stderr b/src/test/ui/imports/issue-55884-1.stderr new file mode 100644 index 0000000000000000000000000000000000000000..477e859d0815ee774297fadda28bdfaa3464b049 --- /dev/null +++ b/src/test/ui/imports/issue-55884-1.stderr @@ -0,0 +1,22 @@ +error[E0659]: `S` is ambiguous (glob import vs glob import in the same module) + --> $DIR/issue-55884-1.rs:19:12 + | +LL | use m::S; //~ ERROR `S` is ambiguous + | ^ ambiguous name + | +note: `S` could refer to the struct imported here + --> $DIR/issue-55884-1.rs:14:13 + | +LL | pub use self::m1::*; + | ^^^^^^^^^^^ + = help: consider adding an explicit import of `S` to disambiguate +note: `S` could also refer to the struct imported here + --> $DIR/issue-55884-1.rs:15:13 + | +LL | pub use self::m2::*; + | ^^^^^^^^^^^ + = help: consider adding an explicit import of `S` to disambiguate + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0659`. diff --git a/src/test/ui/imports/issue-55884-2.rs b/src/test/ui/imports/issue-55884-2.rs new file mode 100644 index 0000000000000000000000000000000000000000..1b4f652c9fc2f1acf060f0224a074885a03a6e4a --- /dev/null +++ b/src/test/ui/imports/issue-55884-2.rs @@ -0,0 +1,14 @@ +mod options { + pub struct ParseOptions {} +} + +mod parser { + pub use options::*; + // Private single import shadows public glob import, but arrives too late for initial + // resolution of `use parser::ParseOptions` because it depends on that resolution itself. + use ParseOptions; +} + +pub use parser::ParseOptions; //~ ERROR struct `ParseOptions` is private + +fn main() {} diff --git a/src/test/ui/imports/issue-55884-2.stderr b/src/test/ui/imports/issue-55884-2.stderr new file mode 100644 index 0000000000000000000000000000000000000000..f8a6cb4a580909b95d4b5905ba5b48b629181ec2 --- /dev/null +++ b/src/test/ui/imports/issue-55884-2.stderr @@ -0,0 +1,9 @@ +error[E0603]: struct `ParseOptions` is private + --> $DIR/issue-55884-2.rs:12:17 + | +LL | pub use parser::ParseOptions; //~ ERROR struct `ParseOptions` is private + | ^^^^^^^^^^^^ + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0603`. diff --git a/src/test/ui/rust-2018/local-path-suggestions-2018.rs b/src/test/ui/rust-2018/local-path-suggestions-2018.rs index 8c9583cfa1bbcf9adfa8b3e0b2968efb10957e6b..0d4aefff9316c6954fa379ccb5f917dcbf02a30b 100644 --- a/src/test/ui/rust-2018/local-path-suggestions-2018.rs +++ b/src/test/ui/rust-2018/local-path-suggestions-2018.rs @@ -19,7 +19,7 @@ mod foo { } mod bazz { - use foo::Bar; + use foo::Bar; //~ ERROR unresolved import `foo` fn baz() { let x: Bar = 22; @@ -28,6 +28,6 @@ fn baz() { use foo::Bar; -use foobar::Baz; +use foobar::Baz; //~ ERROR unresolved import `foobar` fn main() { } diff --git a/src/test/ui/rust-2018/local-path-suggestions-2018.stderr b/src/test/ui/rust-2018/local-path-suggestions-2018.stderr index 27ea6642eb01e6197c7a2c6985f9183338818bea..a445a4c612bb997cbc119e3bd2005451ccbebd57 100644 --- a/src/test/ui/rust-2018/local-path-suggestions-2018.stderr +++ b/src/test/ui/rust-2018/local-path-suggestions-2018.stderr @@ -1,7 +1,7 @@ error[E0432]: unresolved import `foo` --> $DIR/local-path-suggestions-2018.rs:22:9 | -LL | use foo::Bar; +LL | use foo::Bar; //~ ERROR unresolved import `foo` | ^^^ did you mean `crate::foo`? | = note: `use` statements changed in Rust 2018; read more at @@ -9,7 +9,7 @@ LL | use foo::Bar; error[E0432]: unresolved import `foobar` --> $DIR/local-path-suggestions-2018.rs:31:5 | -LL | use foobar::Baz; +LL | use foobar::Baz; //~ ERROR unresolved import `foobar` | ^^^^^^ did you mean `baz::foobar`? error: aborting due to 2 previous errors diff --git a/src/test/ui/rust-2018/uniform-paths/deadlock.rs b/src/test/ui/rust-2018/uniform-paths/deadlock.rs new file mode 100644 index 0000000000000000000000000000000000000000..3228d799083fb228c255d26b1325cebe3498612d --- /dev/null +++ b/src/test/ui/rust-2018/uniform-paths/deadlock.rs @@ -0,0 +1,7 @@ +// edition:2018 +// compile-flags:--extern foo --extern bar + +use foo::bar; //~ ERROR unresolved import +use bar::foo; + +fn main() {} diff --git a/src/test/ui/rust-2018/uniform-paths/deadlock.stderr b/src/test/ui/rust-2018/uniform-paths/deadlock.stderr new file mode 100644 index 0000000000000000000000000000000000000000..8bbc8f33039b946c9a76f0e24f2a38614422a06d --- /dev/null +++ b/src/test/ui/rust-2018/uniform-paths/deadlock.stderr @@ -0,0 +1,9 @@ +error[E0432]: unresolved import + --> $DIR/deadlock.rs:4:5 + | +LL | use foo::bar; //~ ERROR unresolved import + | ^^^^^^^^ + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0432`. diff --git a/src/test/ui/rust-2018/uniform-paths/issue-54390.rs b/src/test/ui/rust-2018/uniform-paths/issue-54390.rs new file mode 100644 index 0000000000000000000000000000000000000000..536cc25e35ac1b4b4516a482e93d3c3b90015b0b --- /dev/null +++ b/src/test/ui/rust-2018/uniform-paths/issue-54390.rs @@ -0,0 +1,11 @@ +// edition:2018 + +#![deny(unused)] + +use std::fmt; + +// No "unresolved import" + "unused import" combination here. +use fmt::Write; //~ ERROR imports can only refer to extern crate names + //~| ERROR unused import: `fmt::Write` + +fn main() {} diff --git a/src/test/ui/rust-2018/uniform-paths/issue-54390.stderr b/src/test/ui/rust-2018/uniform-paths/issue-54390.stderr new file mode 100644 index 0000000000000000000000000000000000000000..8f86698c9c11a16e57ca83bab3a7f1a542736ed3 --- /dev/null +++ b/src/test/ui/rust-2018/uniform-paths/issue-54390.stderr @@ -0,0 +1,32 @@ +error[E0658]: imports can only refer to extern crate names passed with `--extern` on stable channel (see issue #53130) + --> $DIR/issue-54390.rs:8:5 + | +LL | use std::fmt; + | -------- not an extern crate passed with `--extern` +... +LL | use fmt::Write; //~ ERROR imports can only refer to extern crate names + | ^^^ + | + = help: add #![feature(uniform_paths)] to the crate attributes to enable +note: this import refers to the module imported here + --> $DIR/issue-54390.rs:5:5 + | +LL | use std::fmt; + | ^^^^^^^^ + +error: unused import: `fmt::Write` + --> $DIR/issue-54390.rs:8:5 + | +LL | use fmt::Write; //~ ERROR imports can only refer to extern crate names + | ^^^^^^^^^^ + | +note: lint level defined here + --> $DIR/issue-54390.rs:3:9 + | +LL | #![deny(unused)] + | ^^^^^^ + = note: #[deny(unused_imports)] implied by #[deny(unused)] + +error: aborting due to 2 previous errors + +For more information about this error, try `rustc --explain E0658`.