|
3 | 3 | use rustc_data_structures::stable_hasher::{HashStable, StableHasher}; |
4 | 4 | use rustc_data_structures::unify::{EqUnifyValue, UnifyKey}; |
5 | 5 | use rustc_serialize::{Decodable, Decoder, Encodable}; |
6 | | -use std::cmp::Ordering; |
7 | 6 | use std::mem::discriminant; |
8 | 7 | use std::{fmt, hash}; |
9 | 8 |
|
@@ -114,6 +113,13 @@ pub enum AliasKind { |
114 | 113 | /// Types written by the user start out as `hir::TyKind` and get |
115 | 114 | /// converted to this representation using `AstConv::ast_ty_to_ty`. |
116 | 115 | #[rustc_diagnostic_item = "IrTyKind"] |
| 116 | +#[derive(derivative::Derivative)] |
| 117 | +#[derivative( |
| 118 | + PartialOrd(bound = ""), |
| 119 | + PartialOrd = "feature_allow_slow_enum", |
| 120 | + Ord(bound = ""), |
| 121 | + Ord = "feature_allow_slow_enum" |
| 122 | +)] |
117 | 123 | pub enum TyKind<I: Interner> { |
118 | 124 | /// The primitive boolean type. Written as `bool`. |
119 | 125 | Bool, |
@@ -410,64 +416,6 @@ impl<I: Interner> PartialEq for TyKind<I> { |
410 | 416 | // This is manually implemented because a derive would require `I: Eq` |
411 | 417 | impl<I: Interner> Eq for TyKind<I> {} |
412 | 418 |
|
413 | | -// This is manually implemented because a derive would require `I: PartialOrd` |
414 | | -impl<I: Interner> PartialOrd for TyKind<I> { |
415 | | - #[inline] |
416 | | - fn partial_cmp(&self, other: &TyKind<I>) -> Option<Ordering> { |
417 | | - Some(self.cmp(other)) |
418 | | - } |
419 | | -} |
420 | | - |
421 | | -// This is manually implemented because a derive would require `I: Ord` |
422 | | -impl<I: Interner> Ord for TyKind<I> { |
423 | | - #[inline] |
424 | | - fn cmp(&self, other: &TyKind<I>) -> Ordering { |
425 | | - tykind_discriminant(self).cmp(&tykind_discriminant(other)).then_with(|| { |
426 | | - match (self, other) { |
427 | | - (Int(a_i), Int(b_i)) => a_i.cmp(b_i), |
428 | | - (Uint(a_u), Uint(b_u)) => a_u.cmp(b_u), |
429 | | - (Float(a_f), Float(b_f)) => a_f.cmp(b_f), |
430 | | - (Adt(a_d, a_s), Adt(b_d, b_s)) => a_d.cmp(b_d).then_with(|| a_s.cmp(b_s)), |
431 | | - (Foreign(a_d), Foreign(b_d)) => a_d.cmp(b_d), |
432 | | - (Array(a_t, a_c), Array(b_t, b_c)) => a_t.cmp(b_t).then_with(|| a_c.cmp(b_c)), |
433 | | - (Slice(a_t), Slice(b_t)) => a_t.cmp(b_t), |
434 | | - (RawPtr(a_t), RawPtr(b_t)) => a_t.cmp(b_t), |
435 | | - (Ref(a_r, a_t, a_m), Ref(b_r, b_t, b_m)) => { |
436 | | - a_r.cmp(b_r).then_with(|| a_t.cmp(b_t).then_with(|| a_m.cmp(b_m))) |
437 | | - } |
438 | | - (FnDef(a_d, a_s), FnDef(b_d, b_s)) => a_d.cmp(b_d).then_with(|| a_s.cmp(b_s)), |
439 | | - (FnPtr(a_s), FnPtr(b_s)) => a_s.cmp(b_s), |
440 | | - (Dynamic(a_p, a_r, a_repr), Dynamic(b_p, b_r, b_repr)) => { |
441 | | - a_p.cmp(b_p).then_with(|| a_r.cmp(b_r).then_with(|| a_repr.cmp(b_repr))) |
442 | | - } |
443 | | - (Closure(a_p, a_s), Closure(b_p, b_s)) => a_p.cmp(b_p).then_with(|| a_s.cmp(b_s)), |
444 | | - (Coroutine(a_d, a_s, a_m), Coroutine(b_d, b_s, b_m)) => { |
445 | | - a_d.cmp(b_d).then_with(|| a_s.cmp(b_s).then_with(|| a_m.cmp(b_m))) |
446 | | - } |
447 | | - ( |
448 | | - CoroutineWitness(a_d, a_s), |
449 | | - CoroutineWitness(b_d, b_s), |
450 | | - ) => match Ord::cmp(a_d, b_d) { |
451 | | - Ordering::Equal => Ord::cmp(a_s, b_s), |
452 | | - cmp => cmp, |
453 | | - }, |
454 | | - (Tuple(a_t), Tuple(b_t)) => a_t.cmp(b_t), |
455 | | - (Alias(a_i, a_p), Alias(b_i, b_p)) => a_i.cmp(b_i).then_with(|| a_p.cmp(b_p)), |
456 | | - (Param(a_p), Param(b_p)) => a_p.cmp(b_p), |
457 | | - (Bound(a_d, a_b), Bound(b_d, b_b)) => a_d.cmp(b_d).then_with(|| a_b.cmp(b_b)), |
458 | | - (Placeholder(a_p), Placeholder(b_p)) => a_p.cmp(b_p), |
459 | | - (Infer(a_t), Infer(b_t)) => a_t.cmp(b_t), |
460 | | - (Error(a_e), Error(b_e)) => a_e.cmp(b_e), |
461 | | - (Bool, Bool) | (Char, Char) | (Str, Str) | (Never, Never) => Ordering::Equal, |
462 | | - _ => { |
463 | | - debug_assert!(false, "This branch must be unreachable, maybe the match is missing an arm? self = {self:?}, other = {other:?}"); |
464 | | - Ordering::Equal |
465 | | - } |
466 | | - } |
467 | | - }) |
468 | | - } |
469 | | -} |
470 | | - |
471 | 419 | // This is manually implemented because a derive would require `I: Hash` |
472 | 420 | impl<I: Interner> hash::Hash for TyKind<I> { |
473 | 421 | fn hash<__H: hash::Hasher>(&self, state: &mut __H) -> () { |
@@ -614,6 +562,7 @@ impl<I: Interner> DebugWithInfcx<I> for TyKind<I> { |
614 | 562 | } |
615 | 563 | } |
616 | 564 | } |
| 565 | + |
617 | 566 | // This is manually implemented because a derive would require `I: Debug` |
618 | 567 | impl<I: Interner> fmt::Debug for TyKind<I> { |
619 | 568 | fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { |
|
0 commit comments