Skip to content

Commit

Permalink
Add a comment for covariant Ref
Browse files Browse the repository at this point in the history
  • Loading branch information
cuviper committed May 17, 2022
1 parent 1e53fab commit 1f33c92
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion library/core/src/cell.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1318,6 +1318,7 @@ impl Clone for BorrowRef<'_> {
pub struct Ref<'b, T: ?Sized + 'b> {
// NB: we use a pointer instead of `&'b T` to avoid `noalias` violations, because a
// `Ref` argument doesn't hold immutability for its whole scope, only until it drops.
// `NonNull` is also covariant over `T`, just like we would have with `&T`.
value: NonNull<T>,
borrow: BorrowRef<'b>,
}
Expand Down Expand Up @@ -1704,7 +1705,7 @@ pub struct RefMut<'b, T: ?Sized + 'b> {
// `RefMut` argument doesn't hold exclusivity for its whole scope, only until it drops.
value: NonNull<T>,
borrow: BorrowRefMut<'b>,
// NonNull is covariant over T, so we need to reintroduce invariance.
// `NonNull` is covariant over `T`, so we need to reintroduce invariance.
marker: PhantomData<&'b mut T>,
}

Expand Down

0 comments on commit 1f33c92

Please sign in to comment.