|
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 |
|
@@ -115,7 +114,13 @@ pub enum AliasKind { |
115 | 114 | /// converted to this representation using `AstConv::ast_ty_to_ty`. |
116 | 115 | #[rustc_diagnostic_item = "IrTyKind"] |
117 | 116 | #[derive(derivative::Derivative)] |
118 | | -#[derivative(Clone(bound = ""))] |
| 117 | +#[derivative( |
| 118 | + Clone(bound = ""), |
| 119 | + PartialOrd(bound = ""), |
| 120 | + PartialOrd = "feature_allow_slow_enum", |
| 121 | + Ord(bound = ""), |
| 122 | + Ord = "feature_allow_slow_enum" |
| 123 | +)] |
119 | 124 | pub enum TyKind<I: Interner> { |
120 | 125 | /// The primitive boolean type. Written as `bool`. |
121 | 126 | Bool, |
@@ -378,64 +383,6 @@ impl<I: Interner> PartialEq for TyKind<I> { |
378 | 383 | // This is manually implemented because a derive would require `I: Eq` |
379 | 384 | impl<I: Interner> Eq for TyKind<I> {} |
380 | 385 |
|
381 | | -// This is manually implemented because a derive would require `I: PartialOrd` |
382 | | -impl<I: Interner> PartialOrd for TyKind<I> { |
383 | | - #[inline] |
384 | | - fn partial_cmp(&self, other: &TyKind<I>) -> Option<Ordering> { |
385 | | - Some(self.cmp(other)) |
386 | | - } |
387 | | -} |
388 | | - |
389 | | -// This is manually implemented because a derive would require `I: Ord` |
390 | | -impl<I: Interner> Ord for TyKind<I> { |
391 | | - #[inline] |
392 | | - fn cmp(&self, other: &TyKind<I>) -> Ordering { |
393 | | - tykind_discriminant(self).cmp(&tykind_discriminant(other)).then_with(|| { |
394 | | - match (self, other) { |
395 | | - (Int(a_i), Int(b_i)) => a_i.cmp(b_i), |
396 | | - (Uint(a_u), Uint(b_u)) => a_u.cmp(b_u), |
397 | | - (Float(a_f), Float(b_f)) => a_f.cmp(b_f), |
398 | | - (Adt(a_d, a_s), Adt(b_d, b_s)) => a_d.cmp(b_d).then_with(|| a_s.cmp(b_s)), |
399 | | - (Foreign(a_d), Foreign(b_d)) => a_d.cmp(b_d), |
400 | | - (Array(a_t, a_c), Array(b_t, b_c)) => a_t.cmp(b_t).then_with(|| a_c.cmp(b_c)), |
401 | | - (Slice(a_t), Slice(b_t)) => a_t.cmp(b_t), |
402 | | - (RawPtr(a_t), RawPtr(b_t)) => a_t.cmp(b_t), |
403 | | - (Ref(a_r, a_t, a_m), Ref(b_r, b_t, b_m)) => { |
404 | | - a_r.cmp(b_r).then_with(|| a_t.cmp(b_t).then_with(|| a_m.cmp(b_m))) |
405 | | - } |
406 | | - (FnDef(a_d, a_s), FnDef(b_d, b_s)) => a_d.cmp(b_d).then_with(|| a_s.cmp(b_s)), |
407 | | - (FnPtr(a_s), FnPtr(b_s)) => a_s.cmp(b_s), |
408 | | - (Dynamic(a_p, a_r, a_repr), Dynamic(b_p, b_r, b_repr)) => { |
409 | | - a_p.cmp(b_p).then_with(|| a_r.cmp(b_r).then_with(|| a_repr.cmp(b_repr))) |
410 | | - } |
411 | | - (Closure(a_p, a_s), Closure(b_p, b_s)) => a_p.cmp(b_p).then_with(|| a_s.cmp(b_s)), |
412 | | - (Coroutine(a_d, a_s, a_m), Coroutine(b_d, b_s, b_m)) => { |
413 | | - a_d.cmp(b_d).then_with(|| a_s.cmp(b_s).then_with(|| a_m.cmp(b_m))) |
414 | | - } |
415 | | - ( |
416 | | - CoroutineWitness(a_d, a_s), |
417 | | - CoroutineWitness(b_d, b_s), |
418 | | - ) => match Ord::cmp(a_d, b_d) { |
419 | | - Ordering::Equal => Ord::cmp(a_s, b_s), |
420 | | - cmp => cmp, |
421 | | - }, |
422 | | - (Tuple(a_t), Tuple(b_t)) => a_t.cmp(b_t), |
423 | | - (Alias(a_i, a_p), Alias(b_i, b_p)) => a_i.cmp(b_i).then_with(|| a_p.cmp(b_p)), |
424 | | - (Param(a_p), Param(b_p)) => a_p.cmp(b_p), |
425 | | - (Bound(a_d, a_b), Bound(b_d, b_b)) => a_d.cmp(b_d).then_with(|| a_b.cmp(b_b)), |
426 | | - (Placeholder(a_p), Placeholder(b_p)) => a_p.cmp(b_p), |
427 | | - (Infer(a_t), Infer(b_t)) => a_t.cmp(b_t), |
428 | | - (Error(a_e), Error(b_e)) => a_e.cmp(b_e), |
429 | | - (Bool, Bool) | (Char, Char) | (Str, Str) | (Never, Never) => Ordering::Equal, |
430 | | - _ => { |
431 | | - debug_assert!(false, "This branch must be unreachable, maybe the match is missing an arm? self = {self:?}, other = {other:?}"); |
432 | | - Ordering::Equal |
433 | | - } |
434 | | - } |
435 | | - }) |
436 | | - } |
437 | | -} |
438 | | - |
439 | 386 | // This is manually implemented because a derive would require `I: Hash` |
440 | 387 | impl<I: Interner> hash::Hash for TyKind<I> { |
441 | 388 | fn hash<__H: hash::Hasher>(&self, state: &mut __H) -> () { |
|
0 commit comments