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

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

Closed
rukai opened this issue Jan 24, 2024 · 0 comments · Fixed by #120305
Closed

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

rukai opened this issue Jan 24, 2024 · 0 comments · Fixed by #120305
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-enhancement Category: An issue proposing an enhancement or a PR with one. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@rukai
Copy link
Contributor

rukai commented Jan 24, 2024

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

@rukai rukai added A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Jan 24, 2024
@fmease fmease added C-enhancement Category: An issue proposing an enhancement or a PR with one. 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` and removed A-diagnostics Area: Messages for errors, warnings, and lints labels Jan 24, 2024
@bors bors closed this as completed in 3c89280 Mar 2, 2024
rust-timer added a commit to rust-lang-ci/rust that referenced this issue Mar 2, 2024
Rollup merge of rust-lang#120305 - clubby789:unused-import-line, r=estebank

Delete line if suggestion would replace it with an empty line

Fixes rust-lang#120296
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-enhancement Category: An issue proposing an enhancement or a PR with one. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants