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

Incorrect suggestion in useless_attribute lint #4467

Closed
phansch opened this issue Aug 28, 2019 · 0 comments · Fixed by #12755
Closed

Incorrect suggestion in useless_attribute lint #4467

phansch opened this issue Aug 28, 2019 · 0 comments · Fixed by #12755
Labels
C-bug Category: Clippy is not doing the correct thing I-suggestion-causes-error Issue: The suggestions provided by this Lint cause an ICE/error when applied L-suggestion Lint: Improving, adding or fixing lint suggestions

Comments

@phansch
Copy link
Member

phansch commented Aug 28, 2019

The useless_attribute lint is meant to warn about extern crate and use items with outer lint attributes (for example #[allow(dead_code)]).

However, when this lint triggers on items that are preceded by other items, applying the suggestion will fail to compile.

Minimal example (Playground Link):

#![allow(unused_imports)]

fn main() {}

#[allow(dead_code)]
use aho_corasick;

Produces:

error: useless lint attribute
 --> src/main.rs:6:1
  |
6 | #[allow(dead_code)]
  | ^^^^^^^^^^^^^^^^^^^ help: if you just forgot a `!`, use: `#![allow(dead_code)]`

But applying the suggestion results in:

error: an inner attribute is not permitted in this context
 --> src/main.rs:6:3
  |
6 | #![allow(dead_code)]
  |   ^

To fix this, we could

a) Try to find a way to detect if the use/extern crate is preceded by any other items
b) Remove the suggestion completely if a) turns out impossible

@phansch phansch added C-bug Category: Clippy is not doing the correct thing E-hard Call for participation: This a hard problem and requires more experience or effort to work on L-suggestion Lint: Improving, adding or fixing lint suggestions I-suggestion-causes-error Issue: The suggestions provided by this Lint cause an ICE/error when applied labels Aug 28, 2019
@phansch phansch removed the E-hard Call for participation: This a hard problem and requires more experience or effort to work on label Aug 28, 2019
bors added a commit that referenced this issue May 6, 2024
…umeGomez

Allow more attributes in `clippy::useless_attribute`

Fixes #12753
Fixes #4467
Fixes #11595
Fixes #10878

changelog: [`useless_attribute`]: Attributes allowed on `use` items now include `ambiguous_glob_exports`, `hidden_glob_reexports`, `dead_code`, `unused_braces`, and `clippy::disallowed_types`.
@bors bors closed this as completed in e9761bd May 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: Clippy is not doing the correct thing I-suggestion-causes-error Issue: The suggestions provided by this Lint cause an ICE/error when applied L-suggestion Lint: Improving, adding or fixing lint suggestions
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant