Fix suggestion for multiple derefs
This commit is contained in:
parent
a2be050965
commit
2a9dec681f
3 changed files with 52 additions and 3 deletions
|
|
@ -79,3 +79,35 @@ fn iter_clone_collect() {
|
|||
let v3 : HashSet<isize> = v.iter().cloned().collect();
|
||||
let v4 : VecDeque<isize> = v.iter().cloned().collect();
|
||||
}
|
||||
|
||||
mod many_derefs {
|
||||
struct A;
|
||||
struct B;
|
||||
struct C;
|
||||
struct D;
|
||||
#[derive(Copy, Clone)]
|
||||
struct E;
|
||||
|
||||
macro_rules! impl_deref {
|
||||
($src:ident, $dst:ident) => {
|
||||
impl std::ops::Deref for $src {
|
||||
type Target = $dst;
|
||||
fn deref(&self) -> &Self::Target { &$dst }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl_deref!(A, B);
|
||||
impl_deref!(B, C);
|
||||
impl_deref!(C, D);
|
||||
impl std::ops::Deref for D {
|
||||
type Target = &'static E;
|
||||
fn deref(&self) -> &Self::Target { &&E }
|
||||
}
|
||||
|
||||
fn go1() {
|
||||
let a = A;
|
||||
let _: E = a.clone();
|
||||
let _: E = *****a;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -86,5 +86,11 @@ error: called `cloned().collect()` on a slice to create a `Vec`. Calling `to_vec
|
|||
|
|
||||
= note: `-D clippy::iter-cloned-collect` implied by `-D warnings`
|
||||
|
||||
error: aborting due to 12 previous errors
|
||||
error: using `clone` on a `Copy` type
|
||||
--> $DIR/unnecessary_clone.rs:110:20
|
||||
|
|
||||
110 | let _: E = a.clone();
|
||||
| ^^^^^^^^^ help: try dereferencing it: `*****a`
|
||||
|
||||
error: aborting due to 13 previous errors
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue