Evaluate the return expression of a block
This commit is contained in:
parent
e1da00210a
commit
7518969501
4 changed files with 95 additions and 14 deletions
|
|
@ -4,6 +4,26 @@
|
|||
|
||||
use std::sync::Mutex;
|
||||
|
||||
pub fn complex_return_triggers_the_lint() -> i32 {
|
||||
fn foo() -> i32 {
|
||||
1
|
||||
}
|
||||
let mutex = Mutex::new(1);
|
||||
let lock = mutex.lock().unwrap();
|
||||
let _ = *lock;
|
||||
let _ = *lock;
|
||||
drop(lock);
|
||||
foo()
|
||||
}
|
||||
|
||||
pub fn path_return_can_be_ignored() -> i32 {
|
||||
let mutex = Mutex::new(1);
|
||||
let lock = mutex.lock().unwrap();
|
||||
let rslt = *lock;
|
||||
let _ = *lock;
|
||||
rslt
|
||||
}
|
||||
|
||||
pub fn post_bindings_can_be_ignored() {
|
||||
let mutex = Mutex::new(1);
|
||||
let lock = mutex.lock().unwrap();
|
||||
|
|
|
|||
|
|
@ -4,6 +4,25 @@
|
|||
|
||||
use std::sync::Mutex;
|
||||
|
||||
pub fn complex_return_triggers_the_lint() -> i32 {
|
||||
fn foo() -> i32 {
|
||||
1
|
||||
}
|
||||
let mutex = Mutex::new(1);
|
||||
let lock = mutex.lock().unwrap();
|
||||
let _ = *lock;
|
||||
let _ = *lock;
|
||||
foo()
|
||||
}
|
||||
|
||||
pub fn path_return_can_be_ignored() -> i32 {
|
||||
let mutex = Mutex::new(1);
|
||||
let lock = mutex.lock().unwrap();
|
||||
let rslt = *lock;
|
||||
let _ = *lock;
|
||||
rslt
|
||||
}
|
||||
|
||||
pub fn post_bindings_can_be_ignored() {
|
||||
let mutex = Mutex::new(1);
|
||||
let lock = mutex.lock().unwrap();
|
||||
|
|
|
|||
|
|
@ -1,5 +1,29 @@
|
|||
error: temporary with significant `Drop` can be early dropped
|
||||
--> $DIR/significant_drop_tightening.rs:25:13
|
||||
--> $DIR/significant_drop_tightening.rs:12:9
|
||||
|
|
||||
LL | pub fn complex_return_triggers_the_lint() -> i32 {
|
||||
| __________________________________________________-
|
||||
LL | | fn foo() -> i32 {
|
||||
LL | | 1
|
||||
LL | | }
|
||||
LL | | let mutex = Mutex::new(1);
|
||||
LL | | let lock = mutex.lock().unwrap();
|
||||
| | ^^^^
|
||||
... |
|
||||
LL | | foo()
|
||||
LL | | }
|
||||
| |_- temporary `lock` is currently being dropped at the end of its contained scope
|
||||
|
|
||||
= note: this might lead to unnecessary resource contention
|
||||
= note: `-D clippy::significant-drop-tightening` implied by `-D warnings`
|
||||
help: drop the temporary after the end of its last usage
|
||||
|
|
||||
LL ~ let _ = *lock;
|
||||
LL + drop(lock);
|
||||
|
|
||||
|
||||
error: temporary with significant `Drop` can be early dropped
|
||||
--> $DIR/significant_drop_tightening.rs:44:13
|
||||
|
|
||||
LL | / {
|
||||
LL | | let mutex = Mutex::new(1i32);
|
||||
|
|
@ -12,7 +36,6 @@ LL | | }
|
|||
| |_____- temporary `lock` is currently being dropped at the end of its contained scope
|
||||
|
|
||||
= note: this might lead to unnecessary resource contention
|
||||
= note: `-D clippy::significant-drop-tightening` implied by `-D warnings`
|
||||
help: drop the temporary after the end of its last usage
|
||||
|
|
||||
LL ~ let rslt1 = lock.is_positive();
|
||||
|
|
@ -20,7 +43,7 @@ LL + drop(lock);
|
|||
|
|
||||
|
||||
error: temporary with significant `Drop` can be early dropped
|
||||
--> $DIR/significant_drop_tightening.rs:46:13
|
||||
--> $DIR/significant_drop_tightening.rs:65:13
|
||||
|
|
||||
LL | / {
|
||||
LL | | let mutex = Mutex::new(1i32);
|
||||
|
|
@ -44,7 +67,7 @@ LL +
|
|||
|
|
||||
|
||||
error: temporary with significant `Drop` can be early dropped
|
||||
--> $DIR/significant_drop_tightening.rs:52:17
|
||||
--> $DIR/significant_drop_tightening.rs:71:17
|
||||
|
|
||||
LL | / {
|
||||
LL | | let mutex = Mutex::new(vec![1i32]);
|
||||
|
|
@ -67,5 +90,5 @@ LL - lock.clear();
|
|||
LL +
|
||||
|
|
||||
|
||||
error: aborting due to 3 previous errors
|
||||
error: aborting due to 4 previous errors
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue