Skip to content

Commit 4d1076c

Browse files
committed
Auto merge of #94206 - PrestonFrom:significant_drop, r=flip1995
Create clippy lint against unexpectedly late drop for temporaries in match scrutinee expressions A new clippy lint for issue 93883 (#93883). Relies on a new trait in `marker` (called `SignificantDrop` to enable linting), which is why this PR is for the rust-lang repo and not the clippy repo. changelog: new lint [`significant_drop_in_scrutinee`]
2 parents e612ce9 + d9e963f commit 4d1076c

10 files changed

+1204
-0
lines changed

library/std/src/sync/mutex.rs

+1
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,7 @@ unsafe impl<T: ?Sized + Send> Sync for Mutex<T> {}
192192
points can cause deadlocks, delays, \
193193
and cause Futures to not implement `Send`"]
194194
#[stable(feature = "rust1", since = "1.0.0")]
195+
#[clippy::has_significant_drop]
195196
pub struct MutexGuard<'a, T: ?Sized + 'a> {
196197
lock: &'a Mutex<T>,
197198
poison: poison::Guard,

library/std/src/sync/rwlock.rs

+2
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ unsafe impl<T: ?Sized + Send + Sync> Sync for RwLock<T> {}
9999
points can cause deadlocks, delays, \
100100
and cause Futures to not implement `Send`"]
101101
#[stable(feature = "rust1", since = "1.0.0")]
102+
#[clippy::has_significant_drop]
102103
pub struct RwLockReadGuard<'a, T: ?Sized + 'a> {
103104
lock: &'a RwLock<T>,
104105
}
@@ -122,6 +123,7 @@ unsafe impl<T: ?Sized + Sync> Sync for RwLockReadGuard<'_, T> {}
122123
points can cause deadlocks, delays, \
123124
and cause Future's to not implement `Send`"]
124125
#[stable(feature = "rust1", since = "1.0.0")]
126+
#[clippy::has_significant_drop]
125127
pub struct RwLockWriteGuard<'a, T: ?Sized + 'a> {
126128
lock: &'a RwLock<T>,
127129
poison: poison::Guard,

src/tools/clippy/CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -3696,6 +3696,7 @@ Released 2018-09-13
36963696
[`skip_while_next`]: https://rust-lang.github.io/rust-clippy/master/index.html#skip_while_next
36973697
[`slow_vector_initialization`]: https://rust-lang.github.io/rust-clippy/master/index.html#slow_vector_initialization
36983698
[`stable_sort_primitive`]: https://rust-lang.github.io/rust-clippy/master/index.html#stable_sort_primitive
3699+
[`significant_drop_in_scrutinee`]: https://rust-lang.github.io/rust-clippy/master/index.html#significant_drop_in_scrutinee
36993700
[`str_to_string`]: https://rust-lang.github.io/rust-clippy/master/index.html#str_to_string
37003701
[`string_add`]: https://rust-lang.github.io/rust-clippy/master/index.html#string_add
37013702
[`string_add_assign`]: https://rust-lang.github.io/rust-clippy/master/index.html#string_add_assign

src/tools/clippy/clippy_lints/src/lib.register_lints.rs

+1
Original file line numberDiff line numberDiff line change
@@ -475,6 +475,7 @@ store.register_lints(&[
475475
size_of_in_element_count::SIZE_OF_IN_ELEMENT_COUNT,
476476
slow_vector_initialization::SLOW_VECTOR_INITIALIZATION,
477477
stable_sort_primitive::STABLE_SORT_PRIMITIVE,
478+
significant_drop_in_scrutinee::SIGNIFICANT_DROP_IN_SCRUTINEE,
478479
strings::STRING_ADD,
479480
strings::STRING_ADD_ASSIGN,
480481
strings::STRING_FROM_UTF8_AS_BYTES,

src/tools/clippy/clippy_lints/src/lib.register_nursery.rs

+1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ store.register_group(true, "clippy::nursery", Some("clippy_nursery"), vec![
2525
LintId::of(path_buf_push_overwrite::PATH_BUF_PUSH_OVERWRITE),
2626
LintId::of(redundant_pub_crate::REDUNDANT_PUB_CRATE),
2727
LintId::of(regex::TRIVIAL_REGEX),
28+
LintId::of(significant_drop_in_scrutinee::SIGNIFICANT_DROP_IN_SCRUTINEE),
2829
LintId::of(strings::STRING_LIT_AS_BYTES),
2930
LintId::of(suspicious_operation_groupings::SUSPICIOUS_OPERATION_GROUPINGS),
3031
LintId::of(trailing_empty_array::TRAILING_EMPTY_ARRAY),

src/tools/clippy/clippy_lints/src/lib.rs

+2
Original file line numberDiff line numberDiff line change
@@ -364,6 +364,7 @@ mod self_named_constructors;
364364
mod semicolon_if_nothing_returned;
365365
mod serde_api;
366366
mod shadow;
367+
mod significant_drop_in_scrutinee;
367368
mod single_char_lifetime_names;
368369
mod single_component_path_imports;
369370
mod size_of_in_element_count;
@@ -874,6 +875,7 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf:
874875
store.register_late_pass(move || Box::new(manual_bits::ManualBits::new(msrv)));
875876
store.register_late_pass(|| Box::new(default_union_representation::DefaultUnionRepresentation));
876877
store.register_late_pass(|| Box::new(only_used_in_recursion::OnlyUsedInRecursion));
878+
store.register_late_pass(|| Box::new(significant_drop_in_scrutinee::SignificantDropInScrutinee));
877879
store.register_late_pass(|| Box::new(dbg_macro::DbgMacro));
878880
let cargo_ignore_publish = conf.cargo_ignore_publish;
879881
store.register_late_pass(move || {

0 commit comments

Comments
 (0)