Skip to content

Commit 235d0da

Browse files
Rollup merge of #97739 - a2aaron:let_underscore, r=estebank
Uplift the `let_underscore` lints from clippy into rustc. This PR resolves #97241. This PR adds three lints from clippy--`let_underscore_drop`, `let_underscore_lock`, and `let_underscore_must_use`, which are meant to capture likely-incorrect uses of `let _ = ...` bindings (in particular, doing this on a type with a non-trivial `Drop` causes the `Drop` to occur immediately, instead of at the end of the scope. For a type like `MutexGuard`, this effectively releases the lock immediately, which is almost certainly the wrong behavior) In porting the lints from clippy I had to copy over a bunch of utility functions from `clippy_util` that these lints also relied upon. Is that the right approach? Note that I've set the `must_use` and `drop` lints to Allow by default and set `lock` to Deny by default (this matches the same settings that clippy has). In talking with `@estebank` he informed me to do a Crater run (I am not sure what type of Crater run to request here--I think it's just "check only"?) On the linked issue, there's some discussion about using `must_use` and `Drop` together as a heuristic for when to warn--I did not implement this yet. r? `@estebank`
2 parents 7bf8819 + 7e6cc5f commit 235d0da

File tree

2 files changed

+3
-0
lines changed

2 files changed

+3
-0
lines changed

std/src/sync/mutex.rs

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

std/src/sync/rwlock.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ unsafe impl<T: ?Sized + Send + Sync> Sync for RwLock<T> {}
101101
and cause Futures to not implement `Send`"]
102102
#[stable(feature = "rust1", since = "1.0.0")]
103103
#[clippy::has_significant_drop]
104+
#[cfg_attr(not(test), rustc_diagnostic_item = "RwLockReadGuard")]
104105
pub struct RwLockReadGuard<'a, T: ?Sized + 'a> {
105106
// NB: we use a pointer instead of `&'a T` to avoid `noalias` violations, because a
106107
// `Ref` argument doesn't hold immutability for its whole scope, only until it drops.
@@ -130,6 +131,7 @@ unsafe impl<T: ?Sized + Sync> Sync for RwLockReadGuard<'_, T> {}
130131
and cause Future's to not implement `Send`"]
131132
#[stable(feature = "rust1", since = "1.0.0")]
132133
#[clippy::has_significant_drop]
134+
#[cfg_attr(not(test), rustc_diagnostic_item = "RwLockWriteGuard")]
133135
pub struct RwLockWriteGuard<'a, T: ?Sized + 'a> {
134136
lock: &'a RwLock<T>,
135137
poison: poison::Guard,

0 commit comments

Comments
 (0)