about summary refs log tree commit diff
path: root/library/std/src
diff options
context:
space:
mode:
Diffstat (limited to 'library/std/src')
-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 ()>,
 }