-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Open
Labels
C-bugCategory: Clippy is not doing the correct thingCategory: Clippy is not doing the correct thingC-enhancementCategory: Enhancement of lints, like adding more cases or adding help messagesCategory: Enhancement of lints, like adding more cases or adding help messagesE-mediumCall for participation: Medium difficulty level problem and requires some initial experience.Call for participation: Medium difficulty level problem and requires some initial experience.I-false-negativeIssue: The lint should have been triggered on code, but wasn'tIssue: The lint should have been triggered on code, but wasn't
Description
Summary
needless_borrowed_reference currently only lints on shared references (e.g. &ref x), but mutable references can be linted in some cases.
Lint Name
needless_borrowed_reference
Reproducer
This should lint:
fn f(x: Option<&mut i32>) {
if let Some(&mut ref mut x) = x {
*x = 0;
}
}And suggest:
fn f(x: Option<&mut i32>) {
if let Some(x) = x {
*x = 0;
}
}Note that this can only be done if the reference can be moved. None of these should lint:
fn f(x: Option<&mut &mut i32>) {
if let Some(&mut &mut ref mut x) = x {
*x = 0;
}
}fn f(x: Option<&mut i32>) -> Option<&mut i32> {
if let Some(x) = x {
*x = 0;
}
x
}struct WithDrop<'a>(Option<&'a mut i32>);
impl Drop for WithDrop<'_> { fn drop(&mut self) {} }
fn f(x: WithDrop) {
if let Some(&mut ref mut x) = x.0 {
*x = 0;
}
}Metadata
Metadata
Assignees
Labels
C-bugCategory: Clippy is not doing the correct thingCategory: Clippy is not doing the correct thingC-enhancementCategory: Enhancement of lints, like adding more cases or adding help messagesCategory: Enhancement of lints, like adding more cases or adding help messagesE-mediumCall for participation: Medium difficulty level problem and requires some initial experience.Call for participation: Medium difficulty level problem and requires some initial experience.I-false-negativeIssue: The lint should have been triggered on code, but wasn'tIssue: The lint should have been triggered on code, but wasn't