-
Notifications
You must be signed in to change notification settings - Fork 13.3k
unnecessary_parens
false positive when calling function from match
#90456
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
Comments
This is interesting because pub enum Repro {
A(i64),
B(i64),
}
fn make(a: bool, data: i64) -> Repro {
let enum_variant_constructor_fn_ptr: fn(i64) -> Repro = match a {
true => Repro::A,
false => Repro::B,
};
enum_variant_constructor_fn_ptr(data)
} is fine, and pub enum Repro {
A(i64),
B(i64),
}
fn make(a: bool, data: i64) -> Repro {
(match a {
true => Repro::A,
false => Repro::B,
})(data)
} is also fine since enum variants are? fn-pointers I think the issue here is not warning the user with a
There's caveats to this too: consider zero-variant enums: enum Never {}
fn test() -> Never {
match true {
_ => Never
}()
} do not trigger this combo:
So smaller examples that triggers this combo... ...with 1-variant enum: enum Single {
A(())
}
fn test() -> Single {
match true {
_ => Single::A
}(())
} ...or with tuple-struct: struct A(());
fn test() -> A {
match true {
_ => A
}(())
} since their variant/member initializer fns can be cast? into fn pointers. |
Looks like a duplicate of #88519. |
Thanks for the report! Yea, I believe this is a duplicate of #88519, and should be fixed in 1.57. |
Rust Information
rustc --version
:rustc 1.55.0-nightly (gentoo)
rustfmt --version
:rustfmt 1.4.37-nightly ( )
cargo --version
:cargo 1.55.0-nightly
rust-analyzer version:
v0.3.794 preview
(nightly mode is enabled)Repro
Issue
When I write my code as suggested, I get a warning for putting parenthesis around this match statement:
However, upon doing what the warning says, I am then greeted with a compiler error (the error persists if I put the parenthesis next to the closing brace of the match statement, as expected)
The text was updated successfully, but these errors were encountered: