Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
dtolnay opened this issue Aug 20, 2021 · 3 comments · Fixed by #4961
Closed

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

dtolnay opened this issue Aug 20, 2021 · 3 comments · Fixed by #4961
Labels
2x-port:pending bug Panic, non-idempotency, invalid code, etc.

Comments

@dtolnay
Copy link
Member

dtolnay commented Aug 20, 2021

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

@dtolnay
Copy link
Member Author

dtolnay commented Aug 20, 2021

Use case: I hit this in https://github.com/dtolnay/inherent.

@upsuper
Copy link

upsuper commented Aug 21, 2021

I believe this is a duplicate of #4631.

@calebcartwright
Copy link
Member

I believe this is a duplicate of #4631.

No, it isn't.

There is indeed some symptom similarity, but there are also fundamental differences. Crucially, this issue reporting the impact on associated items as valid Rust code vs. #4631 being about call args to macros where folks opt to use the delimiters that instruct rustfmt to format the args as their valid Rust code counterparts if they can be parsed as such.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
2x-port:pending bug Panic, non-idempotency, invalid code, etc.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants