You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
C-bugCategory: Clippy is not doing the correct thingI-false-negativeIssue: The lint should have been triggered on code, but wasn'tL-nurseryLint: Currently in the nursery group
If f() is too expensive to compute eagerly, then of course f() + 1 must be too. However x.unwrap_or(f()) triggers or_fun_call, but x.unwrap_or(f() + 1) does not.
Lint Name
or_fun_call
Reproducer
I tried this code:
pubfnfoo(f:fn() -> i32,x:Option<i32>) -> (i32,i32){let b = x.unwrap_or(f());let c = x.unwrap_or(f() + 1);(b, c)}
warning:use of `unwrap_or` followed by a function call
--> foo.rs:2:15
|
2 | let b = x.unwrap_or(f());
| ^^^^^^^^^^^^^^ help:try: `unwrap_or_else(f)`
|
= help:for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#or_fun_call
= note: requested on the command line with `-W clippy::or-fun-call`
warning:1 warning emitted
C-bugCategory: Clippy is not doing the correct thingI-false-negativeIssue: The lint should have been triggered on code, but wasn'tL-nurseryLint: Currently in the nursery group
Summary
If
f()
is too expensive to compute eagerly, then of coursef() + 1
must be too. Howeverx.unwrap_or(f())
triggersor_fun_call
, butx.unwrap_or(f() + 1)
does not.Lint Name
or_fun_call
Reproducer
I tried this code:
clippy-driver --crate-type lib foo.rs -W clippy::or_fun_call`
I expected to see this happen:
Two similar errors.
Instead, this happened:
Version
The text was updated successfully, but these errors were encountered: