Skip to content

Commit 0a141ab

Browse files
authored
fix: redundant_clone FP on enum cast (rust-lang#14395)
Closes rust-lang#10074 changelog: [`redundant_clone`]: fix FP on enum cast
2 parents c418714 + 1066ee0 commit 0a141ab

File tree

3 files changed

+31
-1
lines changed

3 files changed

+31
-1
lines changed

clippy_utils/src/mir/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ impl<'tcx> Visitor<'tcx> for V<'_> {
7676
}
7777
if matches!(
7878
ctx,
79-
PlaceContext::NonMutatingUse(NonMutatingUseContext::Move)
79+
PlaceContext::NonMutatingUse(NonMutatingUseContext::Move | NonMutatingUseContext::Inspect)
8080
| PlaceContext::MutatingUse(MutatingUseContext::Borrow)
8181
) {
8282
self.results[i].local_consume_or_mutate_locs.push(loc);

tests/ui/redundant_clone.fixed

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -259,3 +259,18 @@ fn false_negative_5707() {
259259
let _z = x.clone(); // pr 7346 can't lint on `x`
260260
drop(y);
261261
}
262+
263+
mod issue10074 {
264+
#[derive(Debug, Clone)]
265+
enum MyEnum {
266+
A = 1,
267+
}
268+
269+
fn false_positive_on_as() {
270+
let e = MyEnum::A;
271+
let v = e.clone() as u16;
272+
273+
println!("{e:?}");
274+
println!("{v}");
275+
}
276+
}

tests/ui/redundant_clone.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -259,3 +259,18 @@ fn false_negative_5707() {
259259
let _z = x.clone(); // pr 7346 can't lint on `x`
260260
drop(y);
261261
}
262+
263+
mod issue10074 {
264+
#[derive(Debug, Clone)]
265+
enum MyEnum {
266+
A = 1,
267+
}
268+
269+
fn false_positive_on_as() {
270+
let e = MyEnum::A;
271+
let v = e.clone() as u16;
272+
273+
println!("{e:?}");
274+
println!("{v}");
275+
}
276+
}

0 commit comments

Comments
 (0)