Skip to content

Commit

Permalink
Implement Any for unsized types
Browse files Browse the repository at this point in the history
This is a bit weird since unsized types can't be used in trait objects,
but Any is *also* used as pure marker trait since Reflect isn't stable.
There are many cases (e.g. TypeMap) where all you need is a TypeId.
  • Loading branch information
sfackler committed Jan 15, 2016
1 parent 9f6917d commit 5d2275d
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/libcore/any.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ pub trait Any: Reflect + 'static {
}

#[stable(feature = "rust1", since = "1.0.0")]
impl<T: Reflect + 'static> Any for T {
impl<T: Reflect + 'static + ?Sized > Any for T {
fn get_type_id(&self) -> TypeId { TypeId::of::<T>() }
}

Expand Down
5 changes: 5 additions & 0 deletions src/libcoretest/any.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,11 @@ fn any_fixed_vec() {
assert!(!test.is::<[usize; 10]>());
}

#[test]
fn any_unsized() {
fn is_any<T: Any + ?Sized>() {}
is_any::<[i32]>();
}

#[bench]
fn bench_downcast_ref(b: &mut Bencher) {
Expand Down

0 comments on commit 5d2275d

Please sign in to comment.