Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

std: Stabilize TypeId and tweak BoxAny #21165

Merged
merged 1 commit into from
Jan 20, 2015

Conversation

alexcrichton
Copy link
Member

This commit aims to stabilize the TypeId abstraction by moving it out of the
intrinsics module into the any module of the standard library. Specifically,

  • TypeId is now defined at std::any::TypeId
  • TypeId::hash has been removed in favor of an implementation of Hash.

This commit also performs a final pass over the any module, confirming the
following:

  • Any::get_type_id remains unstable as usage of the Any trait will likely
    never require this, and the Any trait does not need to be implemented for
    any other types. As a result, this implementation detail can remain unstable
    until associated statics are implemented.
  • Any::downcast_ref is now stable
  • Any::downcast_mut is now stable
  • BoxAny remains unstable. While a direct impl on Box<Any> is allowed today
    it does not allow downcasting of trait objects like Box<Any + Send> (those
    returned from Thread::join). This is covered by Replace current quasi-subtyping relationship for object types with coercions #18737.
  • BoxAny::downcast is now stable.

@alexcrichton
Copy link
Member Author

r? @aturon

@rust-highfive
Copy link
Collaborator

r? @aturon

(rust_highfive has picked a reviewer for you, use r? to override)

@aturon aturon mentioned this pull request Jan 15, 2015
38 tasks
/// printing, and showing.
///
/// A `TypeId` is currently only available for types which ascribe to `'static`,
/// but this limitatoin may be removed in the future.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typo limitation

@aturon
Copy link
Member

aturon commented Jan 15, 2015

OK, I'm happy with this, but want to get @nikomatsakis's opinion as well.

/// instantiated with
#[cfg(not(stage0))]
#[stable]
pub fn of<T: ?Sized + 'static>() -> TypeId {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So obviously the key question is this function, right? I'm roughly willing to go with this, but I'd like to get a better understanding of whether we could get by with some kind of bound here.

@nikomatsakis
Copy link
Contributor

On Thu, Jan 15, 2015 at 10:51:22AM -0800, Aaron Turon wrote:

OK, I'm happy with this, but want to get @nikomatsakis's opinion as well.

After discussing with @reem in IRC, it seems like we want to move to a
design where there is a Reflect trait that is automatically
implemented for all types:

trait Reflect : 'static { }
impl Trait for .. { }

TypeId would thus require a Reflect bound

@flaper87 is actually pretty close to having the .. stuff implemented in full, I think,
so this could plausibly land very soon.

In the meantime it might make sense to keep of() as unstable?

@alexcrichton
Copy link
Member Author

r? @aturon

I've marked TypeId::of as #[unstable] for now until the marker trait is implemented

@aturon
Copy link
Member

aturon commented Jan 16, 2015

Sidenote: the (currently stable) blanket impl for Any will likely also grow a reflect bound. This is unlikely to be a breaking change in practice.

@reem
Copy link
Contributor

reem commented Jan 16, 2015

It will actually require a Reflect bound, since it will use TypeId::of.

bors added a commit that referenced this pull request Jan 17, 2015
This commit aims to stabilize the `TypeId` abstraction by moving it out of the
`intrinsics` module into the `any` module of the standard library. Specifically,

* `TypeId` is now defined at `std::any::TypeId`
* `TypeId::hash` has been removed in favor of an implementation of `Hash`.

This commit also performs a final pass over the `any` module, confirming the
following:

* `Any::get_type_id` remains unstable as *usage* of the `Any` trait will likely
  never require this, and the `Any` trait does not need to be implemented for
  any other types. As a result, this implementation detail can remain unstable
  until associated statics are implemented.
* `Any::downcast_ref` is now stable
* `Any::downcast_mut` is now stable
* `BoxAny` remains unstable. While a direct impl on `Box<Any>` is allowed today
  it does not allow downcasting of trait objects like `Box<Any + Send>` (those
  returned from `Thread::join`). This is covered by #18737.
* `BoxAny::downcast` is now stable.
@alexcrichton
Copy link
Member Author

@bors: r=aturon 80d73e9

@alexcrichton
Copy link
Member Author

@bors: retry

@alexcrichton
Copy link
Member Author

@bors r=aturon e1e0450

This commit aims to stabilize the `TypeId` abstraction by moving it out of the
`intrinsics` module into the `any` module of the standard library. Specifically,

* `TypeId` is now defined at `std::any::TypeId`
* `TypeId::hash` has been removed in favor of an implementation of `Hash`.

This commit also performs a final pass over the `any` module, confirming the
following:

* `Any::get_type_id` remains unstable as *usage* of the `Any` trait will likely
  never require this, and the `Any` trait does not need to be implemented for
  any other types. As a result, this implementation detail can remain unstable
  until associated statics are implemented.
* `Any::downcast_ref` is now stable
* `Any::downcast_mut` is now stable
* `BoxAny` remains unstable. While a direct impl on `Box<Any>` is allowed today
  it does not allow downcasting of trait objects like `Box<Any + Send>` (those
  returned from `Thread::join`). This is covered by rust-lang#18737.
* `BoxAny::downcast` is now stable.
@alexcrichton
Copy link
Member Author

@bors: r=aturon 70f165

@bors
Copy link
Contributor

bors commented Jan 19, 2015

🙀 You have the wrong number! Please try again with 70f7.

@alexcrichton
Copy link
Member Author

@bors: r=aturon 70f7165

@bors
Copy link
Contributor

bors commented Jan 19, 2015

⌛ Testing commit 70f7165 with merge 65b61ff...

bors added a commit that referenced this pull request Jan 19, 2015
This commit aims to stabilize the `TypeId` abstraction by moving it out of the
`intrinsics` module into the `any` module of the standard library. Specifically,

* `TypeId` is now defined at `std::any::TypeId`
* `TypeId::hash` has been removed in favor of an implementation of `Hash`.

This commit also performs a final pass over the `any` module, confirming the
following:

* `Any::get_type_id` remains unstable as *usage* of the `Any` trait will likely
  never require this, and the `Any` trait does not need to be implemented for
  any other types. As a result, this implementation detail can remain unstable
  until associated statics are implemented.
* `Any::downcast_ref` is now stable
* `Any::downcast_mut` is now stable
* `BoxAny` remains unstable. While a direct impl on `Box<Any>` is allowed today
  it does not allow downcasting of trait objects like `Box<Any + Send>` (those
  returned from `Thread::join`). This is covered by #18737.
* `BoxAny::downcast` is now stable.
@bors bors merged commit 70f7165 into rust-lang:master Jan 20, 2015
@alexcrichton alexcrichton deleted the second-pass-type-id branch January 20, 2015 04:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants