rust-lang / rust-lang/rustfmt

`wrap_comments` sometimes breaks code blocks in lists

Open
#5,746 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

A-comments A-markdown only-with-option P-low UO-wrap_comments
Dominant language
Rust
Stars
7k
Forks
1.1k
Avg merge
2d 13h
Merged PRs (30d)
24

Description

With rustfmt 1.5.2-nightly (88fb1b92 2023-04-10):

Input code

Snippet from some internal documentation I'm writing:

//! - References?
//!   - Unsound. See this example:
//!     ```compile_fail
//!     # use core::mem::MaybeUninit;
//!     let mut a = 0;
//!     let b = maybe_uninit_ext::new::<&mut MaybeUninit<u8>>(&mut a);
//!     *b = maybe_uninit_ext::uninit();
//!     assert_eq!(a, 0); // undefined behavior! a is uninitialized.
//!     ```
//!     Due to interior mutability, this is an issue for immutable references
//!     as well.
Actual result
//! - References?
//!   - Unsound. See this example: ```compile_fail # use core::mem::MaybeUninit;
//!     let mut a = 0; let b = maybe_uninit_ext::new::<&mut
//!     MaybeUninit<u8>>(&mut a); *b = maybe_uninit_ext::uninit(); assert_eq!(a,
//!     0); // undefined behavior! a is uninitialized. ``` Due to interior
//!     mutability, this is an issue for immutable references as well.
Expected result

The code block should be preserved.

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 by reproducing the supplied nested-list example with rustfmt 1.5.2-nightly and the wrap_comments option, then trace the formatting path that handles comments and code fences in lists. Done means the nested compile_fail code block remains preserved instead of being joined into the surrounding comment text.

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
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.