diff options
| author | bors <bors@rust-lang.org> | 2016-08-23 04:16:28 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2016-08-23 04:16:28 -0700 |
| commit | 43204fff5d0a656f8a94bfff3129e04bc9d30ad4 (patch) | |
| tree | 9435f13325fe19f06552bf1b51596f3ea274218b /src/libcore | |
| parent | 599f1b96b19c2a67b1e854a64e0cd43af3de164d (diff) | |
| parent | 1fd791ad62a4bb901be465997d9efbf4090819f0 (diff) | |
| download | rust-43204fff5d0a656f8a94bfff3129e04bc9d30ad4.tar.gz rust-43204fff5d0a656f8a94bfff3129e04bc9d30ad4.zip | |
Auto merge of #35627 - apasel422:coerce-cell, r=alexcrichton
Implement `CoerceUnsized` for `{Cell, RefCell, UnsafeCell}`
These impls are analogous to the one for `NonZero`. It's occasionally useful to be able to coerce the cell types when they're being used inside another abstraction. See Manishearth/rust-gc#17 for an example.
r? @eddyb
Diffstat (limited to 'src/libcore')
| -rw-r--r-- | src/libcore/cell.rs | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/src/libcore/cell.rs b/src/libcore/cell.rs index a388012e1da..2af48ef2fab 100644 --- a/src/libcore/cell.rs +++ b/src/libcore/cell.rs @@ -355,6 +355,9 @@ impl<T: Copy> From<T> for Cell<T> { } } +#[unstable(feature = "coerce_unsized", issue = "27732")] +impl<T: CoerceUnsized<U>, U> CoerceUnsized<Cell<U>> for Cell<T> {} + /// A mutable memory location with dynamically checked borrow rules /// /// See the [module-level documentation](index.html) for more. @@ -793,6 +796,9 @@ impl<T> From<T> for RefCell<T> { } } +#[unstable(feature = "coerce_unsized", issue = "27732")] +impl<T: CoerceUnsized<U>, U> CoerceUnsized<RefCell<U>> for RefCell<T> {} + struct BorrowRef<'b> { borrow: &'b Cell<BorrowFlag>, } @@ -1122,3 +1128,13 @@ impl<T> From<T> for UnsafeCell<T> { UnsafeCell::new(t) } } + +#[unstable(feature = "coerce_unsized", issue = "27732")] +impl<T: CoerceUnsized<U>, U> CoerceUnsized<UnsafeCell<U>> for UnsafeCell<T> {} + +#[allow(unused)] +fn assert_coerce_unsized(a: UnsafeCell<&i32>, b: Cell<&i32>, c: RefCell<&i32>) { + let _: UnsafeCell<&Send> = a; + let _: Cell<&Send> = b; + let _: RefCell<&Send> = c; +} |
