Open
Description
Code
pub struct NotClone {}
pub fn foo(v: &Vec<NotClone>) {
let _v = v.clone();
}
Current output
warning: call to `.clone()` on a reference in this situation does nothing
--> src/lib.rs:4:15
|
4 | let _v = v.clone();
| ^^^^^^^^
|
= note: the type `Vec<NotClone>` does not implement `Clone`, so calling `clone` on `&Vec<NotClone>` copies the reference, which does not do anything and can be removed
= note: `#[warn(noop_method_call)]` on by default
help: remove this redundant call
|
4 - let _v = v.clone();
4 + let _v = v;
|
help: if you meant to clone `Vec<NotClone>`, implement `Clone` for it
--> /playground/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/alloc/src/vec/mod.rs:397:1
|
39+ #[derive(Clone)]
39| pub struct Vec<T, #[unstable(feature = "allocator_api", issue = "32838")] A: Allocator = Global> {
|
Desired output
warning: call to `.clone()` on a reference in this situation does nothing
--> src/lib.rs:4:15
|
4 | let _v = v.clone();
| ^^^^^^^^
|
= note: the type `Vec<NotClone>` does not implement `Clone`, so calling `clone` on `&Vec<NotClone>` copies the reference, which does not do anything and can be removed
= note: `#[warn(noop_method_call)]` on by default
help: remove this redundant call
|
4 - let _v = v.clone();
4 + let _v = v;
|
help: if you meant to clone `Vec<NotClone>`, implement `Clone` for it
--> /playground/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/alloc/src/vec/mod.rs:397:1
|
1+ #[derive(Clone)]
2| pub struct NotClone {}
|
Rationale and extra context
Encountered this while investigating around #134467. Obviously the derive
is placed at the wrong place.
Other cases
Rust Version
1.85.0-nightly
(2024-12-17 a4cb3c831823d9baa56c)
Anything else?
No response