@@ -7,28 +7,6 @@ use rustc_lint::{LateContext, LateLintPass};
77use rustc_session:: { declare_lint_pass, declare_tool_lint} ;
88use 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-
3210declare_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";
131107const FORGET_COPY_SUMMARY : & str = "calls to `std::mem::forget` with a value that implements `Copy`. \
132108 Forgetting a copy leaves the original intact";
133109const 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
138114declare_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 ) => {
0 commit comments