diff options
| author | bors <bors@rust-lang.org> | 2015-03-17 13:29:48 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2015-03-17 13:29:48 +0000 |
| commit | c64d671671aea2e44ee7fc6eb00ee75fc30ed7b9 (patch) | |
| tree | 058ec26f2e5ae48d415b7730c5f2d51df9b369a0 /src/liballoc | |
| parent | 31ba21228e0e539a665ce14ab3a176e30e57f822 (diff) | |
| parent | 277b4f035aa7e42330aabbc243a8fcb5cf4cc8bd (diff) | |
| download | rust-c64d671671aea2e44ee7fc6eb00ee75fc30ed7b9.tar.gz rust-c64d671671aea2e44ee7fc6eb00ee75fc30ed7b9.zip | |
Auto merge of #23423 - nikomatsakis:issue-18737-trait-subtyping, r=nrc
This upcast coercion currently never requires vtable changes. It should be generalized. This is a [breaking-change] -- if you have an impl on an object type like `impl SomeTrait`, then this will no longer be applicable to object types like `SomeTrait+Send`. In the standard library, this primarily affected `Any`, and this PR adds impls for `Any+Send` as to keep the API the same in practice. An alternate workaround is to use UFCS form or standalone fns. For more details, see <https://github.com/rust-lang/rust/issues/18737#issuecomment-78450798>. r? @nrc
Diffstat (limited to 'src/liballoc')
| -rw-r--r-- | src/liballoc/boxed.rs | 11 |
1 files changed, 10 insertions, 1 deletions
diff --git a/src/liballoc/boxed.rs b/src/liballoc/boxed.rs index 451237d7596..50935e6404d 100644 --- a/src/liballoc/boxed.rs +++ b/src/liballoc/boxed.rs @@ -241,7 +241,7 @@ pub trait BoxAny { /// Returns the boxed value if it is of type `T`, or /// `Err(Self)` if it isn't. #[stable(feature = "rust1", since = "1.0.0")] - fn downcast<T: 'static>(self) -> Result<Box<T>, Self>; + fn downcast<T: 'static>(self) -> Result<Box<T>, Box<Any>>; } #[stable(feature = "rust1", since = "1.0.0")] @@ -264,6 +264,15 @@ impl BoxAny for Box<Any> { } } +#[cfg(not(stage0))] +#[stable(feature = "rust1", since = "1.0.0")] +impl BoxAny for Box<Any+Send> { + #[inline] + fn downcast<T: 'static>(self) -> Result<Box<T>, Box<Any>> { + <Box<Any>>::downcast(self) + } +} + #[stable(feature = "rust1", since = "1.0.0")] impl<T: fmt::Display + ?Sized> fmt::Display for Box<T> { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { |
