Skip to content

Commit b6f36bd

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

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

rayon-core/src/scope/mod.rs

Lines changed: 6 additions & 5 deletions
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,
@@ -77,11 +80,9 @@ pub struct Scope<'scope> {
7780
/// latch to set when the counter drops to zero (and hence this scope is complete)
7881
job_completed_latch: CountLatch,
7982

80-
/// You can think of a scope as containing a list of closures to execute,
81-
/// all of which outlive `'scope`. They're not actually required to be
82-
/// `Sync`, but it's still safe to let the `Scope` implement `Sync` because
83-
/// the closures are only *moved* across threads to be executed.
84-
marker: PhantomData<&'scope ()>,
83+
/// This ensures 'scope is invariant, which is required for safety,
84+
/// since otherwise you could shrink it as spawn closures which reference shorter data.
85+
marker: PhantomData<&'scope mut &'scope ()>,
8586

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

0 commit comments

Comments
 (0)