Skip to content

Commit 642a324

Browse files
committed
std: add regression test for rust-lang#107466
Tests that messages are immediately dropped once the last receiver is destroyed.
1 parent 746331e commit 642a324

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

library/std/src/sync/mpsc/sync_tests.rs

+13
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use super::*;
22
use crate::env;
3+
use crate::rc::Rc;
34
use crate::sync::mpmc::SendTimeoutError;
45
use crate::thread;
56
use crate::time::Duration;
@@ -656,3 +657,15 @@ fn issue_15761() {
656657
repro()
657658
}
658659
}
660+
661+
#[test]
662+
fn drop_unreceived() {
663+
let (tx, rx) = sync_channel::<Rc<()>>(1);
664+
let msg = Rc::new(());
665+
let weak = Rc::downgrade(&msg);
666+
assert!(tx.send(msg).is_ok());
667+
drop(rx);
668+
// Messages should be dropped immediately when the last receiver is destroyed.
669+
assert!(weak.upgrade().is_none());
670+
drop(tx);
671+
}

0 commit comments

Comments
 (0)