Skip to content

cargo fix on unused use statements leaves empty lines behind. #120296

Closed
@rukai

Description

@rukai

Code

Run cargo fix on the following:

use std::time::Duration;
use std::time::Instant;
use std::time::SystemTime;

Current output

cargo fix will remove the unused use statements but will leave an empty line behind for each one. In this case that is 3 empty lines:




Desired output

No empty lines left behind:

Rationale and extra context

Leaving those empty lines around means they need to be manually cleaned up and I dont think there is ever a scenario where someone would want the empty line left behind.

I'm not sure if this is a cargo bug or a rustc bug.
I know rustc emits some kind of span to tell cargo what change needs to occur?
But maybe its cargo not interpreting the span correctly?

Other cases

No response

Rust Version

It has been this way for as long as I can remember but:
rustc 1.75.0 (82e1608df 2023-12-21)
binary: rustc
commit-hash: 82e1608dfa6e0b5569232559e3d385fea5a93112
commit-date: 2023-12-21
host: x86_64-unknown-linux-gnu
release: 1.75.0
LLVM version: 17.0.6

Anything else?

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-lintsArea: Lints (warnings about flaws in source code) such as unused_mut.A-suggestion-diagnosticsArea: Suggestions generated by the compiler applied by `cargo fix`C-enhancementCategory: An issue proposing an enhancement or a PR with one.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions