-
Notifications
You must be signed in to change notification settings - Fork 942
Open
Copy link
Labels
a-commentsbugPanic, non-idempotency, invalid code, etc.Panic, non-idempotency, invalid code, etc.only-with-optionrequires a non-default option value to reproducerequires a non-default option value to reproduce
Description
With version = "Two"
and wrap_comments = true
, rustfmt can break a /* ... */
comment by changing one of its lines to start with //
. The error does not occur without version "Two" or without wrap_comments
. Maybe worth noting, we have both of those options on at work.
(Sorry if this is a duplicate bug, couldn't find anything by searching for is:issue state:open "wrap_comments = true" "version = \"Two\""
)
Reproduction steps:
cargo new test-crate
cd test-crate
echo 'version = "Two"
wrap_comments = true' > rustfmt.toml
echo 'use rustc_middle::ty::{self, Region, Ty, TyCtxt}; /* xx xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
* xxxxxxxxxxxxx */
fn main() {}
' > src/main.rs
cargo +nightly fmt # or rustfmt +nightly src/main.rs
cat src/main.rs
On my computer, I get:
use rustc_middle::ty::{self, Region, Ty, TyCtxt}; /* xx xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
// xxxxxxxxxxxxx
fn main() {}
Which is not valid syntax.
rustfmt version:
$ rustfmt +nightly --version
rustfmt 1.7.1-nightly (506f22b 2024-09-19)
Metadata
Metadata
Assignees
Labels
a-commentsbugPanic, non-idempotency, invalid code, etc.Panic, non-idempotency, invalid code, etc.only-with-optionrequires a non-default option value to reproducerequires a non-default option value to reproduce
Type
Projects
Milestone
Relationships
Development
Select code repository
Activity
ytmimi commentedon Sep 21, 2024
Confirming I can reproduce this using rustfmt 1.8.0-nightly (6157568 2024-09-20),
style_edition=2024
1 andwrap_comments=true
. There have been similar issues reported before and I'll try to dig through the backlog later to find any that seem relevant here.Input
Output
Footnotes
style_edition
replacesversion
in newer rustfmt releases ↩hlopko commentedon Sep 26, 2024
Thanks @ytmimi!
dqkqd commentedon Oct 5, 2024
Is it ok for me to work on this issue? @ytmimi
I think the bug occurred because we try to
rewrite_comment
onother_lines
, which is a part of a multi lineblock comment
.rustfmt/src/missed_spans.rs
Lines 285 to 289 in 5f48fe9
I suppose a correct fix would be not separating comment lines in case of multi line
block comment
.However, it will wrap comment in this case below as well.
Input
Output
ytmimi commentedon Oct 6, 2024
@dqkqd if you're interested in taking a look at this that would be great!
Wrap multi lined trailing block comments (rust-lang#6339)
Wrap multi lined trailing block comments (rust-lang#6339)