diff options
| author | joboet <jonasboettiger@icloud.com> | 2023-02-17 15:58:15 +0100 |
|---|---|---|
| committer | joboet <jonasboettiger@icloud.com> | 2023-02-17 15:58:15 +0100 |
| commit | 642a3247462a582ee97abea1c06c3fabac3bcb3f (patch) | |
| tree | 055a43edbff511ae8f00bf8ac81227b4db197e30 | |
| parent | 746331edf3a6d055859ed0ed70dde1aa883c517d (diff) | |
| download | rust-642a3247462a582ee97abea1c06c3fabac3bcb3f.tar.gz rust-642a3247462a582ee97abea1c06c3fabac3bcb3f.zip | |
std: add regression test for #107466
Tests that messages are immediately dropped once the last receiver is destroyed.
| -rw-r--r-- | library/std/src/sync/mpsc/sync_tests.rs | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/library/std/src/sync/mpsc/sync_tests.rs b/library/std/src/sync/mpsc/sync_tests.rs index 9d2f92ffc9b..632709fd98d 100644 --- a/library/std/src/sync/mpsc/sync_tests.rs +++ b/library/std/src/sync/mpsc/sync_tests.rs @@ -1,5 +1,6 @@ use super::*; use crate::env; +use crate::rc::Rc; use crate::sync::mpmc::SendTimeoutError; use crate::thread; use crate::time::Duration; @@ -656,3 +657,15 @@ fn issue_15761() { repro() } } + +#[test] +fn drop_unreceived() { + let (tx, rx) = sync_channel::<Rc<()>>(1); + let msg = Rc::new(()); + let weak = Rc::downgrade(&msg); + assert!(tx.send(msg).is_ok()); + drop(rx); + // Messages should be dropped immediately when the last receiver is destroyed. + assert!(weak.upgrade().is_none()); + drop(tx); +} |
