Skip to content

Comment in trait visibility position causes token duplication #6160

Open
@miraclx

Description

@miraclx

Just noticed some weird behaviour, not sure if it's been reported already, I tried searching but I'm not sure how to classify it

this:

pub/* (crate) */ trait MyTrait {}

gets reformatted as:

pub trait MyTrait /* (crate) */ trait MyTrait {}

Test:

$ rustfmt <<< 'pub/* (crate) */ trait MyTrait {}'
pub trait MyTrait /* (crate) */ trait MyTrait {}

Worth noting, I didn't observe this behavior with structs, enums, unions and expanding the comment's scope to include the pub, it behaves correctly with this:

/* pub (crate) */ trait MyTrait {}

getting reformatted to:

/* pub (crate) */
trait MyTrait {}

Metadata

Metadata

Assignees

No one assigned

    Labels

    a-commentsbugPanic, non-idempotency, invalid code, etc.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions