Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 2 additions & 7 deletions src/libcore/any.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,20 +91,15 @@ pub enum Void { }
/// Every type with no non-`'static` references implements `Any`, so `Any` can
/// be used as a trait object to emulate the effects dynamic typing.
#[stable]
pub trait Any: AnyPrivate + 'static {}

/// An inner trait to ensure that only this module can call `get_type_id()`.
pub trait AnyPrivate {
pub trait Any: 'static {
/// Get the `TypeId` of `self`
fn get_type_id(&self) -> TypeId;
}

impl<T: 'static> AnyPrivate for T {
impl<T: 'static> Any for T {
fn get_type_id(&self) -> TypeId { TypeId::of::<T>() }
}

impl<T: 'static + AnyPrivate> Any for T {}

///////////////////////////////////////////////////////////////////////////////
// Extension methods for Any trait objects.
// Implemented as three extension traits so that the methods can be generic.
Expand Down
2 changes: 0 additions & 2 deletions src/test/compile-fail/issue-14366.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,4 @@ fn main() {
let _x = "test" as &::std::any::Any;
//~^ ERROR the trait `core::kinds::Sized` is not implemented for the type `str`
//~^^ NOTE the trait `core::kinds::Sized` must be implemented for the cast to the object type
//~^^^ ERROR the trait `core::kinds::Sized` is not implemented for the type `str`
//~^^^^ NOTE the trait `core::kinds::Sized` must be implemented for the cast to the object type
}