@@ -114,6 +114,8 @@ pub enum AliasKind {
114114/// Types written by the user start out as `hir::TyKind` and get
115115/// converted to this representation using `AstConv::ast_ty_to_ty`.
116116#[ rustc_diagnostic_item = "IrTyKind" ]
117+ #[ derive( derivative:: Derivative ) ]
118+ #[ derivative( PartialEq ( skip_discriminant = "true" , bound = "" ) , Eq ( bound = "" ) ) ]
117119pub enum TyKind < I : Interner > {
118120 /// The primitive boolean type. Written as `bool`.
119121 Bool ,
@@ -358,58 +360,6 @@ impl<I: Interner> Clone for TyKind<I> {
358360 }
359361}
360362
361- // This is manually implemented because a derive would require `I: PartialEq`
362- impl < I : Interner > PartialEq for TyKind < I > {
363- #[ inline]
364- fn eq ( & self , other : & TyKind < I > ) -> bool {
365- // You might expect this `match` to be preceded with this:
366- //
367- // tykind_discriminant(self) == tykind_discriminant(other) &&
368- //
369- // but the data patterns in practice are such that a comparison
370- // succeeds 99%+ of the time, and it's faster to omit it.
371- match ( self , other) {
372- ( Int ( a_i) , Int ( b_i) ) => a_i == b_i,
373- ( Uint ( a_u) , Uint ( b_u) ) => a_u == b_u,
374- ( Float ( a_f) , Float ( b_f) ) => a_f == b_f,
375- ( Adt ( a_d, a_s) , Adt ( b_d, b_s) ) => a_d == b_d && a_s == b_s,
376- ( Foreign ( a_d) , Foreign ( b_d) ) => a_d == b_d,
377- ( Array ( a_t, a_c) , Array ( b_t, b_c) ) => a_t == b_t && a_c == b_c,
378- ( Slice ( a_t) , Slice ( b_t) ) => a_t == b_t,
379- ( RawPtr ( a_t) , RawPtr ( b_t) ) => a_t == b_t,
380- ( Ref ( a_r, a_t, a_m) , Ref ( b_r, b_t, b_m) ) => a_r == b_r && a_t == b_t && a_m == b_m,
381- ( FnDef ( a_d, a_s) , FnDef ( b_d, b_s) ) => a_d == b_d && a_s == b_s,
382- ( FnPtr ( a_s) , FnPtr ( b_s) ) => a_s == b_s,
383- ( Dynamic ( a_p, a_r, a_repr) , Dynamic ( b_p, b_r, b_repr) ) => {
384- a_p == b_p && a_r == b_r && a_repr == b_repr
385- }
386- ( Closure ( a_d, a_s) , Closure ( b_d, b_s) ) => a_d == b_d && a_s == b_s,
387- ( Coroutine ( a_d, a_s, a_m) , Coroutine ( b_d, b_s, b_m) ) => {
388- a_d == b_d && a_s == b_s && a_m == b_m
389- }
390- ( CoroutineWitness ( a_d, a_s) , CoroutineWitness ( b_d, b_s) ) => a_d == b_d && a_s == b_s,
391- ( Tuple ( a_t) , Tuple ( b_t) ) => a_t == b_t,
392- ( Alias ( a_i, a_p) , Alias ( b_i, b_p) ) => a_i == b_i && a_p == b_p,
393- ( Param ( a_p) , Param ( b_p) ) => a_p == b_p,
394- ( Bound ( a_d, a_b) , Bound ( b_d, b_b) ) => a_d == b_d && a_b == b_b,
395- ( Placeholder ( a_p) , Placeholder ( b_p) ) => a_p == b_p,
396- ( Infer ( a_t) , Infer ( b_t) ) => a_t == b_t,
397- ( Error ( a_e) , Error ( b_e) ) => a_e == b_e,
398- ( Bool , Bool ) | ( Char , Char ) | ( Str , Str ) | ( Never , Never ) => true ,
399- _ => {
400- debug_assert ! (
401- tykind_discriminant( self ) != tykind_discriminant( other) ,
402- "This branch must be unreachable, maybe the match is missing an arm? self = self = {self:?}, other = {other:?}"
403- ) ;
404- false
405- }
406- }
407- }
408- }
409-
410- // This is manually implemented because a derive would require `I: Eq`
411- impl < I : Interner > Eq for TyKind < I > { }
412-
413363// This is manually implemented because a derive would require `I: PartialOrd`
414364impl < I : Interner > PartialOrd for TyKind < I > {
415365 #[ inline]
@@ -614,6 +564,7 @@ impl<I: Interner> DebugWithInfcx<I> for TyKind<I> {
614564 }
615565 }
616566}
567+
617568// This is manually implemented because a derive would require `I: Debug`
618569impl < I : Interner > fmt:: Debug for TyKind < I > {
619570 fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
0 commit comments