`/// # #![rustfmt::skip]` behaves weird
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 7k
- Forks
- 1.1k
- Avg merge
- 2d 13h
- Merged PRs (30d)
- 24
Description
I just wanted to keep specific formatting in my list. However it wasn't so easy...
skip visible in the HTML
Source code
//! ```rust
//! #![rustfmt::skip]
//! let _ = [
//! 1, 2, 3,
//! 4, 5,
//! ];
//! ```
Rendered doc
#![rustfmt::skip]
let _ = [
1, 2, 3,
4, 5,
];
This works, but I want to hide the formatting attribute
Hiding the skip
Before save:
//! ```rust
//! # #![rustfmt::skip]
//! let _ = [
//! 1, 2, 3,
//! 4, 5,
//! ];
//! ```
On save the list is formatted:
//! ```rust
//! # #![rustfmt::skip]
//! let _ = [1, 2, 3, 4, 5];
//! ```
Another way to hide skip with a block
Source code
//! ```rust
//! # #![rustfmt::skip] {
//! let _ = [
//! 1, 2, 3,
//! 4, 5
//! ];
//! }
//! ```
No difference on save, but its a new scope so now this variable is not avaliable to unformatted code.
Rendered HTML
let _ = [
1, 2, 3,
4, 5
];
}
Contains trailing }. If you hide the closing brace rustfmt will format the list.
Using nofmt::pls!{}
Source code
//! ```rust
//! let _ = nofmt::pls! {[
//! 1, 2, 3,
//! 4, 5
//! ]};
//! ```
Rendered doc
let _ = nofmt::pls! {[
1, 2, 3,
4, 5
]};
Hiding nofmt::pls!{}
Source code
//! ```rust
//! let _ =
//! # nofmt::pls! {
//! [
//! 1, 2, 3,
//! 4, 5
//! ];
//! # }
//! ```
No change on save.
Rendered doc
let _ =
[
1, 2, 3,
4, 5
];
But this just looks weird, I want to try to put the open bracket on the same line as =. I don't want the doc to look completely unformatted, just a little bit in a subtle way so that my list is more readable.
Making nofmt::pls!{} more hidden
Source code
//! ```rust
//! let _ = [
//! # nofmt::pls! {
//! 1, 2, 3,
//! 4, 5
//! # }
//! ];
//! ```
On save:
//! ```rust
//! let _ = [
//! # nofmt::pls! {
//! 1, 2, 3, 4, 5, //#### # }
//! ];
//! ```
Ouch... I think this is realted to #6025
Versions
rustfmt 1.7.0-nightly (3246e79 2024-02-19)
cargo 1.78.0-nightly (7b7af3077 2024-02-17
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reproducing the documented examples with the reported rustfmt nightly version and compare the source and rendered documentation cases. Trace how hidden attributes, blocks, and nofmt::pls! are processed; done means the intended formatting and hiding behavior is covered consistently by regression tests.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 30/100