]> git.lizzy.rs Git - rust.git/commitdiff
Implement Any for unsized types
authorSteven Fackler <sfackler@gmail.com>
Fri, 15 Jan 2016 07:02:32 +0000 (23:02 -0800)
committerSteven Fackler <sfackler@gmail.com>
Fri, 15 Jan 2016 07:02:32 +0000 (23:02 -0800)
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
src/libcoretest/any.rs

index 2ad121b03fa11a63a12ab06d2c098a9dcb6690f4..cb9bf935cdb58b9608cce14250419de9524fb58e 100644 (file)
@@ -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>() }
 }
 
index eeaaa3e217e8f1c80bbb0aca874f3f688c3c42ce..a9fc8913182b37ddf18611f492a6fab730ac9d3e 100644 (file)
@@ -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) {