Skip to content

Commit f89f190

Browse files
committed
clippy changes to uplift and remove lint
1 parent f9dde4b commit f89f190

13 files changed

+90
-133
lines changed

src/tools/clippy/clippy_dev/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ extern crate rustc_lexer;
1212

1313
use std::path::PathBuf;
1414

15-
pub mod bless;
15+
pub mod bless
1616
pub mod dogfood;
1717
pub mod fmt;
1818
pub mod lint;

src/tools/clippy/clippy_lints/src/declared_lints.rs

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

src/tools/clippy/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
}

src/tools/clippy/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,

src/tools/clippy/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", "clone_double_ref"),
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"),

src/tools/clippy/tests/ui/deprecated.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,6 @@
1818
#![warn(clippy::filter_map)]
1919
#![warn(clippy::pub_enum_variant_names)]
2020
#![warn(clippy::wrong_pub_self_convention)]
21+
#![warn(clippy::clone_double_ref)]
2122

2223
fn main() {}

src/tools/clippy/tests/ui/deprecated.stderr

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,5 +96,11 @@ error: lint `clippy::wrong_pub_self_convention` has been removed: set the `avoid
9696
LL | #![warn(clippy::wrong_pub_self_convention)]
9797
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
9898

99-
error: aborting due to 16 previous errors
99+
error: lint `clippy::clone_double_ref` has been renamed to `clone_double_ref`
100+
--> $DIR/deprecated.rs:21:9
101+
|
102+
LL | #![warn(clippy::clone_double_ref)]
103+
| ^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clone_double_ref`
104+
105+
error: aborting due to 17 previous errors
100106

src/tools/clippy/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+
clone_double_ref,
77
clippy::explicit_auto_deref,
88
clippy::needless_borrow,
99
clippy::uninlined_format_args

src/tools/clippy/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+
clone_double_ref,
77
clippy::explicit_auto_deref,
88
clippy::needless_borrow,
99
clippy::uninlined_format_args

src/tools/clippy/tests/ui/rename.fixed

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
#![allow(clippy::module_name_repetitions)]
2828
#![allow(clippy::recursive_format_impl)]
2929
#![allow(clippy::invisible_characters)]
30+
#![allow(clone_double_ref)]
3031
#![allow(drop_bounds)]
3132
#![allow(for_loops_over_fallibles)]
3233
#![allow(array_into_iter)]
@@ -67,6 +68,7 @@
6768
#![warn(clippy::module_name_repetitions)]
6869
#![warn(clippy::recursive_format_impl)]
6970
#![warn(clippy::invisible_characters)]
71+
#![warn(clone_double_ref)]
7072
#![warn(drop_bounds)]
7173
#![warn(for_loops_over_fallibles)]
7274
#![warn(for_loops_over_fallibles)]

src/tools/clippy/tests/ui/rename.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
#![allow(clippy::module_name_repetitions)]
2828
#![allow(clippy::recursive_format_impl)]
2929
#![allow(clippy::invisible_characters)]
30+
#![allow(clone_double_ref)]
3031
#![allow(drop_bounds)]
3132
#![allow(for_loops_over_fallibles)]
3233
#![allow(array_into_iter)]
@@ -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)