-
Notifications
You must be signed in to change notification settings - Fork 13.9k
Description
I tried this code:
#![feature(stmt_expr_attributes)]
#![allow(unused_must_use)]
pub fn foo() -> impl Fn() {
let _ = (#[inline] || println!("Hello!"));
(#[inline] || println!("Hello!"));
(#[inline] || println!("Hello!"))
}I expected to see this happen: The unused_parens warning fires on all three lines of foo, and the suggestions should only suggest removing the parentheses, not the attribute also.
Instead, this happened: The unused_parens fires on the first and last lines of foo, and the suggestion also removes the #[inline].
No unused_parens warning fires on the second line (#[inline] || println!("Hello!")); (but this is probably a separate issue, unrelated to attributes; it happens even when the attribute is removed; maybe unused_must_use overrides it or something).
warning: unnecessary parentheses around assigned value
--> a.rs:5:13
|
5 | let _ = (#[inline] || println!("Hello!"));
| ^^^^^^^^^^^ ^
|
= note: `#[warn(unused_parens)]` on by default
help: remove these parentheses
|
5 - let _ = (#[inline] || println!("Hello!"));
5 + let _ = || println!("Hello!");
|
warning: unnecessary parentheses around block return value
--> a.rs:7:5
|
7 | (#[inline] || println!("Hello!"))
| ^^^^^^^^^^^ ^
|
help: remove these parentheses
|
7 - (#[inline] || println!("Hello!"))
7 + || println!("Hello!")
|
warning: 2 warnings emittedMeta
rustc --version --verbose:
rustc 1.82.0-nightly (0d634185d 2024-08-29)
binary: rustc
commit-hash: 0d634185dfddefe09047881175f35c65d68dcff1
commit-date: 2024-08-29
host: x86_64-unknown-linux-gnu
release: 1.82.0-nightly
LLVM version: 19.1.0
Requires use of #![feature(stmt_expr_attributes)], otherwise the #[inline] is not legal in that position (though note that the unused_parens warning and suggestion is the same on stable, there's just an error[E0658]: attributes on expressions are experimental first).
The issue is not specific to closures and #[inline], but that was the simplest example of a reasonable attribute-on-expression I thought of.
@rustbot label +A-diagnostics +requires-nightly