-
Notifications
You must be signed in to change notification settings - Fork 13.9k
Closed
Labels
A-lintsArea: Lints (warnings about flaws in source code) such as unused_mut.Area: Lints (warnings about flaws in source code) such as unused_mut.
Description
Due to auto(de)ref, there are situations where calling clone() on a &T either clones the T, or the &T, depending on whether T has a Clone implementation or not.
This leads to confusing error messages in case of a missing Clone impls, especially in combination with #[deriving(Clone)].
Example
struct Foo;
let x: Foo = (&Foo).clone();Fails with
error: mismatched types: expected `main::Foo` but found `&main::Foo` (expected struct main::Foo but found &-ptr)
While this works:
struct Foo;
impl Clone for Foo { fn clone(&self) -> Foo { Foo } };
let x: Foo = (&Foo).clone();Lint
The proposed lint should catch situations where there are type errors arising from a clone() or deep_clone() call returning &T where T is expected, and recommend implementing Clone or DeepClone for T.
Metadata
Metadata
Assignees
Labels
A-lintsArea: Lints (warnings about flaws in source code) such as unused_mut.Area: Lints (warnings about flaws in source code) such as unused_mut.