-
Notifications
You must be signed in to change notification settings - Fork 13.9k
Open
Labels
A-attributesArea: Attributes (`#[…]`, `#![…]`)Area: Attributes (`#[…]`, `#![…]`)A-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsD-lack-of-suggestionDiagnostics: Adding a (structured) suggestion would increase the quality of the diagnostic.Diagnostics: Adding a (structured) suggestion would increase the quality of the diagnostic.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.
Description
Code
fn example(x: bool) {
#[rustfmt::skip]
if x { print!("yea"); } else { print!("nay"); }
println!(".");
}
Current output
error[E0658]: attributes on expressions are experimental
--> src/lib.rs:2:5
|
2 | #[rustfmt::skip]
| ^^^^^^^^^^^^^^^^
Desired output
error[E0658]: attributes on some kinds of expressions are experimental
--> src/lib.rs:2:5
|
2 | #[rustfmt::skip]
| ^^^^^^^^^^^^^^^^
= help: this attribute will be allowed if the expression statement ends with a semicolon:
| if x { print!("yea"); } else { print!("nay"); };
| +
Rationale and extra context
There are two problems with this diagnostic:
- The claim is significantly false; it is not the case that all attributes on all expressions are unstable. (For example, the above code would compile if
rustfmt::skip
was replaced byallow(deprecated)
, or if the expression was a function call.) - There are simple but unintuitive workarounds available which do not require substantially refactoring the code, such as:
- Adding a semicolon to an expression-with-block statement
- Parenthesizing an assignment (surprisingly only works for some attributes, such as
allow
)
Rust Version
rustc 1.90.0 (1159e78c4 2025-09-14)
binary: rustc
commit-hash: 1159e78c4747b02ef996e55082b704c09b970588
commit-date: 2025-09-14
host: aarch64-apple-darwin
release: 1.90.0
LLVM version: 20.1.8
crumblingstatue
Metadata
Metadata
Assignees
Labels
A-attributesArea: Attributes (`#[…]`, `#![…]`)Area: Attributes (`#[…]`, `#![…]`)A-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsD-lack-of-suggestionDiagnostics: Adding a (structured) suggestion would increase the quality of the diagnostic.Diagnostics: Adding a (structured) suggestion would increase the quality of the diagnostic.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.