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

No error emitted for use clippy; #83334

Closed
camelid opened this issue Mar 21, 2021 · 5 comments
Closed

No error emitted for use clippy; #83334

camelid opened this issue Mar 21, 2021 · 5 comments
Labels
A-resolve Area: Name/path resolution done by `rustc_resolve` specifically C-bug Category: This is a bug. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@camelid
Copy link
Member

camelid commented Mar 21, 2021

use clippy::a;

errors with

error[E0432]: unresolved import `clippy`
 --> src/lib.rs:1:5
  |
1 | use clippy::a;
  |     ^^^^^^ `clippy` is a tool module, not a module

but

use clippy;

just says

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

Note that actually using the import gives an error:

error: cannot use a tool module through an import
 --> src/main.rs:4:5
  |
4 |     clippy::a();
  |     ^^^^^^
  |
note: the tool module imported here
 --> src/main.rs:1:5
  |
1 | use clippy;
  |     ^^^^^^

error[E0423]: expected function, found tool attribute `clippy::a`
 --> src/main.rs:4:5
  |
4 |     clippy::a();
  |     ^^^^^^^^^ not a function

error: aborting due to 2 previous errors

Found this while playing around with the MCVE in #83317.

@camelid camelid added A-resolve Area: Name/path resolution done by `rustc_resolve` specifically T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. C-bug Category: This is a bug. labels Mar 21, 2021
@petrochenkov
Copy link
Contributor

This is working as expected, use clippy; working is just uniform import paths in action.
Any name in scope can be imported, including tool modules.

"Cannot use through an import" errors are reported for attributes that are detected textually by their users (tool attributes by tools, derive helpers by proc macros, built-in attributes by rustc), and renaming would break their use.

use clippy::a; should arguably work in theory, but it's hard to do due to implementation details of imports (the import path is split to two parts, the first one of which must be a module), and also entirely useless.

@camelid
Copy link
Member Author

camelid commented Mar 21, 2021

Hmm, interesting. By the way, why doesn't use clippy as foo; #[deny(foo::warnings)] ... work? I get an error with that:

error[E0710]: an unknown tool name found in scoped lint: `foo::warnings`
 --> src/lib.rs:2:8
  |
2 | #[deny(foo::warnings)] pub fn baz() { None.expect(&format!("")) }
  |        ^^^

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

error: aborting due to previous error; 1 warning emitted

@jyn514
Copy link
Member

jyn514 commented Mar 22, 2021

Interestingly, this doesn't work with register_tool either (use 'clippy' on the right, the warning is denied by default): https://play.rust-lang.org/?version=nightly&mode=debug&edition=2018&gist=252d78a905b7b628c04f8315542bd150

@petrochenkov
Copy link
Contributor

By the way, why doesn't use clippy as foo; #[deny(foo::warnings)] ... work?

Because lint naming has zero relation to name resolution.
foo::warnings is not a path in a regular sense, it's not resolved in the current scope, it's just some path-like syntax to name lints belonging to tools.

@camelid
Copy link
Member Author

camelid commented Mar 22, 2021

By the way, why doesn't use clippy as foo; #[deny(foo::warnings)] ... work?

Because lint naming has zero relation to name resolution.
foo::warnings is not a path in a regular sense, it's not resolved in the current scope, it's just some path-like syntax to name lints belonging to tools.

I was asking because I thought tool modules might be allowed to be imported because you could rename them, but I guess it's niche enough that there hasn't been a need. I'll close this issue then.

@camelid camelid closed this as completed Mar 22, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-resolve Area: Name/path resolution done by `rustc_resolve` specifically C-bug Category: This is a bug. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

3 participants