Skip to content

rustfmt breaks a /* ... */ comment into /* ... //, with no terminating */ #6339

@ssbr

Description

@ssbr

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

No one assigned

    Labels

    a-commentsbugPanic, non-idempotency, invalid code, etc.only-with-optionrequires a non-default option value to reproduce

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions