Skip to content

Commit e3d2a0a

Browse files
committed
Drop uplifted clippy::drop_copy
1 parent 78ed1ef commit e3d2a0a

11 files changed

+146
-88
lines changed

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,6 @@ pub(crate) static LINTS: &[&crate::LintInfo] = &[
131131
crate::doc::NEEDLESS_DOCTEST_MAIN_INFO,
132132
crate::doc::UNNECESSARY_SAFETY_DOC_INFO,
133133
crate::double_parens::DOUBLE_PARENS_INFO,
134-
crate::drop_forget_ref::DROP_COPY_INFO,
135134
crate::drop_forget_ref::DROP_NON_DROP_INFO,
136135
crate::drop_forget_ref::FORGET_COPY_INFO,
137136
crate::drop_forget_ref::FORGET_NON_DROP_INFO,

src/tools/clippy/clippy_lints/src/drop_forget_ref.rs

Lines changed: 2 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -29,28 +29,6 @@ declare_clippy_lint! {
2929
"calls to `std::mem::forget` with a reference instead of an owned value"
3030
}
3131

32-
declare_clippy_lint! {
33-
/// ### What it does
34-
/// Checks for calls to `std::mem::drop` with a value
35-
/// that derives the Copy trait
36-
///
37-
/// ### Why is this bad?
38-
/// Calling `std::mem::drop` [does nothing for types that
39-
/// implement Copy](https://doc.rust-lang.org/std/mem/fn.drop.html), since the
40-
/// value will be copied and moved into the function on invocation.
41-
///
42-
/// ### Example
43-
/// ```rust
44-
/// let x: i32 = 42; // i32 implements Copy
45-
/// std::mem::drop(x) // A copy of x is passed to the function, leaving the
46-
/// // original unaffected
47-
/// ```
48-
#[clippy::version = "pre 1.29.0"]
49-
pub DROP_COPY,
50-
correctness,
51-
"calls to `std::mem::drop` with a value that implements Copy"
52-
}
53-
5432
declare_clippy_lint! {
5533
/// ### What it does
5634
/// Checks for calls to `std::mem::forget` with a value that
@@ -150,8 +128,6 @@ declare_clippy_lint! {
150128

151129
const FORGET_REF_SUMMARY: &str = "calls to `std::mem::forget` with a reference instead of an owned value. \
152130
Forgetting a reference does nothing";
153-
const DROP_COPY_SUMMARY: &str = "calls to `std::mem::drop` with a value that implements `Copy`. \
154-
Dropping a copy leaves the original intact";
155131
const FORGET_COPY_SUMMARY: &str = "calls to `std::mem::forget` with a value that implements `Copy`. \
156132
Forgetting a copy leaves the original intact";
157133
const DROP_NON_DROP_SUMMARY: &str = "call to `std::mem::drop` with a value that does not implement `Drop`. \
@@ -161,7 +137,6 @@ const FORGET_NON_DROP_SUMMARY: &str = "call to `std::mem::forget` with a value t
161137

162138
declare_lint_pass!(DropForgetRef => [
163139
FORGET_REF,
164-
DROP_COPY,
165140
FORGET_COPY,
166141
DROP_NON_DROP,
167142
FORGET_NON_DROP,
@@ -179,10 +154,10 @@ impl<'tcx> LateLintPass<'tcx> for DropForgetRef {
179154
let is_copy = is_copy(cx, arg_ty);
180155
let drop_is_single_call_in_arm = is_single_call_in_arm(cx, arg, expr);
181156
let (lint, msg) = match fn_name {
182-
// early return for uplifted lints: drop_ref
157+
// early return for uplifted lints: drop_ref, drop_copy
183158
sym::mem_drop if arg_ty.is_ref() && !drop_is_single_call_in_arm => return,
184159
sym::mem_forget if arg_ty.is_ref() => (FORGET_REF, FORGET_REF_SUMMARY),
185-
sym::mem_drop if is_copy && !drop_is_single_call_in_arm => (DROP_COPY, DROP_COPY_SUMMARY),
160+
sym::mem_drop if is_copy && !drop_is_single_call_in_arm => return,
186161
sym::mem_forget if is_copy => (FORGET_COPY, FORGET_COPY_SUMMARY),
187162
sym::mem_drop if is_type_lang_item(cx, arg_ty, LangItem::ManuallyDrop) => {
188163
span_lint_and_help(

src/tools/clippy/clippy_lints/src/renamed_lints.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ pub static RENAMED_LINTS: &[(&str, &str)] = &[
3131
("clippy::to_string_in_display", "clippy::recursive_format_impl"),
3232
("clippy::zero_width_space", "clippy::invisible_characters"),
3333
("clippy::drop_bounds", "drop_bounds"),
34+
("clippy::drop_copy", "drop_copy"),
3435
("clippy::drop_ref", "drop_ref"),
3536
("clippy::for_loop_over_option", "for_loops_over_fallibles"),
3637
("clippy::for_loop_over_result", "for_loops_over_fallibles"),

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#![warn(clippy::drop_copy, clippy::forget_copy)]
1+
#![warn(drop_copy, clippy::forget_copy)]
22
#![allow(clippy::toplevel_ref_arg, drop_ref, clippy::forget_ref, unused_mut)]
33

44
use std::mem::{drop, forget};

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

Lines changed: 85 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
error: calls to `std::mem::drop` with a value that implements `Copy`. Dropping a copy leaves the original intact
1+
error: call to `std::mem::drop` with a value that does not implement `Drop`. Dropping such a type only extends its contained lifetimes
22
--> $DIR/drop_forget_copy.rs:33:5
33
|
44
LL | drop(s1);
@@ -9,9 +9,9 @@ note: argument has type `SomeStruct`
99
|
1010
LL | drop(s1);
1111
| ^^
12-
= note: `-D clippy::drop-copy` implied by `-D warnings`
12+
= note: `-D clippy::drop-non-drop` implied by `-D warnings`
1313

14-
error: calls to `std::mem::drop` with a value that implements `Copy`. Dropping a copy leaves the original intact
14+
error: call to `std::mem::drop` with a value that does not implement `Drop`. Dropping such a type only extends its contained lifetimes
1515
--> $DIR/drop_forget_copy.rs:34:5
1616
|
1717
LL | drop(s2);
@@ -23,7 +23,7 @@ note: argument has type `SomeStruct`
2323
LL | drop(s2);
2424
| ^^
2525

26-
error: calls to `std::mem::drop` with a value that implements `Copy`. Dropping a copy leaves the original intact
26+
error: call to `std::mem::drop` with a value that does not implement `Drop`. Dropping such a type only extends its contained lifetimes
2727
--> $DIR/drop_forget_copy.rs:35:5
2828
|
2929
LL | drop(s3);
@@ -35,7 +35,7 @@ note: argument has type `&SomeStruct`
3535
LL | drop(s3);
3636
| ^^
3737

38-
error: calls to `std::mem::drop` with a value that implements `Copy`. Dropping a copy leaves the original intact
38+
error: call to `std::mem::drop` with a value that does not implement `Drop`. Dropping such a type only extends its contained lifetimes
3939
--> $DIR/drop_forget_copy.rs:36:5
4040
|
4141
LL | drop(s4);
@@ -47,7 +47,7 @@ note: argument has type `SomeStruct`
4747
LL | drop(s4);
4848
| ^^
4949

50-
error: calls to `std::mem::drop` with a value that implements `Copy`. Dropping a copy leaves the original intact
50+
error: call to `std::mem::drop` with a value that does not implement `Drop`. Dropping such a type only extends its contained lifetimes
5151
--> $DIR/drop_forget_copy.rs:37:5
5252
|
5353
LL | drop(s5);
@@ -96,7 +96,7 @@ note: argument has type `SomeStruct`
9696
LL | forget(s4);
9797
| ^^
9898

99-
error: calls to `std::mem::drop` with a value that implements `Copy`. Dropping a copy leaves the original intact
99+
error: call to `std::mem::drop` with a value that does not implement `Drop`. Dropping such a type only extends its contained lifetimes
100100
--> $DIR/drop_forget_copy.rs:55:5
101101
|
102102
LL | drop(a2);
@@ -108,7 +108,7 @@ note: argument has type `&AnotherStruct`
108108
LL | drop(a2);
109109
| ^^
110110

111-
error: calls to `std::mem::drop` with a value that implements `Copy`. Dropping a copy leaves the original intact
111+
error: call to `std::mem::drop` with a value that does not implement `Drop`. Dropping such a type only extends its contained lifetimes
112112
--> $DIR/drop_forget_copy.rs:57:5
113113
|
114114
LL | drop(a4);
@@ -120,7 +120,7 @@ note: argument has type `&AnotherStruct`
120120
LL | drop(a4);
121121
| ^^
122122

123-
error: calls to `std::mem::drop` with a value that implements `Copy`. Dropping a copy leaves the original intact
123+
error: call to `std::mem::drop` with a value that does not implement `Drop`. Dropping such a type only extends its contained lifetimes
124124
--> $DIR/drop_forget_copy.rs:80:13
125125
|
126126
LL | drop(println_and(13)); // Lint, even if we only care about the side-effect, it's already in a block
@@ -132,7 +132,7 @@ note: argument has type `i32`
132132
LL | drop(println_and(13)); // Lint, even if we only care about the side-effect, it's already in a block
133133
| ^^^^^^^^^^^^^^^
134134

135-
error: calls to `std::mem::drop` with a value that implements `Copy`. Dropping a copy leaves the original intact
135+
error: call to `std::mem::drop` with a value that does not implement `Drop`. Dropping such a type only extends its contained lifetimes
136136
--> $DIR/drop_forget_copy.rs:82:14
137137
|
138138
LL | 3 if drop(println_and(14)) == () => (), // Lint, idiomatic use is only in body of `Arm`
@@ -144,7 +144,7 @@ note: argument has type `i32`
144144
LL | 3 if drop(println_and(14)) == () => (), // Lint, idiomatic use is only in body of `Arm`
145145
| ^^^^^^^^^^^^^^^
146146

147-
error: calls to `std::mem::drop` with a value that implements `Copy`. Dropping a copy leaves the original intact
147+
error: call to `std::mem::drop` with a value that does not implement `Drop`. Dropping such a type only extends its contained lifetimes
148148
--> $DIR/drop_forget_copy.rs:83:14
149149
|
150150
LL | 4 => drop(2), // Lint, not a fn/method call
@@ -156,5 +156,78 @@ note: argument has type `i32`
156156
LL | 4 => drop(2), // Lint, not a fn/method call
157157
| ^
158158

159-
error: aborting due to 13 previous errors
159+
error: calls to `std::mem::drop` with a value that implements `Copy`.
160+
--> $DIR/drop_forget_copy.rs:33:5
161+
|
162+
LL | drop(s1);
163+
| ^^^^^^^^
164+
|
165+
note: argument has type `SomeStruct`
166+
--> $DIR/drop_forget_copy.rs:33:10
167+
|
168+
LL | drop(s1);
169+
| ^^
170+
= note: `-D drop-copy` implied by `-D warnings`
171+
172+
error: calls to `std::mem::drop` with a value that implements `Copy`.
173+
--> $DIR/drop_forget_copy.rs:34:5
174+
|
175+
LL | drop(s2);
176+
| ^^^^^^^^
177+
|
178+
note: argument has type `SomeStruct`
179+
--> $DIR/drop_forget_copy.rs:34:10
180+
|
181+
LL | drop(s2);
182+
| ^^
183+
184+
error: calls to `std::mem::drop` with a value that implements `Copy`.
185+
--> $DIR/drop_forget_copy.rs:36:5
186+
|
187+
LL | drop(s4);
188+
| ^^^^^^^^
189+
|
190+
note: argument has type `SomeStruct`
191+
--> $DIR/drop_forget_copy.rs:36:10
192+
|
193+
LL | drop(s4);
194+
| ^^
195+
196+
error: calls to `std::mem::drop` with a value that implements `Copy`.
197+
--> $DIR/drop_forget_copy.rs:80:13
198+
|
199+
LL | drop(println_and(13)); // Lint, even if we only care about the side-effect, it's already in a block
200+
| ^^^^^^^^^^^^^^^^^^^^^
201+
|
202+
note: argument has type `i32`
203+
--> $DIR/drop_forget_copy.rs:80:18
204+
|
205+
LL | drop(println_and(13)); // Lint, even if we only care about the side-effect, it's already in a block
206+
| ^^^^^^^^^^^^^^^
207+
208+
error: calls to `std::mem::drop` with a value that implements `Copy`.
209+
--> $DIR/drop_forget_copy.rs:82:14
210+
|
211+
LL | 3 if drop(println_and(14)) == () => (), // Lint, idiomatic use is only in body of `Arm`
212+
| ^^^^^^^^^^^^^^^^^^^^^
213+
|
214+
note: argument has type `i32`
215+
--> $DIR/drop_forget_copy.rs:82:19
216+
|
217+
LL | 3 if drop(println_and(14)) == () => (), // Lint, idiomatic use is only in body of `Arm`
218+
| ^^^^^^^^^^^^^^^
219+
220+
error: calls to `std::mem::drop` with a value that implements `Copy`.
221+
--> $DIR/drop_forget_copy.rs:83:14
222+
|
223+
LL | 4 => drop(2), // Lint, not a fn/method call
224+
| ^^^^^^^
225+
|
226+
note: argument has type `i32`
227+
--> $DIR/drop_forget_copy.rs:83:19
228+
|
229+
LL | 4 => drop(2), // Lint, not a fn/method call
230+
| ^
231+
232+
error: aborting due to 19 previous errors
160233

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
#![allow(unused)]
33
#![allow(deref_nullptr)]
44
#![allow(clippy::unnecessary_operation)]
5-
#![allow(clippy::drop_copy)]
5+
#![allow(drop_copy)]
66
#![warn(clippy::multiple_unsafe_ops_per_block)]
77

88
extern crate proc_macros;

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
#![allow(clippy::recursive_format_impl)]
2929
#![allow(clippy::invisible_characters)]
3030
#![allow(drop_bounds)]
31+
#![allow(drop_copy)]
3132
#![allow(drop_ref)]
3233
#![allow(for_loops_over_fallibles)]
3334
#![allow(array_into_iter)]
@@ -69,6 +70,7 @@
6970
#![warn(clippy::recursive_format_impl)]
7071
#![warn(clippy::invisible_characters)]
7172
#![warn(drop_bounds)]
73+
#![warn(drop_copy)]
7274
#![warn(drop_ref)]
7375
#![warn(for_loops_over_fallibles)]
7476
#![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
@@ -28,6 +28,7 @@
2828
#![allow(clippy::recursive_format_impl)]
2929
#![allow(clippy::invisible_characters)]
3030
#![allow(drop_bounds)]
31+
#![allow(drop_copy)]
3132
#![allow(drop_ref)]
3233
#![allow(for_loops_over_fallibles)]
3334
#![allow(array_into_iter)]
@@ -69,6 +70,7 @@
6970
#![warn(clippy::to_string_in_display)]
7071
#![warn(clippy::zero_width_space)]
7172
#![warn(clippy::drop_bounds)]
73+
#![warn(clippy::drop_copy)]
7274
#![warn(clippy::drop_ref)]
7375
#![warn(clippy::for_loop_over_option)]
7476
#![warn(clippy::for_loop_over_result)]

0 commit comments

Comments
 (0)