Skip to content

Commit b7db5bf

Browse files
committed
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
2 parents 89c282f + 0b145d6 commit b7db5bf

File tree

2 files changed

+8
-5
lines changed

2 files changed

+8
-5
lines changed

clippy_lints/src/methods/mod.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2100,8 +2100,11 @@ fn lint_clone_on_copy(cx: &LateContext<'_>, expr: &hir::Expr<'_>, arg: &hir::Exp
21002100
cx,
21012101
CLONE_DOUBLE_REF,
21022102
expr.span,
2103-
"using `clone` on a double-reference; \
2104-
this will copy the reference instead of cloning the inner type",
2103+
&format!(
2104+
"using `clone` on a double-reference; \
2105+
this will copy the reference of type `{}` instead of cloning the inner type",
2106+
ty
2107+
),
21052108
|diag| {
21062109
if let Some(snip) = sugg::Sugg::hir_opt(cx, arg) {
21072110
let mut ty = innermost;

tests/ui/unnecessary_clone.stderr

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ error: using `clone` on a `Copy` type
4444
LL | Some(t).clone();
4545
| ^^^^^^^^^^^^^^^ help: try removing the `clone` call: `Some(t)`
4646

47-
error: using `clone` on a double-reference; this will copy the reference instead of cloning the inner type
47+
error: using `clone` on a double-reference; this will copy the reference of type `&std::vec::Vec<i32>` instead of cloning the inner type
4848
--> $DIR/unnecessary_clone.rs:48:22
4949
|
5050
LL | let z: &Vec<_> = y.clone();
@@ -66,7 +66,7 @@ error: using `clone` on a `Copy` type
6666
LL | let _: E = a.clone();
6767
| ^^^^^^^^^ help: try dereferencing it: `*****a`
6868

69-
error: using `clone` on a double-reference; this will copy the reference instead of cloning the inner type
69+
error: using `clone` on a double-reference; this will copy the reference of type `&[u8]` instead of cloning the inner type
7070
--> $DIR/unnecessary_clone.rs:89:22
7171
|
7272
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
8181
LL | let _ = &mut <&[u8]>::clone(encoded);
8282
| ^^^^^^^^^^^^^^^^^^^^^^^
8383

84-
error: using `clone` on a double-reference; this will copy the reference instead of cloning the inner type
84+
error: using `clone` on a double-reference; this will copy the reference of type `&[u8]` instead of cloning the inner type
8585
--> $DIR/unnecessary_clone.rs:90:18
8686
|
8787
LL | let _ = &encoded.clone();

0 commit comments

Comments
 (0)