@@ -7,34 +7,6 @@ use rustc_lint::{LateContext, LateLintPass};
7
7
use rustc_session:: { declare_lint_pass, declare_tool_lint} ;
8
8
use rustc_span:: sym;
9
9
10
- declare_clippy_lint ! {
11
- /// ### What it does
12
- /// Checks for calls to `std::mem::forget` with a value that
13
- /// derives the Copy trait
14
- ///
15
- /// ### Why is this bad?
16
- /// Calling `std::mem::forget` [does nothing for types that
17
- /// implement Copy](https://doc.rust-lang.org/std/mem/fn.drop.html) since the
18
- /// value will be copied and moved into the function on invocation.
19
- ///
20
- /// An alternative, but also valid, explanation is that Copy types do not
21
- /// implement
22
- /// the Drop trait, which means they have no destructors. Without a destructor,
23
- /// there
24
- /// is nothing for `std::mem::forget` to ignore.
25
- ///
26
- /// ### Example
27
- /// ```rust
28
- /// let x: i32 = 42; // i32 implements Copy
29
- /// std::mem::forget(x) // A copy of x is passed to the function, leaving the
30
- /// // original unaffected
31
- /// ```
32
- #[ clippy:: version = "pre 1.29.0" ]
33
- pub FORGET_COPY ,
34
- correctness,
35
- "calls to `std::mem::forget` with a value that implements Copy"
36
- }
37
-
38
10
declare_clippy_lint ! {
39
11
/// ### What it does
40
12
/// Checks for calls to `std::mem::drop` with a value that does not implement `Drop`.
@@ -104,15 +76,12 @@ declare_clippy_lint! {
104
76
"use of safe `std::mem::drop` function to drop a std::mem::ManuallyDrop, which will not drop the inner value"
105
77
}
106
78
107
- const FORGET_COPY_SUMMARY : & str = "calls to `std::mem::forget` with a value that implements `Copy`. \
108
- Forgetting a copy leaves the original intact";
109
79
const DROP_NON_DROP_SUMMARY : & str = "call to `std::mem::drop` with a value that does not implement `Drop`. \
110
80
Dropping such a type only extends its contained lifetimes";
111
81
const FORGET_NON_DROP_SUMMARY : & str = "call to `std::mem::forget` with a value that does not implement `Drop`. \
112
82
Forgetting such a type is the same as dropping it";
113
83
114
84
declare_lint_pass ! ( DropForgetRef => [
115
- FORGET_COPY ,
116
85
DROP_NON_DROP ,
117
86
FORGET_NON_DROP ,
118
87
UNDROPPED_MANUALLY_DROPS
@@ -129,11 +98,11 @@ impl<'tcx> LateLintPass<'tcx> for DropForgetRef {
129
98
let is_copy = is_copy ( cx, arg_ty) ;
130
99
let drop_is_single_call_in_arm = is_single_call_in_arm ( cx, arg, expr) ;
131
100
let ( lint, msg) = match fn_name {
132
- // early return for uplifted lints: drop_ref, drop_copy, forget_ref
101
+ // early return for uplifted lints: drop_ref, drop_copy, forget_ref, forget_copy
133
102
sym:: mem_drop if arg_ty. is_ref ( ) && !drop_is_single_call_in_arm => return ,
134
103
sym:: mem_forget if arg_ty. is_ref ( ) => return ,
135
104
sym:: mem_drop if is_copy && !drop_is_single_call_in_arm => return ,
136
- sym:: mem_forget if is_copy => ( FORGET_COPY , FORGET_COPY_SUMMARY ) ,
105
+ sym:: mem_forget if is_copy => return ,
137
106
sym:: mem_drop if is_type_lang_item ( cx, arg_ty, LangItem :: ManuallyDrop ) => {
138
107
span_lint_and_help (
139
108
cx,
0 commit comments