Skip to content

Commit bc07f57

Browse files
committed
Drop uplifted clippy::forget_ref
1 parent b91a4e9 commit bc07f57

File tree

10 files changed

+120
-236
lines changed

10 files changed

+120
-236
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
@@ -134,7 +134,6 @@ pub(crate) static LINTS: &[&crate::LintInfo] = &[
134134
crate::drop_forget_ref::DROP_NON_DROP_INFO,
135135
crate::drop_forget_ref::FORGET_COPY_INFO,
136136
crate::drop_forget_ref::FORGET_NON_DROP_INFO,
137-
crate::drop_forget_ref::FORGET_REF_INFO,
138137
crate::drop_forget_ref::UNDROPPED_MANUALLY_DROPS_INFO,
139138
crate::duplicate_mod::DUPLICATE_MOD_INFO,
140139
crate::else_if_without_else::ELSE_IF_WITHOUT_ELSE_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
@@ -7,28 +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::forget` with a reference
13-
/// instead of an owned value.
14-
///
15-
/// ### Why is this bad?
16-
/// Calling `forget` on a reference will only forget the
17-
/// reference itself, which is a no-op. It will not forget the underlying
18-
/// referenced
19-
/// value, which is likely what was intended.
20-
///
21-
/// ### Example
22-
/// ```rust
23-
/// let x = Box::new(1);
24-
/// std::mem::forget(&x) // Should have been forget(x), x will still be dropped
25-
/// ```
26-
#[clippy::version = "pre 1.29.0"]
27-
pub FORGET_REF,
28-
correctness,
29-
"calls to `std::mem::forget` with a reference instead of an owned value"
30-
}
31-
3210
declare_clippy_lint! {
3311
/// ### What it does
3412
/// Checks for calls to `std::mem::forget` with a value that
@@ -126,8 +104,6 @@ declare_clippy_lint! {
126104
"use of safe `std::mem::drop` function to drop a std::mem::ManuallyDrop, which will not drop the inner value"
127105
}
128106

129-
const FORGET_REF_SUMMARY: &str = "calls to `std::mem::forget` with a reference instead of an owned value. \
130-
Forgetting a reference does nothing";
131107
const FORGET_COPY_SUMMARY: &str = "calls to `std::mem::forget` with a value that implements `Copy`. \
132108
Forgetting a copy leaves the original intact";
133109
const DROP_NON_DROP_SUMMARY: &str = "call to `std::mem::drop` with a value that does not implement `Drop`. \
@@ -136,7 +112,6 @@ const FORGET_NON_DROP_SUMMARY: &str = "call to `std::mem::forget` with a value t
136112
Forgetting such a type is the same as dropping it";
137113

138114
declare_lint_pass!(DropForgetRef => [
139-
FORGET_REF,
140115
FORGET_COPY,
141116
DROP_NON_DROP,
142117
FORGET_NON_DROP,
@@ -154,9 +129,9 @@ impl<'tcx> LateLintPass<'tcx> for DropForgetRef {
154129
let is_copy = is_copy(cx, arg_ty);
155130
let drop_is_single_call_in_arm = is_single_call_in_arm(cx, arg, expr);
156131
let (lint, msg) = match fn_name {
157-
// early return for uplifted lints: drop_ref, drop_copy
132+
// early return for uplifted lints: drop_ref, drop_copy, forget_ref
158133
sym::mem_drop if arg_ty.is_ref() && !drop_is_single_call_in_arm => return,
159-
sym::mem_forget if arg_ty.is_ref() => (FORGET_REF, FORGET_REF_SUMMARY),
134+
sym::mem_forget if arg_ty.is_ref() => return,
160135
sym::mem_drop if is_copy && !drop_is_single_call_in_arm => return,
161136
sym::mem_forget if is_copy => (FORGET_COPY, FORGET_COPY_SUMMARY),
162137
sym::mem_drop if is_type_lang_item(cx, arg_ty, LangItem::ManuallyDrop) => {

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ pub static RENAMED_LINTS: &[(&str, &str)] = &[
3636
("clippy::for_loop_over_option", "for_loops_over_fallibles"),
3737
("clippy::for_loop_over_result", "for_loops_over_fallibles"),
3838
("clippy::for_loops_over_fallibles", "for_loops_over_fallibles"),
39+
("clippy::forget_ref", "forget_ref"),
3940
("clippy::into_iter_on_array", "array_into_iter"),
4041
("clippy::invalid_atomic_ordering", "invalid_atomic_ordering"),
4142
("clippy::invalid_ref", "invalid_value"),

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(drop_copy, clippy::forget_copy)]
2-
#![allow(clippy::toplevel_ref_arg, drop_ref, clippy::forget_ref, unused_mut)]
2+
#![allow(clippy::toplevel_ref_arg, drop_ref, 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: 61 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,18 @@ note: argument has type `SomeStruct`
8484
LL | forget(s2);
8585
| ^^
8686

87+
error: calls to `std::mem::forget` with a value that implements `Copy`. Forgetting a copy leaves the original intact
88+
--> $DIR/drop_forget_copy.rs:41:5
89+
|
90+
LL | forget(s3);
91+
| ^^^^^^^^^^
92+
|
93+
note: argument has type `&SomeStruct`
94+
--> $DIR/drop_forget_copy.rs:41:12
95+
|
96+
LL | forget(s3);
97+
| ^^
98+
8799
error: calls to `std::mem::forget` with a value that implements `Copy`. Forgetting a copy leaves the original intact
88100
--> $DIR/drop_forget_copy.rs:42:5
89101
|
@@ -96,6 +108,18 @@ note: argument has type `SomeStruct`
96108
LL | forget(s4);
97109
| ^^
98110

111+
error: calls to `std::mem::forget` with a value that implements `Copy`. Forgetting a copy leaves the original intact
112+
--> $DIR/drop_forget_copy.rs:43:5
113+
|
114+
LL | forget(s5);
115+
| ^^^^^^^^^^
116+
|
117+
note: argument has type `&SomeStruct`
118+
--> $DIR/drop_forget_copy.rs:43:12
119+
|
120+
LL | forget(s5);
121+
| ^^
122+
99123
error: call to `std::mem::drop` with a value that does not implement `Drop`. Dropping such a type only extends its contained lifetimes
100124
--> $DIR/drop_forget_copy.rs:55:5
101125
|
@@ -120,6 +144,42 @@ note: argument has type `&AnotherStruct`
120144
LL | drop(a4);
121145
| ^^
122146

147+
error: calls to `std::mem::forget` with a value that implements `Copy`. Forgetting a copy leaves the original intact
148+
--> $DIR/drop_forget_copy.rs:60:5
149+
|
150+
LL | forget(a2);
151+
| ^^^^^^^^^^
152+
|
153+
note: argument has type `&AnotherStruct`
154+
--> $DIR/drop_forget_copy.rs:60:12
155+
|
156+
LL | forget(a2);
157+
| ^^
158+
159+
error: calls to `std::mem::forget` with a value that implements `Copy`. Forgetting a copy leaves the original intact
160+
--> $DIR/drop_forget_copy.rs:62:5
161+
|
162+
LL | forget(a3);
163+
| ^^^^^^^^^^
164+
|
165+
note: argument has type `&AnotherStruct`
166+
--> $DIR/drop_forget_copy.rs:62:12
167+
|
168+
LL | forget(a3);
169+
| ^^
170+
171+
error: calls to `std::mem::forget` with a value that implements `Copy`. Forgetting a copy leaves the original intact
172+
--> $DIR/drop_forget_copy.rs:63:5
173+
|
174+
LL | forget(a4);
175+
| ^^^^^^^^^^
176+
|
177+
note: argument has type `&AnotherStruct`
178+
--> $DIR/drop_forget_copy.rs:63:12
179+
|
180+
LL | forget(a4);
181+
| ^^
182+
123183
error: call to `std::mem::drop` with a value that does not implement `Drop`. Dropping such a type only extends its contained lifetimes
124184
--> $DIR/drop_forget_copy.rs:80:13
125185
|
@@ -229,5 +289,5 @@ note: argument has type `i32`
229289
LL | 4 => drop(2), // Lint, not a fn/method call
230290
| ^
231291

232-
error: aborting due to 19 previous errors
292+
error: aborting due to 24 previous errors
233293

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

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

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

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

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
#![allow(drop_copy)]
3232
#![allow(drop_ref)]
3333
#![allow(for_loops_over_fallibles)]
34+
#![allow(forget_ref)]
3435
#![allow(array_into_iter)]
3536
#![allow(invalid_atomic_ordering)]
3637
#![allow(invalid_value)]
@@ -75,6 +76,7 @@
7576
#![warn(for_loops_over_fallibles)]
7677
#![warn(for_loops_over_fallibles)]
7778
#![warn(for_loops_over_fallibles)]
79+
#![warn(forget_ref)]
7880
#![warn(array_into_iter)]
7981
#![warn(invalid_atomic_ordering)]
8082
#![warn(invalid_value)]

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
#![allow(drop_copy)]
3232
#![allow(drop_ref)]
3333
#![allow(for_loops_over_fallibles)]
34+
#![allow(forget_ref)]
3435
#![allow(array_into_iter)]
3536
#![allow(invalid_atomic_ordering)]
3637
#![allow(invalid_value)]
@@ -75,6 +76,7 @@
7576
#![warn(clippy::for_loop_over_option)]
7677
#![warn(clippy::for_loop_over_result)]
7778
#![warn(clippy::for_loops_over_fallibles)]
79+
#![warn(clippy::forget_ref)]
7880
#![warn(clippy::into_iter_on_array)]
7981
#![warn(clippy::invalid_atomic_ordering)]
8082
#![warn(clippy::invalid_ref)]

0 commit comments

Comments
 (0)