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

rustfmt unexpectedly eats comments in block imports (use statements) #5877

Closed
lthoerner opened this issue Aug 3, 2023 · 2 comments
Closed

Comments

@lthoerner
Copy link

lthoerner commented Aug 3, 2023

Issue

When rustfmt is run on a block of imports that contains commented-out imports or any other comments, it will delete said comments when collapsing the statements, under a particular condition explained below.

Reproducing

Write a block of imports containing one or more "sub-blocks," such as this:

use std::{
    io::{Read, Write},
    time::{Duration, Instant},
    fmt::Display,
    sync::Arc,
};

Now comment out all but one list item, ensuring that the remaining item is one of the aforementioned sub-blocks, like so:

use std::{
    io::{Read, Write},
    // time::{Duration, Instant},
    // fmt::Display,
    // sync::Arc,
};

When formatting, it will collapse to:

use std::io::{Read, Write};

The same is true of normal comments, such as this:

use std::{
    io::{Read, Write},
    // time::{Duration, Instant},
    // fmt::Display,
    // sync::Arc,
    // Hello world!
};

Possible Causes

I honestly am not sure what causes this beyond knowing how to reproduce it, as I am not familiar with the internals of rustfmt. Please let me know if you have a good explanation and I will edit this.

@lthoerner lthoerner changed the title rustfmt unexpectedly eats commented-out use statements in block imports rustfmt unexpectedly eats comments in block imports (use statements) Aug 3, 2023
@ytmimi
Copy link
Contributor

ytmimi commented Aug 3, 2023

Thanks for reaching out. Going to close this as a duplicate of #5852

@ytmimi ytmimi closed this as not planned Won't fix, can't repro, duplicate, stale Aug 3, 2023
@ytmimi
Copy link
Contributor

ytmimi commented Aug 31, 2023

We just merged #5852, so this should be resolved come the next release

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants