[significant_drop_tightening] Fix #11128

This commit is contained in:
Caio 2023-07-08 17:43:34 -03:00
parent c7bf05c1a4
commit 2be695bf29
5 changed files with 56 additions and 8 deletions

View file

@ -28,6 +28,29 @@ pub fn issue_10413() {
}
}
pub fn issue_11128() {
use std::mem::drop as unlock;
struct Foo {
droppable: Option<Vec<i32>>,
mutex: Mutex<Vec<i32>>,
}
impl Drop for Foo {
fn drop(&mut self) {
if let Some(droppable) = self.droppable.take() {
let lock = self.mutex.lock().unwrap();
let idx_opt = lock.iter().copied().find(|el| Some(el) == droppable.first());
if let Some(idx) = idx_opt {
let local_droppable = vec![lock.first().copied().unwrap_or_default()];
unlock(lock);
drop(local_droppable);
}
}
}
}
}
pub fn path_return_can_be_ignored() -> i32 {
let mutex = Mutex::new(1);
let lock = mutex.lock().unwrap();

View file

@ -27,6 +27,29 @@ pub fn issue_10413() {
}
}
pub fn issue_11128() {
use std::mem::drop as unlock;
struct Foo {
droppable: Option<Vec<i32>>,
mutex: Mutex<Vec<i32>>,
}
impl Drop for Foo {
fn drop(&mut self) {
if let Some(droppable) = self.droppable.take() {
let lock = self.mutex.lock().unwrap();
let idx_opt = lock.iter().copied().find(|el| Some(el) == droppable.first());
if let Some(idx) = idx_opt {
let local_droppable = vec![lock.first().copied().unwrap_or_default()];
unlock(lock);
drop(local_droppable);
}
}
}
}
}
pub fn path_return_can_be_ignored() -> i32 {
let mutex = Mutex::new(1);
let lock = mutex.lock().unwrap();

View file

@ -23,7 +23,7 @@ LL + drop(lock);
|
error: temporary with significant `Drop` can be early dropped
--> $DIR/significant_drop_tightening.rs:56:13
--> $DIR/significant_drop_tightening.rs:79:13
|
LL | / {
LL | | let mutex = Mutex::new(1i32);
@ -43,7 +43,7 @@ LL + drop(lock);
|
error: temporary with significant `Drop` can be early dropped
--> $DIR/significant_drop_tightening.rs:77:13
--> $DIR/significant_drop_tightening.rs:100:13
|
LL | / {
LL | | let mutex = Mutex::new(1i32);
@ -67,7 +67,7 @@ LL +
|
error: temporary with significant `Drop` can be early dropped
--> $DIR/significant_drop_tightening.rs:83:17
--> $DIR/significant_drop_tightening.rs:106:17
|
LL | / {
LL | | let mutex = Mutex::new(vec![1i32]);