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

Suggestion of useless_attribute breaks rustfix #5021

Closed
flip1995 opened this issue Jan 8, 2020 · 1 comment · Fixed by #5022
Closed

Suggestion of useless_attribute breaks rustfix #5021

flip1995 opened this issue Jan 8, 2020 · 1 comment · Fixed by #5022
Assignees
Labels
good-first-issue These issues are a good way to get started with Clippy L-suggestion Lint: Improving, adding or fixing lint suggestions

Comments

@flip1995
Copy link
Member

flip1995 commented Jan 8, 2020

Minimal reproducer:

fn foo() {
    #[allow(clippy::almost_swapped)]
    use std::collections::HashMap;

    let _ = HashMap::default();
}

produces

error: useless lint attribute
 --> src/main.rs:2:1
  |
2 |     #[allow(clippy::almost_swapped)]
  | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: if you just forgot a `!`, use: `#![allow(clippy::almost_swapped)]`
  |
  = note: `#[deny(clippy::useless_attribute)]` on by default
  = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#useless_attribute

The suggestion in itself is correct. This trips rustfix though, since rustfix removes indentations of suggestions and then slices the text pointed at from the suggestion. Relevant rustfix code can be found here: https://github.com/rust-lang/rustfix/blob/715eff0b15b6ffc5adcb016b6713132159681723/src/lib.rs#L95-L113

Playground

@flip1995 flip1995 added good-first-issue These issues are a good way to get started with Clippy L-suggestion Lint: Improving, adding or fixing lint suggestions labels Jan 8, 2020
@flip1995
Copy link
Member Author

flip1995 commented Jan 8, 2020

I'll assign this issue to myself. If I shouldn't get to open a PR about this though, it's up for grabs.

@flip1995 flip1995 self-assigned this Jan 8, 2020
bors added a commit that referenced this issue Jan 8, 2020
Fix useless_attribute suggestion

Fixes #5021

changelog: Fix [`useless_attribute`] suggestion, which tripped rustfix
@bors bors closed this as completed in 0da0ae3 Jan 8, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good-first-issue These issues are a good way to get started with Clippy L-suggestion Lint: Improving, adding or fixing lint suggestions
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant