From 5d2275d53ec1f66527db9d903ed84a258927e0ba Mon Sep 17 00:00:00 2001 From: Steven Fackler Date: Thu, 14 Jan 2016 23:02:32 -0800 Subject: [PATCH] Implement Any for unsized types 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. --- src/libcore/any.rs | 2 +- src/libcoretest/any.rs | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/src/libcore/any.rs b/src/libcore/any.rs index 2ad121b03fa11..cb9bf935cdb58 100644 --- a/src/libcore/any.rs +++ b/src/libcore/any.rs @@ -99,7 +99,7 @@ pub trait Any: Reflect + 'static { } #[stable(feature = "rust1", since = "1.0.0")] -impl Any for T { +impl Any for T { fn get_type_id(&self) -> TypeId { TypeId::of::() } } diff --git a/src/libcoretest/any.rs b/src/libcoretest/any.rs index eeaaa3e217e8f..a9fc8913182b3 100644 --- a/src/libcoretest/any.rs +++ b/src/libcoretest/any.rs @@ -119,6 +119,11 @@ fn any_fixed_vec() { assert!(!test.is::<[usize; 10]>()); } +#[test] +fn any_unsized() { + fn is_any() {} + is_any::<[i32]>(); +} #[bench] fn bench_downcast_ref(b: &mut Bencher) {