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

Formatting use statements sometimes leaves behind spaces and newlines #6277

Open
antonilol opened this issue Aug 12, 2024 · 2 comments · May be fixed by #6283
Open

Formatting use statements sometimes leaves behind spaces and newlines #6277

antonilol opened this issue Aug 12, 2024 · 2 comments · May be fixed by #6283
Labels
a-imports `use` syntax bug Panic, non-idempotency, invalid code, etc. e-trailing whitespace error[internal]: left behind trailing whitespace poor-formatting

Comments

@antonilol
Copy link

Formatting the following code with cargo fmt leaves behind a space and curly braces.

Before:

use core::{
    slice,
    
    fmt::{},
};

(there are 4 spaces on the seemingly empty line)

After:

use core::{ slice};

Expected:

use core::slice;

Here a newline is left behind and rustfmt reports an internal error.

Before:

use core::{
    
    fmt::{Debug, Display},
    slice::{},
};

(there are again 4 spaces on the seemingly empty line)

After:

use core::{
    
    fmt::{Debug, Display},
};

(there are again 4 spaces on the seemingly empty line, rustfmt didn't touch them)

Expected:

use core::fmt::{Debug, Display};

Command output:

$ cargo fmt -- --check file.rs 
Diff in /path/to/file.rs at line 1:
 use core::{
     
     fmt::{Debug, Display},
-    slice::{},
 };
 
error[internal]: left behind trailing whitespace
 --> /path/to/file.rs:2:2:1
  |
2 |     
  | ^^^^
  |

warning: rustfmt has failed to format. See previous 1 errors.
@ytmimi
Copy link
Contributor

ytmimi commented Aug 13, 2024

Thanks for the report. Confirming I can reproduce this with rustfmt 1.7.1-nightly (40f5075 2024-08-05)

@wafarm wafarm linked a pull request Aug 15, 2024 that will close this issue
@ytmimi ytmimi added the bug Panic, non-idempotency, invalid code, etc. label Sep 20, 2024
@ytmimi
Copy link
Contributor

ytmimi commented Sep 20, 2024

Also marking this as a bug because it's not idempotent.

@ytmimi ytmimi added the e-trailing whitespace error[internal]: left behind trailing whitespace label Sep 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
a-imports `use` syntax bug Panic, non-idempotency, invalid code, etc. e-trailing whitespace error[internal]: left behind trailing whitespace poor-formatting
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants