Skip to content

Commit fbbec76

Browse files
committed
resolve: Consider erroneous imports used to avoid duplicate diagnostics
1 parent bdfdbcd commit fbbec76

File tree

3 files changed

+36
-0
lines changed

3 files changed

+36
-0
lines changed

src/librustc_resolve/resolve_imports.rs

+2
Original file line numberDiff line numberDiff line change
@@ -627,6 +627,8 @@ impl<'a> Resolver<'a> {
627627
let dummy_binding = self.import(dummy_binding, directive);
628628
self.per_ns(|this, ns| {
629629
let _ = this.try_define(directive.parent_scope.module, target, ns, dummy_binding);
630+
// Consider erroneous imports used to avoid duplicate diagnostics.
631+
this.record_use(target, ns, dummy_binding, false);
630632
});
631633
}
632634
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// There should be *no* unused import errors.
2+
#![deny(unused_imports)]
3+
4+
mod qux {
5+
fn quz() {}
6+
}
7+
8+
use qux::quz; //~ ERROR function `quz` is private
9+
use qux::bar; //~ ERROR unresolved import `qux::bar`
10+
use foo::bar; //~ ERROR unresolved import `foo`
11+
12+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
error[E0432]: unresolved import `qux::bar`
2+
--> $DIR/unresolved-imports-used.rs:9:5
3+
|
4+
LL | use qux::bar;
5+
| ^^^^^^^^ no `bar` in `qux`
6+
7+
error[E0432]: unresolved import `foo`
8+
--> $DIR/unresolved-imports-used.rs:10:5
9+
|
10+
LL | use foo::bar;
11+
| ^^^ maybe a missing `extern crate foo;`?
12+
13+
error[E0603]: function `quz` is private
14+
--> $DIR/unresolved-imports-used.rs:8:10
15+
|
16+
LL | use qux::quz;
17+
| ^^^
18+
19+
error: aborting due to 3 previous errors
20+
21+
Some errors have detailed explanations: E0432, E0603.
22+
For more information about an error, try `rustc --explain E0432`.

0 commit comments

Comments
 (0)