Skip to content

#[rustfmt::skip] is ignored in struct impl. #4499

Open
@phi-gamma

Description

@phi-gamma

Describe the bug

Using #[rustfmt::skip] to prevent damage to comments doesn’t work if the comment is
inside a struct impl.

To Reproduce

#[rustfmt::skip]
/** Comment.

    Rustfmt skips this as expected. */
fn main() {
    for _ in 1..Foo::getRandomNumber() {
        println!("Hello, world!");
    }
}

struct Foo;

impl Foo {
    #[rustfmt::skip]
    /** Comment.

        Rustfmt unindents this despite the ::skip above. */
    #[allow(non_snake_case)]
    pub fn getRandomNumber() -> i32 { 4 }
}

Expected behavior

The comment on getRandomNumber() should be left alone.

Meta

  • rustfmt version: 1.4.20-stable
  • From where did you install rustfmt?: from the Fedora 32 repos.
  • How do you run rustfmt: doesn’t matter, both cargo fmt and rustfmt show the same defect.

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