rust-lang / rust-lang/rustfmt

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

Open
#6,339 4 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

A-2024-style-edition A-comments C-bug only-with-option UO-wrap_comments
Dominant language
Rust
Stars
7k
Forks
1.1k
Avg merge
2d 13h
Merged PRs (30d)
24

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)

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the rustfmt.toml settings and the src/main.rs reproduction, then run cargo +nightly fmt or rustfmt +nightly src/main.rs. Done means formatting the reproduced block comment preserves a terminating */ and produces valid Rust syntax when version = "Two" and wrap_comments = true.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
50/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.