Open
Description
openedon Jan 24, 2022
Description
This affects any lint where we recommend moving code into a closure. Off the top of my head are manual_map
, option_if_let_else
, and map_entry
, but there are probably more.
Given the following code:
let mut x = 0;
let ref_x = &mut x;
let _ = match Some(0) {
Some(y) => Some({
*ref_x = y;
some_fn_call(&mut x) + y
}),
None => None,
};
Clippy will suggest to use Option::map
let _ = Some(0).map(|y| {
*ref_x = y;
some_fn_call(&mut x) + y
});
This will fail with multiple mutable borrows of x
due to the closure capturing both ref_x
and x
. The original code would have the borrow held by ref_x
end right before x
is borrowed for some_fn_call
.
Solving this would require the lifetimes computed by borrowck which I don't believe we have easy access to. It may also require turning these as MIR lints.
Version
No response
Additional Labels
@rustbot label +I-false-positive
@rustbot label +E-hard
@rustbot label +T-MIR
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment