Skip to content

Commit 997a31e

Browse files
committed
Fix Scope lifetime variance
1 parent 12b4cab commit 997a31e

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

rayon-core/src/scope/mod.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@ impl<'scope> ScopeBuilder<'scope> {
3333
}
3434
}
3535

36+
// FIXME: &'scope Scope<'scope> means that we can spawn scopes during `scope` and after it.
37+
// and before it.
38+
// FIXME: Scopes spawned outside this function must not have access to `tlv`
3639
pub fn scope<OP, R>(&'scope mut self, op: OP) -> R
3740
where
3841
OP: FnOnce(&'scope Scope<'scope>) -> R + 'scope,
@@ -81,7 +84,9 @@ pub struct Scope<'scope> {
8184
/// all of which outlive `'scope`. They're not actually required to be
8285
/// `Sync`, but it's still safe to let the `Scope` implement `Sync` because
8386
/// the closures are only *moved* across threads to be executed.
84-
marker: PhantomData<&'scope ()>,
87+
/// This also ensures 'scope is invariant, which is required for safety,
88+
/// since otherwise you could shrink it as spawn closures which reference shorter data.
89+
marker: PhantomData<Box<FnOnce(&Scope<'scope>) + Send + Sync + 'scope>>,
8590

8691
/// The TLV at the scope's creation. Used to set the TLV for spawned jobs.
8792
tlv: usize,

0 commit comments

Comments
 (0)