-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Closed
Labels
C-bugCategory: Clippy is not doing the correct thingCategory: Clippy is not doing the correct thingI-false-positiveIssue: The lint was triggered on code it shouldn't haveIssue: The lint was triggered on code it shouldn't have
Description
Summary
Casting an enum consumes it, but clippy doesn't seem to agree. Applying the suggested fix makes it impossible to compile the code.
Lint Name
redundant_clone
Reproducer
I tried this code:
#[derive(Debug, Clone)]
enum MyEnum {
A = 1,
}
fn main() {
let e = MyEnum::A;
let v = e.clone() as u16;
println!("{e:?}");
println!("{v}");
}I saw this happen:
Checking playground v0.0.1 (/playground)
warning: redundant clone
--> src/main.rs:9:14
|
9 | let v = e.clone() as u16;
| ^^^^^^^^ help: remove this
|
note: cloned value is neither consumed nor mutated
--> src/main.rs:9:13
|
9 | let v = e.clone() as u16;
| ^^^^^^^^^
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#redundant_clone
= note: `#[warn(clippy::redundant_clone)]` on by default
warning: `playground` (bin "playground") generated 1 warning (run `cargo fix --bin "playground"` to apply 1 suggestion)
Finished dev [unoptimized + debuginfo] target(s) in 0.46s
I expected to see this happen:
No warning
Version
1.65.0 (rust playground)
Additional Labels
No response
ericwu17
Metadata
Metadata
Assignees
Labels
C-bugCategory: Clippy is not doing the correct thingCategory: Clippy is not doing the correct thingI-false-positiveIssue: The lint was triggered on code it shouldn't haveIssue: The lint was triggered on code it shouldn't have