2023-02-26 00:08:29 +00:00
|
|
|
error: temporary with significant `Drop` can be early dropped
|
2024-02-27 14:25:18 +00:00
|
|
|
--> tests/ui/significant_drop_tightening.rs:10:9
|
2023-02-26 00:08:29 +00:00
|
|
|
|
|
|
|
|
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`
|
2023-08-01 12:02:21 +00:00
|
|
|
= help: to override `-D warnings` add `#[allow(clippy::significant_drop_tightening)]`
|
2023-02-26 00:08:29 +00:00
|
|
|
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
|
2024-02-27 14:25:18 +00:00
|
|
|
--> tests/ui/significant_drop_tightening.rs:104:13
|
2023-02-26 00:08:29 +00:00
|
|
|
|
|
|
|
|
LL | / {
|
|
|
|
LL | | let mutex = Mutex::new(1i32);
|
|
|
|
LL | | let lock = mutex.lock().unwrap();
|
|
|
|
| | ^^^^
|
|
|
|
LL | | let rslt0 = lock.abs();
|
|
|
|
LL | | let rslt1 = lock.is_positive();
|
|
|
|
LL | | do_heavy_computation_that_takes_time((rslt0, rslt1));
|
|
|
|
LL | | }
|
|
|
|
| |_____- temporary `lock` is currently being dropped at the end of its contained scope
|
|
|
|
|
|
|
|
|
= note: this might lead to unnecessary resource contention
|
|
|
|
help: drop the temporary after the end of its last usage
|
|
|
|
|
|
|
|
|
LL ~ let rslt1 = lock.is_positive();
|
|
|
|
LL + drop(lock);
|
|
|
|
|
|
|
|
|
|
|
|
|
error: temporary with significant `Drop` can be early dropped
|
2024-02-27 14:25:18 +00:00
|
|
|
--> tests/ui/significant_drop_tightening.rs:125:13
|
2023-02-26 00:08:29 +00:00
|
|
|
|
|
|
|
|
LL | / {
|
|
|
|
LL | | let mutex = Mutex::new(1i32);
|
|
|
|
LL | | let lock = mutex.lock().unwrap();
|
|
|
|
| | ^^^^
|
|
|
|
LL | | let rslt0 = lock.abs();
|
|
|
|
LL | | do_heavy_computation_that_takes_time(rslt0);
|
|
|
|
LL | | }
|
|
|
|
| |_____- temporary `lock` is currently being dropped at the end of its contained scope
|
|
|
|
|
|
|
|
|
= note: this might lead to unnecessary resource contention
|
|
|
|
help: merge the temporary construction with its single usage
|
|
|
|
|
|
|
|
|
LL ~
|
|
|
|
LL + let rslt0 = mutex.lock().unwrap().abs();
|
|
|
|
|
|
|
|
|
help: remove separated single usage
|
|
|
|
|
|
|
|
|
LL - let rslt0 = lock.abs();
|
|
|
|
LL +
|
|
|
|
|
|
|
|
|
|
|
|
|
error: temporary with significant `Drop` can be early dropped
|
2024-02-27 14:25:18 +00:00
|
|
|
--> tests/ui/significant_drop_tightening.rs:131:17
|
2023-02-26 00:08:29 +00:00
|
|
|
|
|
|
|
|
LL | / {
|
|
|
|
LL | | let mutex = Mutex::new(vec![1i32]);
|
|
|
|
LL | | let mut lock = mutex.lock().unwrap();
|
|
|
|
| | ^^^^
|
|
|
|
LL | | lock.clear();
|
|
|
|
LL | | do_heavy_computation_that_takes_time(());
|
|
|
|
LL | | }
|
|
|
|
| |_____- temporary `lock` is currently being dropped at the end of its contained scope
|
|
|
|
|
|
|
|
|
= note: this might lead to unnecessary resource contention
|
|
|
|
help: merge the temporary construction with its single usage
|
|
|
|
|
|
|
|
|
LL ~
|
|
|
|
LL + mutex.lock().unwrap().clear();
|
|
|
|
|
|
|
|
|
help: remove separated single usage
|
|
|
|
|
|
|
|
|
LL - lock.clear();
|
|
|
|
LL +
|
|
|
|
|
|
|
|
|
|
|
|
|
error: aborting due to 4 previous errors
|
|
|
|
|