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

unused_imports suggestion does not remove attributes #87973

Closed
ehuss opened this issue Aug 12, 2021 · 1 comment · Fixed by #87975
Closed

unused_imports suggestion does not remove attributes #87973

ehuss opened this issue Aug 12, 2021 · 1 comment · Fixed by #87975
Assignees
Labels
A-lint Area: Lints (warnings about flaws in source code) such as unused_mut. A-suggestion-diagnostics Area: Suggestions generated by the compiler applied by `cargo fix`. C-bug Category: This is a bug. D-invalid-suggestion Diagnostics: A structured suggestion resulting in incorrect code.

Comments

@ehuss
Copy link
Contributor

ehuss commented Aug 12, 2021

I tried this code:

#[deprecated]
#[allow(unsafe_code)]
#[cfg(not(foo))]
use std::fs;

fn main() {}

I expected to see this happen: The suggestion should suggest removing use std::fs; and its attributes.

Instead, this happened: The suggestion span does not encompass the attributes. This causes cargo fix to remove the item, and leave the attributes applying to whatever happens to be next.

Meta

rustc 1.56.0-nightly (ccffcafd5 2021-08-11)

See also #56328 for a similar issue (although I think that one is subtly different).

@ehuss ehuss added the C-bug Category: This is a bug. label Aug 12, 2021
@jonas-schievink jonas-schievink added A-lint Area: Lints (warnings about flaws in source code) such as unused_mut. A-suggestion-diagnostics Area: Suggestions generated by the compiler applied by `cargo fix`. labels Aug 12, 2021
@m-ou-se m-ou-se self-assigned this Aug 12, 2021
@m-ou-se m-ou-se added the D-invalid-suggestion Diagnostics: A structured suggestion resulting in incorrect code. label Aug 12, 2021
@m-ou-se
Copy link
Member

m-ou-se commented Aug 12, 2021

#87975 fixes this.

@bors bors closed this as completed in dfe5fd0 Aug 15, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-lint Area: Lints (warnings about flaws in source code) such as unused_mut. A-suggestion-diagnostics Area: Suggestions generated by the compiler applied by `cargo fix`. C-bug Category: This is a bug. D-invalid-suggestion Diagnostics: A structured suggestion resulting in incorrect code.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants