Skip to content

Poor formatting for function with attribute and doc comment #4398

Closed
@cdisselkoen

Description

@cdisselkoen

rustfmt un-indents the attribute in this small example. Interestingly, if either the doc comment or the inline comment are removed, rustfmt lets the attribute stay indented, which I believe to be the intuitive behavior.

Input

pub struct Struct {}

impl Struct {
    /// Documentation for `foo`
    #[rustfmt::skip] // comment on why use a skip here
    pub fn foo(&self) -> usize {
        0
    }
}

Output

pub struct Struct {}

impl Struct {
    /// Documentation for `foo`
#[rustfmt::skip] // comment on why use a skip here
    pub fn foo(&self) -> usize {
        0
    }
}

Expected output

(no change)

Meta

  • rustfmt version: Observed this behavior on both 1.4.17-stable (2020-07-20) and 1.4.20-nightly (2020-08-09)
  • From where did you install rustfmt?: rustup

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions