about summary refs log tree commit diff
path: root/library/std/src/thread
diff options
context:
space:
mode:
authorMara Bos <m-ou.se@m-ou.se>2022-01-22 17:15:08 +0100
committerMara Bos <m-ou.se@m-ou.se>2022-01-22 17:15:08 +0100
commit465c405418409cdd1d4c1537c44849effd01501d (patch)
treeb3014d1247c39967416f38933e3968af6b2e600f /library/std/src/thread
parent12cc7d9e1552068e224fd484a7dcc92a5d337110 (diff)
downloadrust-465c405418409cdd1d4c1537c44849effd01501d.tar.gz
rust-465c405418409cdd1d4c1537c44849effd01501d.zip
Add test for thread::Scope invariance.
Diffstat (limited to 'library/std/src/thread')
-rw-r--r--library/std/src/thread/scoped.rs13
1 files changed, 13 insertions, 0 deletions
diff --git a/library/std/src/thread/scoped.rs b/library/std/src/thread/scoped.rs
index c1b501f3aff..9dd7c15fc59 100644
--- a/library/std/src/thread/scoped.rs
+++ b/library/std/src/thread/scoped.rs
@@ -13,6 +13,19 @@ pub struct Scope<'env> {
     data: ScopeData,
     /// Invariance over 'env, to make sure 'env cannot shrink,
     /// which is necessary for soundness.
+    ///
+    /// Without invariance, this would compile fine but be unsound:
+    ///
+    /// ```compile_fail
+    /// #![feature(scoped_threads)]
+    ///
+    /// std::thread::scope(|s| {
+    ///     s.spawn(|s| {
+    ///         let a = String::from("abcd");
+    ///         s.spawn(|_| println!("{:?}", a)); // might run after `a` is dropped
+    ///     });
+    /// });
+    /// ```
     env: PhantomData<&'env mut &'env ()>,
 }