Skip to content

Commit 465c405

Browse files
committed
Add test for thread::Scope invariance.
1 parent 12cc7d9 commit 465c405

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

library/std/src/thread/scoped.rs

+13
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,19 @@ pub struct Scope<'env> {
1313
data: ScopeData,
1414
/// Invariance over 'env, to make sure 'env cannot shrink,
1515
/// which is necessary for soundness.
16+
///
17+
/// Without invariance, this would compile fine but be unsound:
18+
///
19+
/// ```compile_fail
20+
/// #![feature(scoped_threads)]
21+
///
22+
/// std::thread::scope(|s| {
23+
/// s.spawn(|s| {
24+
/// let a = String::from("abcd");
25+
/// s.spawn(|_| println!("{:?}", a)); // might run after `a` is dropped
26+
/// });
27+
/// });
28+
/// ```
1629
env: PhantomData<&'env mut &'env ()>,
1730
}
1831

0 commit comments

Comments
 (0)