about summary refs log tree commit diff
diff options
context:
space:
mode:
authorjoboet <jonasboettiger@icloud.com>2023-02-17 15:58:15 +0100
committerjoboet <jonasboettiger@icloud.com>2023-02-17 15:58:15 +0100
commit642a3247462a582ee97abea1c06c3fabac3bcb3f (patch)
tree055a43edbff511ae8f00bf8ac81227b4db197e30
parent746331edf3a6d055859ed0ed70dde1aa883c517d (diff)
downloadrust-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.rs13
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);
+}