Skip to content

/// # #![rustfmt::skip] behaves weird #6098

Open
@max-ishere

Description

@max-ishere

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions