@@ -7,34 +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 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-
3810declare_clippy_lint ! {
3911 /// ### What it does
4012 /// Checks for calls to `std::mem::drop` with a value that does not implement `Drop`.
@@ -104,15 +76,12 @@ declare_clippy_lint! {
10476 "use of safe `std::mem::drop` function to drop a std::mem::ManuallyDrop, which will not drop the inner value"
10577}
10678
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";
10979const DROP_NON_DROP_SUMMARY : & str = "call to `std::mem::drop` with a value that does not implement `Drop`. \
11080 Dropping such a type only extends its contained lifetimes";
11181const FORGET_NON_DROP_SUMMARY : & str = "call to `std::mem::forget` with a value that does not implement `Drop`. \
11282 Forgetting such a type is the same as dropping it";
11383
11484declare_lint_pass ! ( DropForgetRef => [
115- FORGET_COPY ,
11685 DROP_NON_DROP ,
11786 FORGET_NON_DROP ,
11887 UNDROPPED_MANUALLY_DROPS
@@ -129,11 +98,11 @@ impl<'tcx> LateLintPass<'tcx> for DropForgetRef {
12998 let is_copy = is_copy ( cx, arg_ty) ;
13099 let drop_is_single_call_in_arm = is_single_call_in_arm ( cx, arg, expr) ;
131100 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
133102 sym:: mem_drop if arg_ty. is_ref ( ) && !drop_is_single_call_in_arm => return ,
134103 sym:: mem_forget if arg_ty. is_ref ( ) => return ,
135104 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 ,
137106 sym:: mem_drop if is_type_lang_item ( cx, arg_ty, LangItem :: ManuallyDrop ) => {
138107 span_lint_and_help (
139108 cx,
0 commit comments