Skip to content

Commit 2581d0c

Browse files
committed
Add regression test for issue 199
1 parent f7b7fef commit 2581d0c

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed

tests/test.rs

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1402,3 +1402,40 @@ pub mod issue183 {
14021402
async fn foo(_n: i32) {}
14031403
}
14041404
}
1405+
1406+
// https://github.com/dtolnay/async-trait/issues/199
1407+
pub mod issue199 {
1408+
use async_trait::async_trait;
1409+
use std::cell::Cell;
1410+
1411+
struct IncrementOnDrop<'a>(&'a Cell<usize>);
1412+
1413+
impl<'a> Drop for IncrementOnDrop<'a> {
1414+
fn drop(&mut self) {
1415+
self.0.set(self.0.get() + 1);
1416+
}
1417+
}
1418+
1419+
#[async_trait(?Send)]
1420+
trait Trait {
1421+
async fn f(counter: &Cell<usize>, arg: IncrementOnDrop<'_>);
1422+
}
1423+
1424+
struct Struct;
1425+
1426+
#[async_trait(?Send)]
1427+
impl Trait for Struct {
1428+
async fn f(counter: &Cell<usize>, _: IncrementOnDrop<'_>) {
1429+
assert_eq!(counter.get(), 0); // second arg not dropped yet
1430+
}
1431+
}
1432+
1433+
#[test]
1434+
fn test() {
1435+
let counter = Cell::new(0);
1436+
let future = Struct::f(&counter, IncrementOnDrop(&counter));
1437+
assert_eq!(counter.get(), 0);
1438+
drop(future);
1439+
assert_eq!(counter.get(), 1);
1440+
}
1441+
}

0 commit comments

Comments
 (0)