Skip to content
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
fixup
  • Loading branch information
Julian Orth committed Mar 6, 2015
commit 019b8a57ed5eb1681ed8b8a036e0bdea91b08a26
8 changes: 8 additions & 0 deletions src/libcollections/vec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1813,6 +1813,14 @@ pub struct Drain<'a, T> {
marker1: PhantomData<&'a ()>,
// Drain<T> contains functions to retrieve T but none to insert T.
marker2: PhantomData<Fn() -> T>,

// The straightforward marker would be &'a mut Vec<T>. If we were writing this in safe
// code, that's what we would have after all. However, that would also induce
// invariance on T, which given that Drain only ever extracts values of T is stricter
// than necessary. Therefore, we use this more subtle formulation, which uses a &'a ()
// marker to bind the lifetime securing the vector, and which uses a second marker to
// express that we have a way of producing T instances that we are going to employ.
// This gives covariance in T.
}

unsafe impl<'a, T: Sync> Sync for Drain<'a, T> {}
Expand Down