|
1 |
| -use clippy_utils::diagnostics::{span_lint_and_sugg, span_lint_and_then}; |
| 1 | +use clippy_utils::diagnostics::span_lint_and_sugg; |
2 | 2 | use clippy_utils::get_parent_node;
|
3 | 3 | use clippy_utils::source::snippet_with_context;
|
4 |
| -use clippy_utils::sugg; |
5 | 4 | use clippy_utils::ty::is_copy;
|
6 | 5 | use rustc_errors::Applicability;
|
7 | 6 | use rustc_hir::{BindingAnnotation, ByRef, Expr, ExprKind, MatchSource, Node, PatKind, QPath};
|
8 | 7 | use rustc_lint::LateContext;
|
9 | 8 | use rustc_middle::ty::{self, adjustment::Adjust, print::with_forced_trimmed_paths};
|
10 | 9 | use rustc_span::symbol::{sym, Symbol};
|
11 | 10 |
|
12 |
| -use super::CLONE_DOUBLE_REF; |
13 | 11 | use super::CLONE_ON_COPY;
|
14 | 12 |
|
15 | 13 | /// Checks for the `CLONE_ON_COPY` lint.
|
@@ -42,41 +40,7 @@ pub(super) fn check(
|
42 | 40 |
|
43 | 41 | let ty = cx.typeck_results().expr_ty(expr);
|
44 | 42 | if let ty::Ref(_, inner, _) = arg_ty.kind() {
|
45 |
| - if let ty::Ref(_, innermost, _) = inner.kind() { |
46 |
| - span_lint_and_then( |
47 |
| - cx, |
48 |
| - CLONE_DOUBLE_REF, |
49 |
| - expr.span, |
50 |
| - &with_forced_trimmed_paths!(format!( |
51 |
| - "using `clone` on a double-reference; \ |
52 |
| - this will copy the reference of type `{ty}` instead of cloning the inner type" |
53 |
| - )), |
54 |
| - |diag| { |
55 |
| - if let Some(snip) = sugg::Sugg::hir_opt(cx, arg) { |
56 |
| - let mut ty = innermost; |
57 |
| - let mut n = 0; |
58 |
| - while let ty::Ref(_, inner, _) = ty.kind() { |
59 |
| - ty = inner; |
60 |
| - n += 1; |
61 |
| - } |
62 |
| - let refs = "&".repeat(n + 1); |
63 |
| - let derefs = "*".repeat(n); |
64 |
| - let explicit = with_forced_trimmed_paths!(format!("<{refs}{ty}>::clone({snip})")); |
65 |
| - diag.span_suggestion( |
66 |
| - expr.span, |
67 |
| - "try dereferencing it", |
68 |
| - with_forced_trimmed_paths!(format!("{refs}({derefs}{}).clone()", snip.deref())), |
69 |
| - Applicability::MaybeIncorrect, |
70 |
| - ); |
71 |
| - diag.span_suggestion( |
72 |
| - expr.span, |
73 |
| - "or try being explicit if you are sure, that you want to clone a reference", |
74 |
| - explicit, |
75 |
| - Applicability::MaybeIncorrect, |
76 |
| - ); |
77 |
| - } |
78 |
| - }, |
79 |
| - ); |
| 43 | + if let ty::Ref(..) = inner.kind() { |
80 | 44 | return; // don't report clone_on_copy
|
81 | 45 | }
|
82 | 46 | }
|
|
0 commit comments