From 54b728a9e392f4e4ff580d8a3f06d79122b8d1dc Mon Sep 17 00:00:00 2001 From: Yosh Date: Fri, 23 Jun 2023 02:57:50 +0200 Subject: [PATCH] validate miri --- src/future/try_join/tuple.rs | 68 ++++++++++++++++++------------------ 1 file changed, 34 insertions(+), 34 deletions(-) diff --git a/src/future/try_join/tuple.rs b/src/future/try_join/tuple.rs index f379cc3..36f28e4 100644 --- a/src/future/try_join/tuple.rs +++ b/src/future/try_join/tuple.rs @@ -362,38 +362,38 @@ mod test { }); } - // #[test] - // fn does_not_leak_memory() { - // use core::cell::RefCell; - // use futures_lite::future::pending; - - // thread_local! { - // static NOT_LEAKING: RefCell = RefCell::new(false); - // }; - - // struct FlipFlagAtDrop; - // impl Drop for FlipFlagAtDrop { - // fn drop(&mut self) { - // NOT_LEAKING.with(|v| { - // *v.borrow_mut() = true; - // }); - // } - // } - - // futures_lite::future::block_on(async { - // // this will trigger Miri if we don't drop the memory - // let string = future::ready("memory leak".to_owned()); - - // // this will not flip the thread_local flag if we don't drop the memory - // let flip = future::ready(FlipFlagAtDrop); - - // let leak = (string, flip, pending::()).try_join(); - - // _ = futures_lite::future::poll_once(leak).await; - // }); - - // NOT_LEAKING.with(|flag| { - // assert!(*flag.borrow()); - // }) - // } + #[test] + fn does_not_leak_memory() { + use core::cell::RefCell; + use futures_lite::future::pending; + + thread_local! { + static NOT_LEAKING: RefCell = RefCell::new(false); + }; + + struct FlipFlagAtDrop; + impl Drop for FlipFlagAtDrop { + fn drop(&mut self) { + NOT_LEAKING.with(|v| { + *v.borrow_mut() = true; + }); + } + } + + futures_lite::future::block_on(async { + // this will trigger Miri if we don't drop the memory + let string = future::ready(io::Result::Ok("memory leak".to_owned())); + + // this will not flip the thread_local flag if we don't drop the memory + let flip = future::ready(io::Result::Ok(FlipFlagAtDrop)); + + let leak = (string, flip, pending::>()).try_join(); + + _ = futures_lite::future::poll_once(leak).await; + }); + + NOT_LEAKING.with(|flag| { + assert!(*flag.borrow()); + }) + } }