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

Silence unused_import warning on unresolved import #63724

Closed
estebank opened this issue Aug 20, 2019 · 1 comment · Fixed by #64054 or #64265
Closed

Silence unused_import warning on unresolved import #63724

estebank opened this issue Aug 20, 2019 · 1 comment · Fixed by #64054 or #64265
Labels
A-diagnostics Area: Messages for errors, warnings, and lints C-cleanup Category: PRs that clean code up or issues documenting cleanup. C-enhancement Category: An issue proposing an enhancement or a PR with one. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@estebank
Copy link
Contributor

estebank commented Aug 20, 2019

use Foo::*; will cause the following output:

error[E0432]: unresolved import `Foo`
 --> src/lib.rs:1:5
  |
1 | use Foo::*;
  |     ^^^ use of undeclared type or module `Foo`

warning: unused import: `Foo::*`
 --> src/lib.rs:1:5
  |
1 | use Foo::*;
  |     ^^^^^^
  |
  = note: `#[warn(unused_imports)]` on by default

The warning should be silenced.

CC #56982

@estebank estebank added C-cleanup Category: PRs that clean code up or issues documenting cleanup. C-enhancement Category: An issue proposing an enhancement or a PR with one. A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Aug 20, 2019
@estebank
Copy link
Contributor Author

estebank commented Sep 1, 2019

The following doesn't seem to be behaving correctly either as only the first incorrect import gets an E0432, while the others just get the unused import warning:

use foo1;
use foo2::foo3;
use foo4::*;
use foo5;
use foo6::foo7;
use foo8::*;

I have a patch for the glob imports, but this new problem is still unresolved. CC @petrochenkov

--- a/src/librustc_resolve/resolve_imports.rs
+++ b/src/librustc_resolve/resolve_imports.rs
@@ -764,6 +764,12 @@ impl<'a, 'b> ImportResolver<'a, 'b> {
             match path_res {
                 PathResult::Module(module) => module,
                 PathResult::Indeterminate => return false,
+                PathResult::Failed { .. } if directive.is_glob() => {
+                    // Do not complain about unused import when encountering a bad glob import.
+                    // (#63724)
+                    self.r.used_imports.insert((directive.id, TypeNS));
+                    return true;
+                }
                 PathResult::NonModule(..) | PathResult::Failed { .. } => return true,
             }
         };

@petrochenkov what stops us from creating errors for both determined_imports and indeterminate_imports in finalize_imports? Other than the subpar suggestions like the following:

error[E0432]: unresolved import `foo5`
 --> file.rs:6:5
  |
6 | use foo5;
  |     ^^^^
  |     |
  |     no `foo5` in the root
  |     help: a similar name exists in the module: `foo7`

@bors bors closed this as completed in 3a32803 Sep 8, 2019
Centril added a commit to Centril/rust that referenced this issue Sep 9, 2019
… r=petrochenkov

Always emit unresolved import errors and hide unused import lint

Fix rust-lang#63724.

r? @petrochenkov
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints C-cleanup Category: PRs that clean code up or issues documenting cleanup. C-enhancement Category: An issue proposing an enhancement or a PR with one. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
1 participant