Auto merge of #6442 - matthiaskrgr:clone-double-ref-ty, r=llogiq

clone_double_ref: print reference type in lint message

changelog: clone_double_ref: print the type of the reference in lint message
This commit is contained in:
bors 2020-12-13 10:09:00 +00:00
commit b7db5bfc50
2 changed files with 8 additions and 5 deletions

View File

@ -2100,8 +2100,11 @@ fn lint_clone_on_copy(cx: &LateContext<'_>, expr: &hir::Expr<'_>, arg: &hir::Exp
cx,
CLONE_DOUBLE_REF,
expr.span,
&format!(
"using `clone` on a double-reference; \
this will copy the reference instead of cloning the inner type",
this will copy the reference of type `{}` instead of cloning the inner type",
ty
),
|diag| {
if let Some(snip) = sugg::Sugg::hir_opt(cx, arg) {
let mut ty = innermost;

View File

@ -44,7 +44,7 @@ error: using `clone` on a `Copy` type
LL | Some(t).clone();
| ^^^^^^^^^^^^^^^ help: try removing the `clone` call: `Some(t)`
error: using `clone` on a double-reference; this will copy the reference instead of cloning the inner type
error: using `clone` on a double-reference; this will copy the reference of type `&std::vec::Vec<i32>` instead of cloning the inner type
--> $DIR/unnecessary_clone.rs:48:22
|
LL | let z: &Vec<_> = y.clone();
@ -66,7 +66,7 @@ error: using `clone` on a `Copy` type
LL | let _: E = a.clone();
| ^^^^^^^^^ help: try dereferencing it: `*****a`
error: using `clone` on a double-reference; this will copy the reference instead of cloning the inner type
error: using `clone` on a double-reference; this will copy the reference of type `&[u8]` instead of cloning the inner type
--> $DIR/unnecessary_clone.rs:89:22
|
LL | let _ = &mut encoded.clone();
@ -81,7 +81,7 @@ help: or try being explicit if you are sure, that you want to clone a reference
LL | let _ = &mut <&[u8]>::clone(encoded);
| ^^^^^^^^^^^^^^^^^^^^^^^
error: using `clone` on a double-reference; this will copy the reference instead of cloning the inner type
error: using `clone` on a double-reference; this will copy the reference of type `&[u8]` instead of cloning the inner type
--> $DIR/unnecessary_clone.rs:90:18
|
LL | let _ = &encoded.clone();