Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

resolve: Consider erroneous imports used to avoid duplicate diagnostics #60359

Merged
merged 1 commit into from
Apr 29, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/librustc_resolve/resolve_imports.rs
Original file line number Diff line number Diff line change
Expand Up @@ -627,6 +627,8 @@ impl<'a> Resolver<'a> {
let dummy_binding = self.import(dummy_binding, directive);
self.per_ns(|this, ns| {
let _ = this.try_define(directive.parent_scope.module, target, ns, dummy_binding);
// Consider erroneous imports used to avoid duplicate diagnostics.
this.record_use(target, ns, dummy_binding, false);
});
}
}
Expand Down
12 changes: 12 additions & 0 deletions src/test/ui/imports/unresolved-imports-used.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// There should be *no* unused import errors.
#![deny(unused_imports)]

mod qux {
fn quz() {}
}

use qux::quz; //~ ERROR function `quz` is private
use qux::bar; //~ ERROR unresolved import `qux::bar`
use foo::bar; //~ ERROR unresolved import `foo`

fn main() {}
22 changes: 22 additions & 0 deletions src/test/ui/imports/unresolved-imports-used.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
error[E0432]: unresolved import `qux::bar`
--> $DIR/unresolved-imports-used.rs:9:5
|
LL | use qux::bar;
| ^^^^^^^^ no `bar` in `qux`

error[E0432]: unresolved import `foo`
--> $DIR/unresolved-imports-used.rs:10:5
|
LL | use foo::bar;
| ^^^ maybe a missing `extern crate foo;`?

error[E0603]: function `quz` is private
--> $DIR/unresolved-imports-used.rs:8:10
|
LL | use qux::quz;
| ^^^

error: aborting due to 3 previous errors

Some errors have detailed explanations: E0432, E0603.
For more information about an error, try `rustc --explain E0432`.