Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit d7ad9d9

Browse files
committedJun 9, 2023
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: #99696 (review) `@rustbot` label: +I-lang-nominated r? compiler ----- For Clippy: changelog: Moves: Uplifted `clippy::undropped_manually_drops` into rustc
2 parents 343ad6f + d9d1c76 commit d7ad9d9

14 files changed

+192
-141
lines changed
 

‎compiler/rustc_lint/messages.ftl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -492,6 +492,10 @@ lint_tykind = usage of `ty::TyKind`
492492
lint_tykind_kind = usage of `ty::TyKind::<kind>`
493493
.suggestion = try using `ty::<kind>` directly
494494
495+
lint_undropped_manually_drops = calls to `std::mem::drop` with `std::mem::ManuallyDrop` instead of the inner value does nothing
496+
.label = argument has type `{$arg_ty}`
497+
.suggestion = use `std::mem::ManuallyDrop::into_inner` to get the inner value
498+
495499
lint_ungated_async_fn_track_caller = `#[track_caller]` on async functions is a no-op
496500
.label = this function will not propagate the caller location
497501

‎compiler/rustc_lint/src/drop_forget_useless.rs

Lines changed: 42 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
use rustc_hir::{Arm, Expr, ExprKind, Node};
2+
use rustc_middle::ty;
23
use rustc_span::sym;
34

45
use crate::{
5-
lints::{DropCopyDiag, DropRefDiag, ForgetCopyDiag, ForgetRefDiag},
6+
lints::{
7+
DropCopyDiag, DropRefDiag, ForgetCopyDiag, ForgetRefDiag, UndroppedManuallyDropsDiag,
8+
UndroppedManuallyDropsSuggestion,
9+
},
610
LateContext, LateLintPass, LintContext,
711
};
812

@@ -109,7 +113,29 @@ declare_lint! {
109113
"calls to `std::mem::forget` with a value that implements Copy"
110114
}
111115

112-
declare_lint_pass!(DropForgetUseless => [DROPPING_REFERENCES, FORGETTING_REFERENCES, DROPPING_COPY_TYPES, FORGETTING_COPY_TYPES]);
116+
declare_lint! {
117+
/// The `undropped_manually_drops` lint check for calls to `std::mem::drop` with
118+
/// a value of `std::mem::ManuallyDrop` which doesn't drop.
119+
///
120+
/// ### Example
121+
///
122+
/// ```rust,compile_fail
123+
/// struct S;
124+
/// drop(std::mem::ManuallyDrop::new(S));
125+
/// ```
126+
///
127+
/// {{produces}}
128+
///
129+
/// ### Explanation
130+
///
131+
/// `ManuallyDrop` does not drop it's inner value so calling `std::mem::drop` will
132+
/// not drop the inner value of the `ManuallyDrop` either.
133+
pub UNDROPPED_MANUALLY_DROPS,
134+
Deny,
135+
"calls to `std::mem::drop` with `std::mem::ManuallyDrop` instead of it's inner value"
136+
}
137+
138+
declare_lint_pass!(DropForgetUseless => [DROPPING_REFERENCES, FORGETTING_REFERENCES, DROPPING_COPY_TYPES, FORGETTING_COPY_TYPES, UNDROPPED_MANUALLY_DROPS]);
113139

114140
impl<'tcx> LateLintPass<'tcx> for DropForgetUseless {
115141
fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'tcx>) {
@@ -134,6 +160,20 @@ impl<'tcx> LateLintPass<'tcx> for DropForgetUseless {
134160
sym::mem_forget if is_copy => {
135161
cx.emit_spanned_lint(FORGETTING_COPY_TYPES, expr.span, ForgetCopyDiag { arg_ty, label: arg.span });
136162
}
163+
sym::mem_drop if let ty::Adt(adt, _) = arg_ty.kind() && adt.is_manually_drop() => {
164+
cx.emit_spanned_lint(
165+
UNDROPPED_MANUALLY_DROPS,
166+
expr.span,
167+
UndroppedManuallyDropsDiag {
168+
arg_ty,
169+
label: arg.span,
170+
suggestion: UndroppedManuallyDropsSuggestion {
171+
start_span: arg.span.shrink_to_lo(),
172+
end_span: arg.span.shrink_to_hi()
173+
}
174+
}
175+
);
176+
}
137177
_ => return,
138178
};
139179
}

‎compiler/rustc_lint/src/lints.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -699,6 +699,25 @@ pub struct ForgetCopyDiag<'a> {
699699
pub label: Span,
700700
}
701701

702+
#[derive(LintDiagnostic)]
703+
#[diag(lint_undropped_manually_drops)]
704+
pub struct UndroppedManuallyDropsDiag<'a> {
705+
pub arg_ty: Ty<'a>,
706+
#[label]
707+
pub label: Span,
708+
#[subdiagnostic]
709+
pub suggestion: UndroppedManuallyDropsSuggestion,
710+
}
711+
712+
#[derive(Subdiagnostic)]
713+
#[multipart_suggestion(lint_suggestion, applicability = "machine-applicable")]
714+
pub struct UndroppedManuallyDropsSuggestion {
715+
#[suggestion_part(code = "std::mem::ManuallyDrop::into_inner(")]
716+
pub start_span: Span,
717+
#[suggestion_part(code = ")")]
718+
pub end_span: Span,
719+
}
720+
702721
// invalid_from_utf8.rs
703722
#[derive(LintDiagnostic)]
704723
pub enum InvalidFromUtf8Diag {

‎library/core/tests/manually_drop.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#![cfg_attr(not(bootstrap), allow(undropped_manually_drops))]
2+
13
use core::mem::ManuallyDrop;
24

35
#[test]

‎src/tools/clippy/clippy_lints/src/declared_lints.rs

Lines changed: 0 additions & 1 deletion
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,

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

Lines changed: 2 additions & 42 deletions
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)

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

Lines changed: 1 addition & 0 deletions
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
];

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

Lines changed: 2 additions & 0 deletions
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

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

Lines changed: 2 additions & 0 deletions
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

Lines changed: 57 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -1,304 +1,310 @@
11
error: lint `clippy::almost_complete_letter_range` has been renamed to `clippy::almost_complete_range`
2-
--> $DIR/rename.rs:52:9
2+
--> $DIR/rename.rs:53:9
33
|
44
LL | #![warn(clippy::almost_complete_letter_range)]
55
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::almost_complete_range`
66
|
77
= note: `-D renamed-and-removed-lints` implied by `-D warnings`
88

99
error: lint `clippy::blacklisted_name` has been renamed to `clippy::disallowed_names`
10-
--> $DIR/rename.rs:53:9
10+
--> $DIR/rename.rs:54:9
1111
|
1212
LL | #![warn(clippy::blacklisted_name)]
1313
| ^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::disallowed_names`
1414

1515
error: lint `clippy::block_in_if_condition_expr` has been renamed to `clippy::blocks_in_if_conditions`
16-
--> $DIR/rename.rs:54:9
16+
--> $DIR/rename.rs:55:9
1717
|
1818
LL | #![warn(clippy::block_in_if_condition_expr)]
1919
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::blocks_in_if_conditions`
2020

2121
error: lint `clippy::block_in_if_condition_stmt` has been renamed to `clippy::blocks_in_if_conditions`
22-
--> $DIR/rename.rs:55:9
22+
--> $DIR/rename.rs:56:9
2323
|
2424
LL | #![warn(clippy::block_in_if_condition_stmt)]
2525
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::blocks_in_if_conditions`
2626

2727
error: lint `clippy::box_vec` has been renamed to `clippy::box_collection`
28-
--> $DIR/rename.rs:56:9
28+
--> $DIR/rename.rs:57:9
2929
|
3030
LL | #![warn(clippy::box_vec)]
3131
| ^^^^^^^^^^^^^^^ help: use the new name: `clippy::box_collection`
3232

3333
error: lint `clippy::const_static_lifetime` has been renamed to `clippy::redundant_static_lifetimes`
34-
--> $DIR/rename.rs:57:9
34+
--> $DIR/rename.rs:58:9
3535
|
3636
LL | #![warn(clippy::const_static_lifetime)]
3737
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::redundant_static_lifetimes`
3838

3939
error: lint `clippy::cyclomatic_complexity` has been renamed to `clippy::cognitive_complexity`
40-
--> $DIR/rename.rs:58:9
40+
--> $DIR/rename.rs:59:9
4141
|
4242
LL | #![warn(clippy::cyclomatic_complexity)]
4343
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::cognitive_complexity`
4444

4545
error: lint `clippy::derive_hash_xor_eq` has been renamed to `clippy::derived_hash_with_manual_eq`
46-
--> $DIR/rename.rs:59:9
46+
--> $DIR/rename.rs:60:9
4747
|
4848
LL | #![warn(clippy::derive_hash_xor_eq)]
4949
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::derived_hash_with_manual_eq`
5050

5151
error: lint `clippy::disallowed_method` has been renamed to `clippy::disallowed_methods`
52-
--> $DIR/rename.rs:60:9
52+
--> $DIR/rename.rs:61:9
5353
|
5454
LL | #![warn(clippy::disallowed_method)]
5555
| ^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::disallowed_methods`
5656

5757
error: lint `clippy::disallowed_type` has been renamed to `clippy::disallowed_types`
58-
--> $DIR/rename.rs:61:9
58+
--> $DIR/rename.rs:62:9
5959
|
6060
LL | #![warn(clippy::disallowed_type)]
6161
| ^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::disallowed_types`
6262

6363
error: lint `clippy::eval_order_dependence` has been renamed to `clippy::mixed_read_write_in_expression`
64-
--> $DIR/rename.rs:62:9
64+
--> $DIR/rename.rs:63:9
6565
|
6666
LL | #![warn(clippy::eval_order_dependence)]
6767
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::mixed_read_write_in_expression`
6868

6969
error: lint `clippy::identity_conversion` has been renamed to `clippy::useless_conversion`
70-
--> $DIR/rename.rs:63:9
70+
--> $DIR/rename.rs:64:9
7171
|
7272
LL | #![warn(clippy::identity_conversion)]
7373
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::useless_conversion`
7474

7575
error: lint `clippy::if_let_some_result` has been renamed to `clippy::match_result_ok`
76-
--> $DIR/rename.rs:64:9
76+
--> $DIR/rename.rs:65:9
7777
|
7878
LL | #![warn(clippy::if_let_some_result)]
7979
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::match_result_ok`
8080

8181
error: lint `clippy::integer_arithmetic` has been renamed to `clippy::arithmetic_side_effects`
82-
--> $DIR/rename.rs:65:9
82+
--> $DIR/rename.rs:66:9
8383
|
8484
LL | #![warn(clippy::integer_arithmetic)]
8585
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::arithmetic_side_effects`
8686

8787
error: lint `clippy::logic_bug` has been renamed to `clippy::overly_complex_bool_expr`
88-
--> $DIR/rename.rs:66:9
88+
--> $DIR/rename.rs:67:9
8989
|
9090
LL | #![warn(clippy::logic_bug)]
9191
| ^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::overly_complex_bool_expr`
9292

9393
error: lint `clippy::new_without_default_derive` has been renamed to `clippy::new_without_default`
94-
--> $DIR/rename.rs:67:9
94+
--> $DIR/rename.rs:68:9
9595
|
9696
LL | #![warn(clippy::new_without_default_derive)]
9797
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::new_without_default`
9898

9999
error: lint `clippy::option_and_then_some` has been renamed to `clippy::bind_instead_of_map`
100-
--> $DIR/rename.rs:68:9
100+
--> $DIR/rename.rs:69:9
101101
|
102102
LL | #![warn(clippy::option_and_then_some)]
103103
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::bind_instead_of_map`
104104

105105
error: lint `clippy::option_expect_used` has been renamed to `clippy::expect_used`
106-
--> $DIR/rename.rs:69:9
106+
--> $DIR/rename.rs:70:9
107107
|
108108
LL | #![warn(clippy::option_expect_used)]
109109
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::expect_used`
110110

111111
error: lint `clippy::option_map_unwrap_or` has been renamed to `clippy::map_unwrap_or`
112-
--> $DIR/rename.rs:70:9
112+
--> $DIR/rename.rs:71:9
113113
|
114114
LL | #![warn(clippy::option_map_unwrap_or)]
115115
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::map_unwrap_or`
116116

117117
error: lint `clippy::option_map_unwrap_or_else` has been renamed to `clippy::map_unwrap_or`
118-
--> $DIR/rename.rs:71:9
118+
--> $DIR/rename.rs:72:9
119119
|
120120
LL | #![warn(clippy::option_map_unwrap_or_else)]
121121
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::map_unwrap_or`
122122

123123
error: lint `clippy::option_unwrap_used` has been renamed to `clippy::unwrap_used`
124-
--> $DIR/rename.rs:72:9
124+
--> $DIR/rename.rs:73:9
125125
|
126126
LL | #![warn(clippy::option_unwrap_used)]
127127
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::unwrap_used`
128128

129129
error: lint `clippy::ref_in_deref` has been renamed to `clippy::needless_borrow`
130-
--> $DIR/rename.rs:73:9
130+
--> $DIR/rename.rs:74:9
131131
|
132132
LL | #![warn(clippy::ref_in_deref)]
133133
| ^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::needless_borrow`
134134

135135
error: lint `clippy::result_expect_used` has been renamed to `clippy::expect_used`
136-
--> $DIR/rename.rs:74:9
136+
--> $DIR/rename.rs:75:9
137137
|
138138
LL | #![warn(clippy::result_expect_used)]
139139
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::expect_used`
140140

141141
error: lint `clippy::result_map_unwrap_or_else` has been renamed to `clippy::map_unwrap_or`
142-
--> $DIR/rename.rs:75:9
142+
--> $DIR/rename.rs:76:9
143143
|
144144
LL | #![warn(clippy::result_map_unwrap_or_else)]
145145
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::map_unwrap_or`
146146

147147
error: lint `clippy::result_unwrap_used` has been renamed to `clippy::unwrap_used`
148-
--> $DIR/rename.rs:76:9
148+
--> $DIR/rename.rs:77:9
149149
|
150150
LL | #![warn(clippy::result_unwrap_used)]
151151
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::unwrap_used`
152152

153153
error: lint `clippy::single_char_push_str` has been renamed to `clippy::single_char_add_str`
154-
--> $DIR/rename.rs:77:9
154+
--> $DIR/rename.rs:78:9
155155
|
156156
LL | #![warn(clippy::single_char_push_str)]
157157
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::single_char_add_str`
158158

159159
error: lint `clippy::stutter` has been renamed to `clippy::module_name_repetitions`
160-
--> $DIR/rename.rs:78:9
160+
--> $DIR/rename.rs:79:9
161161
|
162162
LL | #![warn(clippy::stutter)]
163163
| ^^^^^^^^^^^^^^^ help: use the new name: `clippy::module_name_repetitions`
164164

165165
error: lint `clippy::to_string_in_display` has been renamed to `clippy::recursive_format_impl`
166-
--> $DIR/rename.rs:79:9
166+
--> $DIR/rename.rs:80:9
167167
|
168168
LL | #![warn(clippy::to_string_in_display)]
169169
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::recursive_format_impl`
170170

171171
error: lint `clippy::zero_width_space` has been renamed to `clippy::invisible_characters`
172-
--> $DIR/rename.rs:80:9
172+
--> $DIR/rename.rs:81:9
173173
|
174174
LL | #![warn(clippy::zero_width_space)]
175175
| ^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::invisible_characters`
176176

177177
error: lint `clippy::cast_ref_to_mut` has been renamed to `cast_ref_to_mut`
178-
--> $DIR/rename.rs:81:9
178+
--> $DIR/rename.rs:82:9
179179
|
180180
LL | #![warn(clippy::cast_ref_to_mut)]
181181
| ^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `cast_ref_to_mut`
182182

183183
error: lint `clippy::clone_double_ref` has been renamed to `suspicious_double_ref_op`
184-
--> $DIR/rename.rs:82:9
184+
--> $DIR/rename.rs:83:9
185185
|
186186
LL | #![warn(clippy::clone_double_ref)]
187187
| ^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `suspicious_double_ref_op`
188188

189189
error: lint `clippy::drop_bounds` has been renamed to `drop_bounds`
190-
--> $DIR/rename.rs:83:9
190+
--> $DIR/rename.rs:84:9
191191
|
192192
LL | #![warn(clippy::drop_bounds)]
193193
| ^^^^^^^^^^^^^^^^^^^ help: use the new name: `drop_bounds`
194194

195195
error: lint `clippy::drop_copy` has been renamed to `dropping_copy_types`
196-
--> $DIR/rename.rs:84:9
196+
--> $DIR/rename.rs:85:9
197197
|
198198
LL | #![warn(clippy::drop_copy)]
199199
| ^^^^^^^^^^^^^^^^^ help: use the new name: `dropping_copy_types`
200200

201201
error: lint `clippy::drop_ref` has been renamed to `dropping_references`
202-
--> $DIR/rename.rs:85:9
202+
--> $DIR/rename.rs:86:9
203203
|
204204
LL | #![warn(clippy::drop_ref)]
205205
| ^^^^^^^^^^^^^^^^ help: use the new name: `dropping_references`
206206

207207
error: lint `clippy::for_loop_over_option` has been renamed to `for_loops_over_fallibles`
208-
--> $DIR/rename.rs:86:9
208+
--> $DIR/rename.rs:87:9
209209
|
210210
LL | #![warn(clippy::for_loop_over_option)]
211211
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `for_loops_over_fallibles`
212212

213213
error: lint `clippy::for_loop_over_result` has been renamed to `for_loops_over_fallibles`
214-
--> $DIR/rename.rs:87:9
214+
--> $DIR/rename.rs:88:9
215215
|
216216
LL | #![warn(clippy::for_loop_over_result)]
217217
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `for_loops_over_fallibles`
218218

219219
error: lint `clippy::for_loops_over_fallibles` has been renamed to `for_loops_over_fallibles`
220-
--> $DIR/rename.rs:88:9
220+
--> $DIR/rename.rs:89:9
221221
|
222222
LL | #![warn(clippy::for_loops_over_fallibles)]
223223
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `for_loops_over_fallibles`
224224

225225
error: lint `clippy::forget_copy` has been renamed to `forgetting_copy_types`
226-
--> $DIR/rename.rs:89:9
226+
--> $DIR/rename.rs:90:9
227227
|
228228
LL | #![warn(clippy::forget_copy)]
229229
| ^^^^^^^^^^^^^^^^^^^ help: use the new name: `forgetting_copy_types`
230230

231231
error: lint `clippy::forget_ref` has been renamed to `forgetting_references`
232-
--> $DIR/rename.rs:90:9
232+
--> $DIR/rename.rs:91:9
233233
|
234234
LL | #![warn(clippy::forget_ref)]
235235
| ^^^^^^^^^^^^^^^^^^ help: use the new name: `forgetting_references`
236236

237237
error: lint `clippy::into_iter_on_array` has been renamed to `array_into_iter`
238-
--> $DIR/rename.rs:91:9
238+
--> $DIR/rename.rs:92:9
239239
|
240240
LL | #![warn(clippy::into_iter_on_array)]
241241
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `array_into_iter`
242242

243243
error: lint `clippy::invalid_atomic_ordering` has been renamed to `invalid_atomic_ordering`
244-
--> $DIR/rename.rs:92:9
244+
--> $DIR/rename.rs:93:9
245245
|
246246
LL | #![warn(clippy::invalid_atomic_ordering)]
247247
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `invalid_atomic_ordering`
248248

249249
error: lint `clippy::invalid_ref` has been renamed to `invalid_value`
250-
--> $DIR/rename.rs:93:9
250+
--> $DIR/rename.rs:94:9
251251
|
252252
LL | #![warn(clippy::invalid_ref)]
253253
| ^^^^^^^^^^^^^^^^^^^ help: use the new name: `invalid_value`
254254

255255
error: lint `clippy::invalid_utf8_in_unchecked` has been renamed to `invalid_from_utf8_unchecked`
256-
--> $DIR/rename.rs:94:9
256+
--> $DIR/rename.rs:95:9
257257
|
258258
LL | #![warn(clippy::invalid_utf8_in_unchecked)]
259259
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `invalid_from_utf8_unchecked`
260260

261261
error: lint `clippy::let_underscore_drop` has been renamed to `let_underscore_drop`
262-
--> $DIR/rename.rs:95:9
262+
--> $DIR/rename.rs:96:9
263263
|
264264
LL | #![warn(clippy::let_underscore_drop)]
265265
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `let_underscore_drop`
266266

267267
error: lint `clippy::mem_discriminant_non_enum` has been renamed to `enum_intrinsics_non_enums`
268-
--> $DIR/rename.rs:96:9
268+
--> $DIR/rename.rs:97:9
269269
|
270270
LL | #![warn(clippy::mem_discriminant_non_enum)]
271271
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `enum_intrinsics_non_enums`
272272

273273
error: lint `clippy::panic_params` has been renamed to `non_fmt_panics`
274-
--> $DIR/rename.rs:97:9
274+
--> $DIR/rename.rs:98:9
275275
|
276276
LL | #![warn(clippy::panic_params)]
277277
| ^^^^^^^^^^^^^^^^^^^^ help: use the new name: `non_fmt_panics`
278278

279279
error: lint `clippy::positional_named_format_parameters` has been renamed to `named_arguments_used_positionally`
280-
--> $DIR/rename.rs:98:9
280+
--> $DIR/rename.rs:99:9
281281
|
282282
LL | #![warn(clippy::positional_named_format_parameters)]
283283
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `named_arguments_used_positionally`
284284

285285
error: lint `clippy::temporary_cstring_as_ptr` has been renamed to `temporary_cstring_as_ptr`
286-
--> $DIR/rename.rs:99:9
286+
--> $DIR/rename.rs:100:9
287287
|
288288
LL | #![warn(clippy::temporary_cstring_as_ptr)]
289289
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `temporary_cstring_as_ptr`
290290

291+
error: lint `clippy::undropped_manually_drops` has been renamed to `undropped_manually_drops`
292+
--> $DIR/rename.rs:101:9
293+
|
294+
LL | #![warn(clippy::undropped_manually_drops)]
295+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `undropped_manually_drops`
296+
291297
error: lint `clippy::unknown_clippy_lints` has been renamed to `unknown_lints`
292-
--> $DIR/rename.rs:100:9
298+
--> $DIR/rename.rs:102:9
293299
|
294300
LL | #![warn(clippy::unknown_clippy_lints)]
295301
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `unknown_lints`
296302

297303
error: lint `clippy::unused_label` has been renamed to `unused_labels`
298-
--> $DIR/rename.rs:101:9
304+
--> $DIR/rename.rs:103:9
299305
|
300306
LL | #![warn(clippy::unused_label)]
301307
| ^^^^^^^^^^^^^^^^^^^^ help: use the new name: `unused_labels`
302308

303-
error: aborting due to 50 previous errors
309+
error: aborting due to 51 previous errors
304310

‎src/tools/clippy/tests/ui/undropped_manually_drops.rs

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

‎src/tools/clippy/tests/ui/undropped_manually_drops.stderr

Lines changed: 0 additions & 19 deletions
This file was deleted.
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// check-fail
2+
3+
struct S;
4+
5+
fn main() {
6+
let mut manual1 = std::mem::ManuallyDrop::new(S);
7+
let mut manual2 = std::mem::ManuallyDrop::new(S);
8+
let mut manual3 = std::mem::ManuallyDrop::new(S);
9+
10+
drop(std::mem::ManuallyDrop::new(S)); //~ ERROR calls to `std::mem::drop`
11+
drop(manual1); //~ ERROR calls to `std::mem::drop`
12+
drop({ manual3 }); //~ ERROR calls to `std::mem::drop`
13+
14+
// These lines will drop `S` and should be okay.
15+
unsafe {
16+
std::mem::ManuallyDrop::drop(&mut std::mem::ManuallyDrop::new(S));
17+
std::mem::ManuallyDrop::drop(&mut manual2);
18+
}
19+
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
error: calls to `std::mem::drop` with `std::mem::ManuallyDrop` instead of the inner value does nothing
2+
--> $DIR/undropped_manually_drops.rs:10:5
3+
|
4+
LL | drop(std::mem::ManuallyDrop::new(S));
5+
| ^^^^^------------------------------^
6+
| |
7+
| argument has type `ManuallyDrop<S>`
8+
|
9+
= note: `#[deny(undropped_manually_drops)]` on by default
10+
help: use `std::mem::ManuallyDrop::into_inner` to get the inner value
11+
|
12+
LL | drop(std::mem::ManuallyDrop::into_inner(std::mem::ManuallyDrop::new(S)));
13+
| +++++++++++++++++++++++++++++++++++ +
14+
15+
error: calls to `std::mem::drop` with `std::mem::ManuallyDrop` instead of the inner value does nothing
16+
--> $DIR/undropped_manually_drops.rs:11:5
17+
|
18+
LL | drop(manual1);
19+
| ^^^^^-------^
20+
| |
21+
| argument has type `ManuallyDrop<S>`
22+
|
23+
help: use `std::mem::ManuallyDrop::into_inner` to get the inner value
24+
|
25+
LL | drop(std::mem::ManuallyDrop::into_inner(manual1));
26+
| +++++++++++++++++++++++++++++++++++ +
27+
28+
error: calls to `std::mem::drop` with `std::mem::ManuallyDrop` instead of the inner value does nothing
29+
--> $DIR/undropped_manually_drops.rs:12:5
30+
|
31+
LL | drop({ manual3 });
32+
| ^^^^^-----------^
33+
| |
34+
| argument has type `ManuallyDrop<S>`
35+
|
36+
help: use `std::mem::ManuallyDrop::into_inner` to get the inner value
37+
|
38+
LL | drop(std::mem::ManuallyDrop::into_inner({ manual3 }));
39+
| +++++++++++++++++++++++++++++++++++ +
40+
41+
error: aborting due to 3 previous errors
42+

0 commit comments

Comments
 (0)
Please sign in to comment.