From 6365c4307adb56bb5019f48c50d33b734daffddd Mon Sep 17 00:00:00 2001 From: Sean Leffler Date: Tue, 10 Jan 2017 18:19:01 -0800 Subject: [PATCH 1/2] Add PartialOrd, Ord derivations to TypeId I want to be able to sort a `Vec` of types which contain `TypeId`s, so an `Ord` derivation would be very useful to me. `Hash` already exists, so the missing `PartialOrd` and `Ord` derivations feel like an oversight to me. --- src/libcore/any.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libcore/any.rs b/src/libcore/any.rs index eb0636e8576be..1dbe443925e43 100644 --- a/src/libcore/any.rs +++ b/src/libcore/any.rs @@ -338,7 +338,7 @@ impl Any+Send { /// /// A `TypeId` is currently only available for types which ascribe to `'static`, /// but this limitation may be removed in the future. -#[derive(Clone, Copy, PartialEq, Eq, Debug, Hash)] +#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Debug, Hash)] #[stable(feature = "rust1", since = "1.0.0")] pub struct TypeId { t: u64, From b08ab1e20d8c70e741e3820f16fc277ba6a9a697 Mon Sep 17 00:00:00 2001 From: Sean Leffler Date: Tue, 17 Jan 2017 13:56:46 -0800 Subject: [PATCH 2/2] Add warning about varying hashes/orderings --- src/libcore/any.rs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/libcore/any.rs b/src/libcore/any.rs index 1dbe443925e43..f475c3a1f3cc7 100644 --- a/src/libcore/any.rs +++ b/src/libcore/any.rs @@ -338,6 +338,10 @@ impl Any+Send { /// /// A `TypeId` is currently only available for types which ascribe to `'static`, /// but this limitation may be removed in the future. +/// +/// While `TypeId` implements `Hash`, `PartialOrd`, and `Ord`, it is worth +/// noting that the hashes and ordering will vary between Rust releases. Beware +/// of relying on them outside of your code! #[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Debug, Hash)] #[stable(feature = "rust1", since = "1.0.0")] pub struct TypeId {