Rollup merge of #64265 - petrochenkov:useerr, r=estebank

resolve: Mark more erroneous imports as used

Fixes https://github.com/rust-lang/rust/issues/63724
r? @estebank
This commit is contained in:
Mazdak Farrokhzad 2019-09-08 12:11:57 +02:00 committed by GitHub
commit 3a3280326e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 37 additions and 11 deletions

View File

@ -673,6 +673,10 @@ impl<'a, 'b> ImportResolver<'a, 'b> {
self.throw_unresolved_import_error(errors.clone(), None);
}
for import in &self.r.indeterminate_imports {
// Consider erroneous imports used to avoid duplicate diagnostics.
self.r.used_imports.insert((import.id, TypeNS));
}
// Report unresolved imports only if no hard error was already reported
// to avoid generating multiple errors on the same import.
if !has_errors {
@ -839,6 +843,10 @@ impl<'a, 'b> ImportResolver<'a, 'b> {
true, directive.span, directive.crate_lint());
let no_ambiguity = self.r.ambiguity_errors.len() == prev_ambiguity_errors_len;
directive.vis.set(orig_vis);
if let PathResult::Failed { .. } | PathResult::NonModule(..) = path_res {
// Consider erroneous imports used to avoid duplicate diagnostics.
self.r.used_imports.insert((directive.id, TypeNS));
}
let module = match path_res {
PathResult::Module(module) => {
// Consistency checks, analogous to `finalize_macro_resolutions`.

View File

@ -1,12 +1,18 @@
// There should be *no* unused import errors.
// There should be *one* unused import error.
#![deny(unused_imports)]
mod qux {
fn quz() {}
pub fn quy() {}
}
use qux::quz; //~ ERROR function `quz` is private
use qux::bar; //~ ERROR unresolved import `qux::bar`
use foo::bar; //~ ERROR unresolved import `foo`
use qux::quz; //~ ERROR function `quz` is private
use qux::bar; //~ ERROR unresolved import `qux::bar`
use foo::bar;
use baz::*;
use qux::bar2; //~ ERROR unresolved import `qux::bar2`
use foo2::bar2;
use baz2::*;
use qux::quy; //~ ERROR unused import
fn main() {}

View File

@ -1,22 +1,34 @@
error[E0432]: unresolved import `qux::bar`
--> $DIR/unresolved-imports-used.rs:9:5
--> $DIR/unresolved-imports-used.rs:10:5
|
LL | use qux::bar;
| ^^^^^^^^ no `bar` in `qux`
error[E0432]: unresolved import `foo`
--> $DIR/unresolved-imports-used.rs:10:5
error[E0432]: unresolved import `qux::bar2`
--> $DIR/unresolved-imports-used.rs:13:5
|
LL | use foo::bar;
| ^^^ maybe a missing crate `foo`?
LL | use qux::bar2;
| ^^^^^^^^^ no `bar2` in `qux`
error[E0603]: function `quz` is private
--> $DIR/unresolved-imports-used.rs:8:10
--> $DIR/unresolved-imports-used.rs:9:10
|
LL | use qux::quz;
| ^^^
error: aborting due to 3 previous errors
error: unused import: `qux::quy`
--> $DIR/unresolved-imports-used.rs:16:5
|
LL | use qux::quy;
| ^^^^^^^^
|
note: lint level defined here
--> $DIR/unresolved-imports-used.rs:2:9
|
LL | #![deny(unused_imports)]
| ^^^^^^^^^^^^^^
error: aborting due to 4 previous errors
Some errors have detailed explanations: E0432, E0603.
For more information about an error, try `rustc --explain E0432`.