Skip to content

Commit b356491

Browse files
committed
Auto merge of #111530 - Urgau:uplift_undropped_manually_drops, r=compiler-errors
Uplift `clippy::undropped_manually_drops` lint This PR aims at uplifting the `clippy::undropped_manually_drops` lint. ## `undropped_manually_drops` (warn-by-default) The `undropped_manually_drops` lint check for calls to `std::mem::drop` with a value of `std::mem::ManuallyDrop` which doesn't drop. ### Example ```rust struct S; drop(std::mem::ManuallyDrop::new(S)); ``` ### Explanation `ManuallyDrop` does not drop it's inner value so calling `std::mem::drop` will not drop the inner value of the `ManuallyDrop` either. ----- Mostly followed the instructions for uplifting an clippy lint described here: rust-lang/rust#99696 (review) `@rustbot` label: +I-lang-nominated r? compiler ----- For Clippy: changelog: Moves: Uplifted `clippy::undropped_manually_drops` into rustc
2 parents 737cba0 + f47e915 commit b356491

8 files changed

+64
-139
lines changed

clippy_lints/src/declared_lints.rs

-1
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,6 @@ pub(crate) static LINTS: &[&crate::LintInfo] = &[
136136
crate::double_parens::DOUBLE_PARENS_INFO,
137137
crate::drop_forget_ref::DROP_NON_DROP_INFO,
138138
crate::drop_forget_ref::FORGET_NON_DROP_INFO,
139-
crate::drop_forget_ref::UNDROPPED_MANUALLY_DROPS_INFO,
140139
crate::duplicate_mod::DUPLICATE_MOD_INFO,
141140
crate::else_if_without_else::ELSE_IF_WITHOUT_ELSE_INFO,
142141
crate::empty_drop::EMPTY_DROP_INFO,

clippy_lints/src/drop_forget_ref.rs

+2-42
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use clippy_utils::diagnostics::{span_lint_and_help, span_lint_and_note};
1+
use clippy_utils::diagnostics::span_lint_and_note;
22
use clippy_utils::get_parent_node;
33
use clippy_utils::is_must_use_func_call;
44
use clippy_utils::ty::{is_copy, is_must_use_ty, is_type_lang_item};
@@ -47,35 +47,6 @@ declare_clippy_lint! {
4747
"call to `std::mem::forget` with a value which does not implement `Drop`"
4848
}
4949

50-
declare_clippy_lint! {
51-
/// ### What it does
52-
/// Prevents the safe `std::mem::drop` function from being called on `std::mem::ManuallyDrop`.
53-
///
54-
/// ### Why is this bad?
55-
/// The safe `drop` function does not drop the inner value of a `ManuallyDrop`.
56-
///
57-
/// ### Known problems
58-
/// Does not catch cases if the user binds `std::mem::drop`
59-
/// to a different name and calls it that way.
60-
///
61-
/// ### Example
62-
/// ```rust
63-
/// struct S;
64-
/// drop(std::mem::ManuallyDrop::new(S));
65-
/// ```
66-
/// Use instead:
67-
/// ```rust
68-
/// struct S;
69-
/// unsafe {
70-
/// std::mem::ManuallyDrop::drop(&mut std::mem::ManuallyDrop::new(S));
71-
/// }
72-
/// ```
73-
#[clippy::version = "1.49.0"]
74-
pub UNDROPPED_MANUALLY_DROPS,
75-
correctness,
76-
"use of safe `std::mem::drop` function to drop a std::mem::ManuallyDrop, which will not drop the inner value"
77-
}
78-
7950
const DROP_NON_DROP_SUMMARY: &str = "call to `std::mem::drop` with a value that does not implement `Drop`. \
8051
Dropping such a type only extends its contained lifetimes";
8152
const FORGET_NON_DROP_SUMMARY: &str = "call to `std::mem::forget` with a value that does not implement `Drop`. \
@@ -84,7 +55,6 @@ const FORGET_NON_DROP_SUMMARY: &str = "call to `std::mem::forget` with a value t
8455
declare_lint_pass!(DropForgetRef => [
8556
DROP_NON_DROP,
8657
FORGET_NON_DROP,
87-
UNDROPPED_MANUALLY_DROPS
8858
]);
8959

9060
impl<'tcx> LateLintPass<'tcx> for DropForgetRef {
@@ -103,17 +73,7 @@ impl<'tcx> LateLintPass<'tcx> for DropForgetRef {
10373
sym::mem_forget if arg_ty.is_ref() => return,
10474
sym::mem_drop if is_copy && !drop_is_single_call_in_arm => return,
10575
sym::mem_forget if is_copy => return,
106-
sym::mem_drop if is_type_lang_item(cx, arg_ty, LangItem::ManuallyDrop) => {
107-
span_lint_and_help(
108-
cx,
109-
UNDROPPED_MANUALLY_DROPS,
110-
expr.span,
111-
"the inner value of this ManuallyDrop will not be dropped",
112-
None,
113-
"to drop a `ManuallyDrop<T>`, use std::mem::ManuallyDrop::drop",
114-
);
115-
return;
116-
}
76+
sym::mem_drop if is_type_lang_item(cx, arg_ty, LangItem::ManuallyDrop) => return,
11777
sym::mem_drop
11878
if !(arg_ty.needs_drop(cx.tcx, cx.param_env)
11979
|| is_must_use_func_call(cx, arg)

clippy_lints/src/renamed_lints.rs

+1
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ pub static RENAMED_LINTS: &[(&str, &str)] = &[
5050
("clippy::panic_params", "non_fmt_panics"),
5151
("clippy::positional_named_format_parameters", "named_arguments_used_positionally"),
5252
("clippy::temporary_cstring_as_ptr", "temporary_cstring_as_ptr"),
53+
("clippy::undropped_manually_drops", "undropped_manually_drops"),
5354
("clippy::unknown_clippy_lints", "unknown_lints"),
5455
("clippy::unused_label", "unused_labels"),
5556
];

tests/ui/rename.fixed

+2
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
#![allow(named_arguments_used_positionally)]
4848
#![allow(suspicious_double_ref_op)]
4949
#![allow(temporary_cstring_as_ptr)]
50+
#![allow(undropped_manually_drops)]
5051
#![allow(unknown_lints)]
5152
#![allow(unused_labels)]
5253
#![warn(clippy::almost_complete_range)]
@@ -97,6 +98,7 @@
9798
#![warn(non_fmt_panics)]
9899
#![warn(named_arguments_used_positionally)]
99100
#![warn(temporary_cstring_as_ptr)]
101+
#![warn(undropped_manually_drops)]
100102
#![warn(unknown_lints)]
101103
#![warn(unused_labels)]
102104

tests/ui/rename.rs

+2
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
#![allow(named_arguments_used_positionally)]
4848
#![allow(suspicious_double_ref_op)]
4949
#![allow(temporary_cstring_as_ptr)]
50+
#![allow(undropped_manually_drops)]
5051
#![allow(unknown_lints)]
5152
#![allow(unused_labels)]
5253
#![warn(clippy::almost_complete_letter_range)]
@@ -97,6 +98,7 @@
9798
#![warn(clippy::panic_params)]
9899
#![warn(clippy::positional_named_format_parameters)]
99100
#![warn(clippy::temporary_cstring_as_ptr)]
101+
#![warn(clippy::undropped_manually_drops)]
100102
#![warn(clippy::unknown_clippy_lints)]
101103
#![warn(clippy::unused_label)]
102104

0 commit comments

Comments
 (0)