Skip to content

Commit

Permalink
fixup
Browse files Browse the repository at this point in the history
  • Loading branch information
Julian Orth committed Mar 6, 2015
1 parent 093c526 commit ad305ac
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/libcollections/vec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1804,14 +1804,15 @@ impl DrainRange for usize {
#[unsafe_no_drop_flag]
#[unstable(feature = "collections",
reason = "recently added as part of collections reform 2")]
pub struct Drain<'a, T: 'a> {
pub struct Drain<'a, T> {
tail: usize,
start: *const T,
end: *const T,
left: *const T,
right: *const T,
marker1: PhantomData<&'a ()>,
marker2: PhantomData<T>,
// Drain<T> contains functions to retrieve T but none to insert T.
marker2: PhantomData<Fn() -> T>,

This comment has been minimized.

Copy link
@nikomatsakis

nikomatsakis Mar 6, 2015

Contributor

Can you say something like this:

// 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.

Feel free to make it less wordy. :) The main thing I am interested in is expressing why we avoided the straightforward thing and why covariance is believed to be correct. (You might also indicate a brief note that this similarly implies T:'a is not needed.)

}

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

0 comments on commit ad305ac

Please sign in to comment.