-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Open
Labels
E-hardCall for participation: This a hard problem and requires more experience or effort to work onCall for participation: This a hard problem and requires more experience or effort to work onI-false-positiveIssue: The lint was triggered on code it shouldn't haveIssue: The lint was triggered on code it shouldn't haveT-MIRType: This lint will require working with the MIRType: This lint will require working with the MIR
Description
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
dswij, greg-enbala, tamaroning, anko and Sh3Rm4n
Metadata
Metadata
Assignees
Labels
E-hardCall for participation: This a hard problem and requires more experience or effort to work onCall for participation: This a hard problem and requires more experience or effort to work onI-false-positiveIssue: The lint was triggered on code it shouldn't haveIssue: The lint was triggered on code it shouldn't haveT-MIRType: This lint will require working with the MIRType: This lint will require working with the MIR