@@ -7,28 +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 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
-
32
10
declare_clippy_lint ! {
33
11
/// ### What it does
34
12
/// Checks for calls to `std::mem::forget` with a value that
@@ -126,8 +104,6 @@ declare_clippy_lint! {
126
104
"use of safe `std::mem::drop` function to drop a std::mem::ManuallyDrop, which will not drop the inner value"
127
105
}
128
106
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";
131
107
const FORGET_COPY_SUMMARY : & str = "calls to `std::mem::forget` with a value that implements `Copy`. \
132
108
Forgetting a copy leaves the original intact";
133
109
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
136
112
Forgetting such a type is the same as dropping it";
137
113
138
114
declare_lint_pass ! ( DropForgetRef => [
139
- FORGET_REF ,
140
115
FORGET_COPY ,
141
116
DROP_NON_DROP ,
142
117
FORGET_NON_DROP ,
@@ -154,9 +129,9 @@ impl<'tcx> LateLintPass<'tcx> for DropForgetRef {
154
129
let is_copy = is_copy ( cx, arg_ty) ;
155
130
let drop_is_single_call_in_arm = is_single_call_in_arm ( cx, arg, expr) ;
156
131
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
158
133
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 ,
160
135
sym:: mem_drop if is_copy && !drop_is_single_call_in_arm => return ,
161
136
sym:: mem_forget if is_copy => ( FORGET_COPY , FORGET_COPY_SUMMARY ) ,
162
137
sym:: mem_drop if is_type_lang_item ( cx, arg_ty, LangItem :: ManuallyDrop ) => {
0 commit comments