Skip to content

Rustfmt loses visibility on some trait items and impl items #4960

@dtolnay

Description

@dtolnay

As of current master, rustfmt applies the following incorrect diff to this valid Rust code.

 #[cfg(any())]
 trait Visible {
-    pub const C: i32;
+    const C: i32;
     pub type T;
-    pub fn f();
+    fn f();
-    pub fn g() {}
+    fn g() {}
 }

 #[cfg(any())]
 impl Visible for Bar {
     pub const C: i32;
     pub type T;
-    pub fn f();
+    fn f();
     pub fn g() {}
 }

To reproduce: cargo run --bin rustfmt repro.rs

Metadata

Metadata

Assignees

No one assigned

    Labels

    2x-port:pendingC-bugCategory: this is a bug; use also I-* labels for specific bug kinds, e.g. I-non-idempotency or I-ICE

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions