Skip to content

Commit 81a6141

Browse files
committed
uplift clippy::clone_double_ref as suspicious_double_ref_op
1 parent 0339d4e commit 81a6141

11 files changed

+61
-170
lines changed

clippy_lints/src/declared_lints.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,6 @@ pub(crate) static LINTS: &[&crate::LintInfo] = &[
313313
crate::methods::CHARS_NEXT_CMP_INFO,
314314
crate::methods::CLEAR_WITH_DRAIN_INFO,
315315
crate::methods::CLONED_INSTEAD_OF_COPIED_INFO,
316-
crate::methods::CLONE_DOUBLE_REF_INFO,
317316
crate::methods::CLONE_ON_COPY_INFO,
318317
crate::methods::CLONE_ON_REF_PTR_INFO,
319318
crate::methods::COLLAPSIBLE_STR_REPLACE_INFO,

clippy_lints/src/methods/clone_on_copy.rs

Lines changed: 2 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,13 @@
1-
use clippy_utils::diagnostics::{span_lint_and_sugg, span_lint_and_then};
1+
use clippy_utils::diagnostics::span_lint_and_sugg;
22
use clippy_utils::get_parent_node;
33
use clippy_utils::source::snippet_with_context;
4-
use clippy_utils::sugg;
54
use clippy_utils::ty::is_copy;
65
use rustc_errors::Applicability;
76
use rustc_hir::{BindingAnnotation, ByRef, Expr, ExprKind, MatchSource, Node, PatKind, QPath};
87
use rustc_lint::LateContext;
98
use rustc_middle::ty::{self, adjustment::Adjust, print::with_forced_trimmed_paths};
109
use rustc_span::symbol::{sym, Symbol};
1110

12-
use super::CLONE_DOUBLE_REF;
1311
use super::CLONE_ON_COPY;
1412

1513
/// Checks for the `CLONE_ON_COPY` lint.
@@ -42,41 +40,7 @@ pub(super) fn check(
4240

4341
let ty = cx.typeck_results().expr_ty(expr);
4442
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() {
8044
return; // don't report clone_on_copy
8145
}
8246
}

clippy_lints/src/methods/mod.rs

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -984,29 +984,6 @@ declare_clippy_lint! {
984984
"using 'clone' on a ref-counted pointer"
985985
}
986986

987-
declare_clippy_lint! {
988-
/// ### What it does
989-
/// Checks for usage of `.clone()` on an `&&T`.
990-
///
991-
/// ### Why is this bad?
992-
/// Cloning an `&&T` copies the inner `&T`, instead of
993-
/// cloning the underlying `T`.
994-
///
995-
/// ### Example
996-
/// ```rust
997-
/// fn main() {
998-
/// let x = vec![1];
999-
/// let y = &&x;
1000-
/// let z = y.clone();
1001-
/// println!("{:p} {:p}", *y, z); // prints out the same pointer
1002-
/// }
1003-
/// ```
1004-
#[clippy::version = "pre 1.29.0"]
1005-
pub CLONE_DOUBLE_REF,
1006-
correctness,
1007-
"using `clone` on `&&T`"
1008-
}
1009-
1010987
declare_clippy_lint! {
1011988
/// ### What it does
1012989
/// Checks for usage of `.to_string()` on an `&&T` where
@@ -3258,7 +3235,6 @@ impl_lint_pass!(Methods => [
32583235
CHARS_LAST_CMP,
32593236
CLONE_ON_COPY,
32603237
CLONE_ON_REF_PTR,
3261-
CLONE_DOUBLE_REF,
32623238
COLLAPSIBLE_STR_REPLACE,
32633239
ITER_OVEREAGER_CLONED,
32643240
CLONED_INSTEAD_OF_COPIED,

clippy_lints/src/renamed_lints.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ pub static RENAMED_LINTS: &[(&str, &str)] = &[
3030
("clippy::stutter", "clippy::module_name_repetitions"),
3131
("clippy::to_string_in_display", "clippy::recursive_format_impl"),
3232
("clippy::zero_width_space", "clippy::invisible_characters"),
33+
("clippy::clone_double_ref", "suspicious_double_ref_op"),
3334
("clippy::drop_bounds", "drop_bounds"),
3435
("clippy::for_loop_over_option", "for_loops_over_fallibles"),
3536
("clippy::for_loop_over_result", "for_loops_over_fallibles"),

tests/ui/explicit_deref_methods.fixed

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
#![allow(unused_variables)]
44
#![allow(
55
clippy::borrow_deref_ref,
6-
clippy::clone_double_ref,
6+
suspicious_double_ref_op,
77
clippy::explicit_auto_deref,
88
clippy::needless_borrow,
99
clippy::uninlined_format_args

tests/ui/explicit_deref_methods.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
#![allow(unused_variables)]
44
#![allow(
55
clippy::borrow_deref_ref,
6-
clippy::clone_double_ref,
6+
suspicious_double_ref_op,
77
clippy::explicit_auto_deref,
88
clippy::needless_borrow,
99
clippy::uninlined_format_args

tests/ui/rename.fixed

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
#![allow(enum_intrinsics_non_enums)]
3737
#![allow(non_fmt_panics)]
3838
#![allow(named_arguments_used_positionally)]
39+
#![allow(suspicious_double_ref_op)]
3940
#![allow(temporary_cstring_as_ptr)]
4041
#![allow(unknown_lints)]
4142
#![allow(unused_labels)]
@@ -67,6 +68,7 @@
6768
#![warn(clippy::module_name_repetitions)]
6869
#![warn(clippy::recursive_format_impl)]
6970
#![warn(clippy::invisible_characters)]
71+
#![warn(suspicious_double_ref_op)]
7072
#![warn(drop_bounds)]
7173
#![warn(for_loops_over_fallibles)]
7274
#![warn(for_loops_over_fallibles)]

tests/ui/rename.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
#![allow(enum_intrinsics_non_enums)]
3737
#![allow(non_fmt_panics)]
3838
#![allow(named_arguments_used_positionally)]
39+
#![allow(suspicious_double_ref_op)]
3940
#![allow(temporary_cstring_as_ptr)]
4041
#![allow(unknown_lints)]
4142
#![allow(unused_labels)]
@@ -67,6 +68,7 @@
6768
#![warn(clippy::stutter)]
6869
#![warn(clippy::to_string_in_display)]
6970
#![warn(clippy::zero_width_space)]
71+
#![warn(clippy::clone_double_ref)]
7072
#![warn(clippy::drop_bounds)]
7173
#![warn(clippy::for_loop_over_option)]
7274
#![warn(clippy::for_loop_over_result)]

0 commit comments

Comments
 (0)