Skip to content

Commit c6772b4

Browse files
committed
Implement Ord as necessary
1 parent 0bbc422 commit c6772b4

File tree

4 files changed

+33
-5
lines changed

4 files changed

+33
-5
lines changed

src/librustc/traits/project.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ pub struct MismatchedProjectionTypes<'tcx> {
101101
pub err: ty::error::TypeError<'tcx>
102102
}
103103

104-
#[derive(PartialEq, Eq, Debug)]
104+
#[derive(PartialEq, Eq, PartialOrd, Ord, Debug)]
105105
enum ProjectionTyCandidate<'tcx> {
106106
// from a where-clause in the env or object type
107107
ParamEnv(ty::PolyProjectionPredicate<'tcx>),

src/librustc/ty/mod.rs

+29-1
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ use util::nodemap::{NodeSet, DefIdMap, FxHashMap, FxHashSet};
3939
use serialize::{self, Encodable, Encoder};
4040
use std::collections::BTreeMap;
4141
use std::cmp;
42+
use std::cmp::Ordering;
4243
use std::fmt;
4344
use std::hash::{Hash, Hasher};
4445
use std::iter::FromIterator;
@@ -497,6 +498,20 @@ impl<'tcx> Hash for TyS<'tcx> {
497498
}
498499
}
499500

501+
impl<'tcx> Ord for TyS<'tcx> {
502+
#[inline]
503+
fn cmp(&self, other: &TyS<'tcx>) -> Ordering {
504+
// (self as *const _).cmp(other as *const _)
505+
(self as *const TyS<'tcx>).cmp(&(other as *const TyS<'tcx>))
506+
}
507+
}
508+
impl<'tcx> PartialOrd for TyS<'tcx> {
509+
#[inline]
510+
fn partial_cmp(&self, other: &TyS<'tcx>) -> Option<Ordering> {
511+
Some(self.cmp(other))
512+
}
513+
}
514+
500515
impl<'tcx> TyS<'tcx> {
501516
pub fn is_primitive_ty(&self) -> bool {
502517
match self.sty {
@@ -566,6 +581,19 @@ impl<T> PartialEq for Slice<T> {
566581
}
567582
impl<T> Eq for Slice<T> {}
568583

584+
impl<T> Ord for Slice<T> {
585+
#[inline]
586+
fn cmp(&self, other: &Slice<T>) -> Ordering {
587+
(&self.0 as *const [T]).cmp(&(&other.0 as *const [T]))
588+
}
589+
}
590+
impl<T> PartialOrd for Slice<T> {
591+
#[inline]
592+
fn partial_cmp(&self, other: &Slice<T>) -> Option<Ordering> {
593+
Some(self.cmp(other))
594+
}
595+
}
596+
569597
impl<T> Hash for Slice<T> {
570598
fn hash<H: Hasher>(&self, s: &mut H) {
571599
(self.as_ptr(), self.len()).hash(s)
@@ -1101,7 +1129,7 @@ pub type PolySubtypePredicate<'tcx> = ty::Binder<SubtypePredicate<'tcx>>;
11011129
/// equality between arbitrary types. Processing an instance of
11021130
/// Form #2 eventually yields one of these `ProjectionPredicate`
11031131
/// instances to normalize the LHS.
1104-
#[derive(Copy, Clone, PartialEq, Eq, Hash, RustcEncodable, RustcDecodable)]
1132+
#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, RustcEncodable, RustcDecodable)]
11051133
pub struct ProjectionPredicate<'tcx> {
11061134
pub projection_ty: ProjectionTy<'tcx>,
11071135
pub ty: Ty<'tcx>,

src/librustc/ty/sty.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -646,7 +646,7 @@ impl<'tcx> PolyExistentialTraitRef<'tcx> {
646646
/// erase, or otherwise "discharge" these bound regions, we change the
647647
/// type from `Binder<T>` to just `T` (see
648648
/// e.g. `liberate_late_bound_regions`).
649-
#[derive(Copy, Clone, PartialEq, Eq, Hash, Debug, RustcEncodable, RustcDecodable)]
649+
#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Debug, RustcEncodable, RustcDecodable)]
650650
pub struct Binder<T>(pub T);
651651

652652
impl<T> Binder<T> {
@@ -746,7 +746,7 @@ impl<T> Binder<T> {
746746

747747
/// Represents the projection of an associated type. In explicit UFCS
748748
/// form this would be written `<T as Trait<..>>::N`.
749-
#[derive(Copy, Clone, PartialEq, Eq, Hash, Debug, RustcEncodable, RustcDecodable)]
749+
#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Debug, RustcEncodable, RustcDecodable)]
750750
pub struct ProjectionTy<'tcx> {
751751
/// The parameters of the associated item.
752752
pub substs: &'tcx Substs<'tcx>,

src/librustc/ty/subst.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ use std::mem;
2929
/// To reduce memory usage, a `Kind` is a interned pointer,
3030
/// with the lowest 2 bits being reserved for a tag to
3131
/// indicate the type (`Ty` or `Region`) it points to.
32-
#[derive(Copy, Clone, PartialEq, Eq, Hash)]
32+
#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
3333
pub struct Kind<'tcx> {
3434
ptr: NonZero<usize>,
3535
marker: PhantomData<(Ty<'tcx>, ty::Region<'tcx>)>

0 commit comments

Comments
 (0)