Rollup merge of #119710 - Nilstrieb:let-_-=-oops, r=TaKO8Ki
Improve `let_underscore_lock` - lint if the lock was in a nested pattern - lint if the lock is inside a `Result<Lock, _>` addresses https://github.com/rust-lang/rust/pull/119704#discussion_r1444044745
This commit is contained in:
commit
72dddeaeb7
7 changed files with 156 additions and 44 deletions
|
|
@ -11,4 +11,6 @@ impl Drop for NontrivialDrop {
|
|||
|
||||
fn main() {
|
||||
let _ = NontrivialDrop; //~WARNING non-binding let on a type that implements `Drop`
|
||||
|
||||
let (_, _) = (NontrivialDrop, NontrivialDrop); // This should be ignored.
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,7 +1,22 @@
|
|||
// check-fail
|
||||
use std::sync::{Arc, Mutex};
|
||||
|
||||
struct Struct<T> {
|
||||
a: T,
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let data = Arc::new(Mutex::new(0));
|
||||
let _ = data.lock().unwrap(); //~ERROR non-binding let on a synchronization lock
|
||||
|
||||
let _ = data.lock(); //~ERROR non-binding let on a synchronization lock
|
||||
|
||||
let (_, _) = (data.lock(), 1); //~ERROR non-binding let on a synchronization lock
|
||||
|
||||
let (_a, Struct { a: _ }) = (0, Struct { a: data.lock() }); //~ERROR non-binding let on a synchronization lock
|
||||
|
||||
(_ , _) = (data.lock(), 1); //~ERROR non-binding let on a synchronization lock
|
||||
|
||||
let _b;
|
||||
(_b, Struct { a: _ }) = (0, Struct { a: data.lock() }); //~ERROR non-binding let on a synchronization lock
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,10 +1,8 @@
|
|||
error: non-binding let on a synchronization lock
|
||||
--> $DIR/let_underscore_lock.rs:6:9
|
||||
--> $DIR/let_underscore_lock.rs:10:9
|
||||
|
|
||||
LL | let _ = data.lock().unwrap();
|
||||
| ^ ^^^^^^^^^^^^^^^^^^^^ this binding will immediately drop the value assigned to it
|
||||
| |
|
||||
| this lock is not assigned to a binding and is immediately dropped
|
||||
| ^ this lock is not assigned to a binding and is immediately dropped
|
||||
|
|
||||
= note: `#[deny(let_underscore_lock)]` on by default
|
||||
help: consider binding to an unused variable to avoid immediately dropping the value
|
||||
|
|
@ -16,5 +14,70 @@ help: consider immediately dropping the value
|
|||
LL | drop(data.lock().unwrap());
|
||||
| ~~~~~ +
|
||||
|
||||
error: aborting due to 1 previous error
|
||||
error: non-binding let on a synchronization lock
|
||||
--> $DIR/let_underscore_lock.rs:12:9
|
||||
|
|
||||
LL | let _ = data.lock();
|
||||
| ^ this lock is not assigned to a binding and is immediately dropped
|
||||
|
|
||||
help: consider binding to an unused variable to avoid immediately dropping the value
|
||||
|
|
||||
LL | let _unused = data.lock();
|
||||
| ~~~~~~~
|
||||
help: consider immediately dropping the value
|
||||
|
|
||||
LL | drop(data.lock());
|
||||
| ~~~~~ +
|
||||
|
||||
error: non-binding let on a synchronization lock
|
||||
--> $DIR/let_underscore_lock.rs:14:10
|
||||
|
|
||||
LL | let (_, _) = (data.lock(), 1);
|
||||
| ^ this lock is not assigned to a binding and is immediately dropped
|
||||
|
|
||||
= help: consider immediately dropping the value using `drop(..)` after the `let` statement
|
||||
help: consider binding to an unused variable to avoid immediately dropping the value
|
||||
|
|
||||
LL | let (_unused, _) = (data.lock(), 1);
|
||||
| ~~~~~~~
|
||||
|
||||
error: non-binding let on a synchronization lock
|
||||
--> $DIR/let_underscore_lock.rs:16:26
|
||||
|
|
||||
LL | let (_a, Struct { a: _ }) = (0, Struct { a: data.lock() });
|
||||
| ^ this lock is not assigned to a binding and is immediately dropped
|
||||
|
|
||||
= help: consider immediately dropping the value using `drop(..)` after the `let` statement
|
||||
help: consider binding to an unused variable to avoid immediately dropping the value
|
||||
|
|
||||
LL | let (_a, Struct { a: _unused }) = (0, Struct { a: data.lock() });
|
||||
| ~~~~~~~
|
||||
|
||||
error: non-binding let on a synchronization lock
|
||||
--> $DIR/let_underscore_lock.rs:18:6
|
||||
|
|
||||
LL | (_ , _) = (data.lock(), 1);
|
||||
| ^ this lock is not assigned to a binding and is immediately dropped
|
||||
|
|
||||
help: consider binding to an unused variable to avoid immediately dropping the value
|
||||
--> $DIR/let_underscore_lock.rs:18:6
|
||||
|
|
||||
LL | (_ , _) = (data.lock(), 1);
|
||||
| ^
|
||||
= help: consider immediately dropping the value using `drop(..)` after the `let` statement
|
||||
|
||||
error: non-binding let on a synchronization lock
|
||||
--> $DIR/let_underscore_lock.rs:21:22
|
||||
|
|
||||
LL | (_b, Struct { a: _ }) = (0, Struct { a: data.lock() });
|
||||
| ^ this lock is not assigned to a binding and is immediately dropped
|
||||
|
|
||||
help: consider binding to an unused variable to avoid immediately dropping the value
|
||||
--> $DIR/let_underscore_lock.rs:21:22
|
||||
|
|
||||
LL | (_b, Struct { a: _ }) = (0, Struct { a: data.lock() });
|
||||
| ^
|
||||
= help: consider immediately dropping the value using `drop(..)` after the `let` statement
|
||||
|
||||
error: aborting due to 6 previous errors
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue