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/libcore | |
| 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/libcore')
| -rw-r--r-- | src/libcore/any.rs | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/src/libcore/any.rs b/src/libcore/any.rs index 462b6771b4a..6d3fac4c68d 100644 --- a/src/libcore/any.rs +++ b/src/libcore/any.rs @@ -71,6 +71,7 @@ #![stable(feature = "rust1", since = "1.0.0")] +use marker::Send; use mem::transmute; use option::Option::{self, Some, None}; use raw::TraitObject; @@ -154,6 +155,31 @@ impl Any { } } +#[cfg(not(stage0))] +impl Any+Send { + /// Forwards to the method defined on the type `Any`. + #[stable(feature = "rust1", since = "1.0.0")] + #[inline] + pub fn is<T: 'static>(&self) -> bool { + Any::is::<T>(self) + } + + /// Forwards to the method defined on the type `Any`. + #[stable(feature = "rust1", since = "1.0.0")] + #[inline] + pub fn downcast_ref<T: 'static>(&self) -> Option<&T> { + Any::downcast_ref::<T>(self) + } + + /// Forwards to the method defined on the type `Any`. + #[stable(feature = "rust1", since = "1.0.0")] + #[inline] + pub fn downcast_mut<T: 'static>(&mut self) -> Option<&mut T> { + Any::downcast_mut::<T>(self) + } +} + + /////////////////////////////////////////////////////////////////////////////// // TypeID and its methods /////////////////////////////////////////////////////////////////////////////// |
