-
Notifications
You must be signed in to change notification settings - Fork 13.6k
Closed
Labels
A-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsA-edition-2018Area: The 2018 editionArea: The 2018 editionA-lintsArea: Lints (warnings about flaws in source code) such as unused_mut.Area: Lints (warnings about flaws in source code) such as unused_mut.
Description
Original rustfix issue: rust-lang/rustfix#147
When rustc outputs warnings like "you don't need this extern crate line anymore, delete it," it doesn't include accompanying attributes. This leads rustfix to apply its suggestion to delete the extern crate line, but leave the attribute, which then gets applied to the next item.
For example:
#[cfg(unix)]
extern crate nix;
mod foo;
becomes
#[cfg(unix)]
mod foo;
which applies the #[cfg(unix)]
attribute to mod foo;
which is definitely not what was desired.
sanmai-NL, HyeonuPark, estebank, killercup and hcpl
Metadata
Metadata
Assignees
Labels
A-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsA-edition-2018Area: The 2018 editionArea: The 2018 editionA-lintsArea: Lints (warnings about flaws in source code) such as unused_mut.Area: Lints (warnings about flaws in source code) such as unused_mut.
Type
Projects
Milestone
Relationships
Development
Select code repository
Activity
zackmdavis commentedon Sep 21, 2018
Here's where we issue the diagnostic:
rust/src/librustc_typeck/check_unused.rs
Lines 137 to 152 in 2fa1390
Assuming the cfg attribute is actually preserved by earlier passes, then correcting for this case should be easy (look for it in
tcx.get_attrs
and extend the span correspondingly), but I don't remember offhand whether that's true and don't have time to investigate right now. If it isn't, then this is similar-in-spirit to #45216 in that we "just" want the span of an attribute, but would need to do some nontrivial rearchitecting work to make it available.in which we include attributes in unused `extern crate` suggestion spans
extern crate
suggestion spans #54488Rollup merge of rust-lang#54488 - zackmdavis:and_the_case_of_the_unus…