-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
False positive for or_fun_call
#1609
Comments
I thought we fixed this... |
The problem is still there. struct Zst {}
fn z(_: i32) -> Zst { Zst {} }
fn f(_: i32) -> i32 { 42 }
fn main() {
let _ = Some(Zst {}).unwrap_or(z(1));
let _ = Some(42).unwrap_or(f(1));
} Both produce Clippy warnings:
I think this warning should be suppressed (or moved to pedantic) for types that impl Version info:
|
The return type is fn request_default_value() -> i32 {
// do some network request to get the value
}
let _ = option.unwrap_or(request_default_value()); and in this case Clippy should definitely issue this warning. But I think this situation is indeed improvable. I suggest that Clippy should not issue this warning if it's a const expression, i.e. its value can be computed at compile time.
|
Seeing the reasoning for closing #5658 ; should this not be closed too? (Disclaimer: I came here wanting to report this exact same issue, and I do believe that my |
I hit this with clippy 0.0.212:
If this wasn't a constant function, it wouldn't be allowed for initialization of statics (e.g. |
@Ekleog I agree. Closing. For the original example, Clippy has no way of knowing how expensive
@Allen-Webb Building off the discussion in #5658, you could have |
I got the following message:
AIUI, this does not invoke allocations (
SeekOverflow
is a zero-sized struct (ZST) and ZSTs aren't actually allocated), and can be const-folded by the compiler. Thus, thisok_or_else
shouldn't provide benefit overok_or
.To make it a bit more obvious, here's an example that definitely doesn't invoke any allocations:
The text was updated successfully, but these errors were encountered: