-
Notifications
You must be signed in to change notification settings - Fork 898
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
presence of lint attributes changes const block formatting #6341
Comments
const block formatting was updated in the 1.7.1 release to address a different bug: #6173. It's unfortunate that the formatting for const blocks with outer attributes was impacted because of it, and it's something that was overlooked. The upside here is that const blocks now behave like other kinds of blocks when they're annotated with outer attributes. See #6106 for an example with To prevent further churn, I don't think we can go back to the one line formatting without gating the change. |
I don't have an opinion about matching the 1.80 behavior. Either format seems fine to me. But formatting the block differently depending on whether there's an attribute present seems like a bug. |
Rust 1.83 still has this problem, where the attribute causes different block formatting. Example, with attribute: impl Thing {
pub fn set() {
#[allow(clippy::assertions_on_constants)]
const {
assert!(COUNT == 5)
};
}
} Example, without attribute: impl Thing {
pub fn set() {
const { assert!(COUNT == 5) };
}
} nightly 2024-11-25 behaves the same. |
If I ask
cargo fmt
from 1.81.0 to format this code, I get:Under 1.80.0 I get:
Weirdly, if I remove the lint attribute, then both 1.81.0 and 1.80.0 format the const block on a single line.
I'm on Ubuntu 22.04, with no
rustfmt.toml
and therustfmt
versions are:The text was updated successfully, but these errors were encountered: