Remove subtyping for object types and replace with an *upcast* coercion.

This upcast coercion currently preserves the vtable for the object, but
eventually it can be used to create a derived vtable. The upcast
coercion is not introduced into method dispatch; see comment on #18737
for information about why. Fixes #18737.
This commit is contained in:
Niko Matsakis
2015-02-17 05:17:19 -05:00
parent bde09eea35
commit 5f5ed62298
18 changed files with 187 additions and 101 deletions

View File

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