-
Notifications
You must be signed in to change notification settings - Fork 850
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
Adding an attribute to an unsafe
block changes its formatting
#6106
Comments
A similar issue has popped up in other cases too. #5901 and #5662 immediately come to mind, but there might be others in the backlog. I haven't looked into this, but my hunch is that rustfmt considers the newline between the attribute and the block as an indication that the block can't be written on one line. |
I'm assuming this affects all blocks, not just unsafe blocks? What about async blocks for example? |
Good call, looks like fn main() {
// #[cfg(not(fake_flag))]
async { println!() };
} fn main() {
#[cfg(not(fake_flag))]
async {
println!()
};
} Probably indeed the same issue as #5662 so close this if you see fit. I just noticed because the diff for rust-lang/rust#121894 looked kind of funny :) |
I think its the same underlying problem as #5662, but it's occurring in a different parts of the codebase. rustfmt rewrites attrs before rewriting the AST node those attrs are associated with so I think this is a distinct issue to the others I linked. |
This is the
rustfmt
result for anunsafe
block:But uncomment the attribute, and it reformats it as:
Changing the attribute probably should not change the formatting.
rustfmt 1.7.0-nightly (5119208f 2024-03-02)
The text was updated successfully, but these errors were encountered: