Skip to content

Commit b33d6ea

Browse files
committed
Drop uplifted clippy::drop_ref
1 parent 6978147 commit b33d6ea

File tree

10 files changed

+106
-318
lines changed

10 files changed

+106
-318
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
@@ -133,7 +133,6 @@ pub(crate) static LINTS: &[&crate::LintInfo] = &[
133133
crate::double_parens::DOUBLE_PARENS_INFO,
134134
crate::drop_forget_ref::DROP_COPY_INFO,
135135
crate::drop_forget_ref::DROP_NON_DROP_INFO,
136-
crate::drop_forget_ref::DROP_REF_INFO,
137136
crate::drop_forget_ref::FORGET_COPY_INFO,
138137
crate::drop_forget_ref::FORGET_NON_DROP_INFO,
139138
crate::drop_forget_ref::FORGET_REF_INFO,

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

Lines changed: 2 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -7,30 +7,6 @@ use rustc_lint::{LateContext, LateLintPass};
77
use rustc_session::{declare_lint_pass, declare_tool_lint};
88
use rustc_span::sym;
99

10-
declare_clippy_lint! {
11-
/// ### What it does
12-
/// Checks for calls to `std::mem::drop` with a reference
13-
/// instead of an owned value.
14-
///
15-
/// ### Why is this bad?
16-
/// Calling `drop` on a reference will only drop the
17-
/// reference itself, which is a no-op. It will not call the `drop` method (from
18-
/// the `Drop` trait implementation) on the underlying referenced value, which
19-
/// is likely what was intended.
20-
///
21-
/// ### Example
22-
/// ```ignore
23-
/// let mut lock_guard = mutex.lock();
24-
/// std::mem::drop(&lock_guard) // Should have been drop(lock_guard), mutex
25-
/// // still locked
26-
/// operation_that_requires_mutex_to_be_unlocked();
27-
/// ```
28-
#[clippy::version = "pre 1.29.0"]
29-
pub DROP_REF,
30-
correctness,
31-
"calls to `std::mem::drop` with a reference instead of an owned value"
32-
}
33-
3410
declare_clippy_lint! {
3511
/// ### What it does
3612
/// Checks for calls to `std::mem::forget` with a reference
@@ -172,8 +148,6 @@ declare_clippy_lint! {
172148
"use of safe `std::mem::drop` function to drop a std::mem::ManuallyDrop, which will not drop the inner value"
173149
}
174150

175-
const DROP_REF_SUMMARY: &str = "calls to `std::mem::drop` with a reference instead of an owned value. \
176-
Dropping a reference does nothing";
177151
const FORGET_REF_SUMMARY: &str = "calls to `std::mem::forget` with a reference instead of an owned value. \
178152
Forgetting a reference does nothing";
179153
const DROP_COPY_SUMMARY: &str = "calls to `std::mem::drop` with a value that implements `Copy`. \
@@ -186,7 +160,6 @@ const FORGET_NON_DROP_SUMMARY: &str = "call to `std::mem::forget` with a value t
186160
Forgetting such a type is the same as dropping it";
187161

188162
declare_lint_pass!(DropForgetRef => [
189-
DROP_REF,
190163
FORGET_REF,
191164
DROP_COPY,
192165
FORGET_COPY,
@@ -206,7 +179,8 @@ impl<'tcx> LateLintPass<'tcx> for DropForgetRef {
206179
let is_copy = is_copy(cx, arg_ty);
207180
let drop_is_single_call_in_arm = is_single_call_in_arm(cx, arg, expr);
208181
let (lint, msg) = match fn_name {
209-
sym::mem_drop if arg_ty.is_ref() && !drop_is_single_call_in_arm => (DROP_REF, DROP_REF_SUMMARY),
182+
// early return for uplifted lints: drop_ref
183+
sym::mem_drop if arg_ty.is_ref() && !drop_is_single_call_in_arm => return,
210184
sym::mem_forget if arg_ty.is_ref() => (FORGET_REF, FORGET_REF_SUMMARY),
211185
sym::mem_drop if is_copy && !drop_is_single_call_in_arm => (DROP_COPY, DROP_COPY_SUMMARY),
212186
sym::mem_forget if is_copy => (FORGET_COPY, FORGET_COPY_SUMMARY),

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_ref", "drop_ref"),
3435
("clippy::for_loop_over_option", "for_loops_over_fallibles"),
3536
("clippy::for_loop_over_result", "for_loops_over_fallibles"),
3637
("clippy::for_loops_over_fallibles", "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,5 +1,5 @@
11
#![warn(clippy::drop_copy, clippy::forget_copy)]
2-
#![allow(clippy::toplevel_ref_arg, clippy::drop_ref, clippy::forget_ref, unused_mut)]
2+
#![allow(clippy::toplevel_ref_arg, drop_ref, clippy::forget_ref, unused_mut)]
33

44
use std::mem::{drop, forget};
55
use std::vec::Vec;

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

Lines changed: 49 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,18 @@ 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
27+
--> $DIR/drop_forget_copy.rs:35:5
28+
|
29+
LL | drop(s3);
30+
| ^^^^^^^^
31+
|
32+
note: argument has type `&SomeStruct`
33+
--> $DIR/drop_forget_copy.rs:35:10
34+
|
35+
LL | drop(s3);
36+
| ^^
37+
2638
error: calls to `std::mem::drop` with a value that implements `Copy`. Dropping a copy leaves the original intact
2739
--> $DIR/drop_forget_copy.rs:36:5
2840
|
@@ -35,6 +47,18 @@ note: argument has type `SomeStruct`
3547
LL | drop(s4);
3648
| ^^
3749

50+
error: calls to `std::mem::drop` with a value that implements `Copy`. Dropping a copy leaves the original intact
51+
--> $DIR/drop_forget_copy.rs:37:5
52+
|
53+
LL | drop(s5);
54+
| ^^^^^^^^
55+
|
56+
note: argument has type `&SomeStruct`
57+
--> $DIR/drop_forget_copy.rs:37:10
58+
|
59+
LL | drop(s5);
60+
| ^^
61+
3862
error: calls to `std::mem::forget` with a value that implements `Copy`. Forgetting a copy leaves the original intact
3963
--> $DIR/drop_forget_copy.rs:39:5
4064
|
@@ -72,6 +96,30 @@ note: argument has type `SomeStruct`
7296
LL | forget(s4);
7397
| ^^
7498

99+
error: calls to `std::mem::drop` with a value that implements `Copy`. Dropping a copy leaves the original intact
100+
--> $DIR/drop_forget_copy.rs:55:5
101+
|
102+
LL | drop(a2);
103+
| ^^^^^^^^
104+
|
105+
note: argument has type `&AnotherStruct`
106+
--> $DIR/drop_forget_copy.rs:55:10
107+
|
108+
LL | drop(a2);
109+
| ^^
110+
111+
error: calls to `std::mem::drop` with a value that implements `Copy`. Dropping a copy leaves the original intact
112+
--> $DIR/drop_forget_copy.rs:57:5
113+
|
114+
LL | drop(a4);
115+
| ^^^^^^^^
116+
|
117+
note: argument has type `&AnotherStruct`
118+
--> $DIR/drop_forget_copy.rs:57:10
119+
|
120+
LL | drop(a4);
121+
| ^^
122+
75123
error: calls to `std::mem::drop` with a value that implements `Copy`. Dropping a copy leaves the original intact
76124
--> $DIR/drop_forget_copy.rs:80:13
77125
|
@@ -108,5 +156,5 @@ note: argument has type `i32`
108156
LL | 4 => drop(2), // Lint, not a fn/method call
109157
| ^
110158

111-
error: aborting due to 9 previous errors
159+
error: aborting due to 13 previous errors
112160

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

Lines changed: 0 additions & 97 deletions
This file was deleted.

0 commit comments

Comments
 (0)