Skip to content

Commit 3f81b6b

Browse files
committed
Drop uplifted clippy::forget_copy
1 parent 971b9b2 commit 3f81b6b

File tree

9 files changed

+61
-280
lines changed

9 files changed

+61
-280
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
@@ -133,7 +133,6 @@ pub(crate) static LINTS: &[&crate::LintInfo] = &[
133133
crate::doc::UNNECESSARY_SAFETY_DOC_INFO,
134134
crate::double_parens::DOUBLE_PARENS_INFO,
135135
crate::drop_forget_ref::DROP_NON_DROP_INFO,
136-
crate::drop_forget_ref::FORGET_COPY_INFO,
137136
crate::drop_forget_ref::FORGET_NON_DROP_INFO,
138137
crate::drop_forget_ref::UNDROPPED_MANUALLY_DROPS_INFO,
139138
crate::duplicate_mod::DUPLICATE_MOD_INFO,

src/tools/clippy/clippy_lints/src/drop_forget_ref.rs

Lines changed: 2 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -7,34 +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 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-
3810
declare_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";
10979
const 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";
11181
const 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

11484
declare_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,

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ pub static RENAMED_LINTS: &[(&str, &str)] = &[
3737
("clippy::for_loop_over_option", "for_loops_over_fallibles"),
3838
("clippy::for_loop_over_result", "for_loops_over_fallibles"),
3939
("clippy::for_loops_over_fallibles", "for_loops_over_fallibles"),
40+
("clippy::forget_copy", "forget_copy"),
4041
("clippy::forget_ref", "forget_ref"),
4142
("clippy::into_iter_on_array", "array_into_iter"),
4243
("clippy::invalid_atomic_ordering", "invalid_atomic_ordering"),

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

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

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

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

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use std::mem as memstuff;
55
use std::mem::forget as forgetSomething;
66

77
#[warn(clippy::mem_forget)]
8-
#[allow(clippy::forget_copy)]
8+
#[allow(forget_copy)]
99
fn main() {
1010
let five: i32 = 5;
1111
forgetSomething(five);

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
#![allow(drop_copy)]
3333
#![allow(drop_ref)]
3434
#![allow(for_loops_over_fallibles)]
35+
#![allow(forget_copy)]
3536
#![allow(forget_ref)]
3637
#![allow(array_into_iter)]
3738
#![allow(invalid_atomic_ordering)]
@@ -79,6 +80,7 @@
7980
#![warn(for_loops_over_fallibles)]
8081
#![warn(for_loops_over_fallibles)]
8182
#![warn(for_loops_over_fallibles)]
83+
#![warn(forget_copy)]
8284
#![warn(forget_ref)]
8385
#![warn(array_into_iter)]
8486
#![warn(invalid_atomic_ordering)]

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
#![allow(drop_copy)]
3333
#![allow(drop_ref)]
3434
#![allow(for_loops_over_fallibles)]
35+
#![allow(forget_copy)]
3536
#![allow(forget_ref)]
3637
#![allow(array_into_iter)]
3738
#![allow(invalid_atomic_ordering)]
@@ -79,6 +80,7 @@
7980
#![warn(clippy::for_loop_over_option)]
8081
#![warn(clippy::for_loop_over_result)]
8182
#![warn(clippy::for_loops_over_fallibles)]
83+
#![warn(clippy::forget_copy)]
8284
#![warn(clippy::forget_ref)]
8385
#![warn(clippy::into_iter_on_array)]
8486
#![warn(clippy::invalid_atomic_ordering)]

0 commit comments

Comments
 (0)