Closed
Description
In some cases suggested change regarding or_fun_call
lint does not compile. Here's an example:
struct Pair {
a: u32,
b: u32,
}
fn foo(x: u32) -> u32 { x }
fn bar(pair: &mut Pair) {
let borrow = &mut pair.a;
let b = None.unwrap_or(foo(pair.b));
}
pair
is partially borrowed. Calling id(pair.b)
is valid, because compiler can see that only field a
is borrowed, so field b
can be freely used. Clippy suggests to use unwrap_or_else
, and move function call into a closure. However, the closure will borrow pair
fully which is not possible, and the code will not compile.