1
1
#![ allow( rustc:: usage_of_ty_tykind) ]
2
2
3
+ #[ cfg( feature = "nightly" ) ]
3
4
use rustc_data_structures:: stable_hasher:: { HashStable , StableHasher } ;
5
+ #[ cfg( feature = "nightly" ) ]
4
6
use rustc_data_structures:: unify:: { EqUnifyValue , UnifyKey } ;
5
7
use std:: fmt;
6
- use std:: mem:: discriminant;
7
8
8
- use crate :: HashStableContext ;
9
9
use crate :: Interner ;
10
10
use crate :: { DebruijnIndex , DebugWithInfcx , InferCtxtLike , WithInfcx } ;
11
11
12
12
use self :: TyKind :: * ;
13
13
14
14
/// The movability of a coroutine / closure literal:
15
15
/// whether a coroutine contains self-references, causing it to be `!Unpin`.
16
- #[ derive( Clone , PartialEq , Eq , PartialOrd , Ord , Hash , Encodable , Decodable , Debug , Copy ) ]
17
- #[ derive( HashStable_Generic ) ]
16
+ #[ derive( Clone , PartialEq , Eq , PartialOrd , Ord , Hash , Debug , Copy ) ]
17
+ #[ cfg_attr ( feature = "nightly" , derive( Encodable , Decodable , HashStable_Generic ) ) ]
18
18
pub enum Movability {
19
19
/// May contain self-references, `!Unpin`.
20
20
Static ,
@@ -23,7 +23,7 @@ pub enum Movability {
23
23
}
24
24
25
25
#[ derive( Clone , PartialEq , Eq , PartialOrd , Ord , Hash , Debug , Copy ) ]
26
- #[ derive ( HashStable_Generic , Encodable , Decodable ) ]
26
+ #[ cfg_attr ( feature = "nightly" , derive ( Encodable , Decodable , HashStable_Generic ) ) ]
27
27
pub enum Mutability {
28
28
// N.B. Order is deliberate, so that Not < Mut
29
29
Not ,
@@ -75,7 +75,7 @@ impl Mutability {
75
75
76
76
/// Specifies how a trait object is represented.
77
77
#[ derive( Clone , Copy , PartialEq , Eq , PartialOrd , Ord , Hash , Debug ) ]
78
- #[ derive( Encodable , Decodable , HashStable_Generic ) ]
78
+ #[ cfg_attr ( feature = "nightly" , derive( Encodable , Decodable , HashStable_Generic ) ) ]
79
79
pub enum DynKind {
80
80
/// An unsized `dyn Trait` object
81
81
Dyn ,
@@ -89,7 +89,7 @@ pub enum DynKind {
89
89
}
90
90
91
91
#[ derive( Clone , Copy , PartialEq , Eq , PartialOrd , Ord , Hash , Debug ) ]
92
- #[ derive( Encodable , Decodable , HashStable_Generic ) ]
92
+ #[ cfg_attr ( feature = "nightly" , derive( Encodable , Decodable , HashStable_Generic ) ) ]
93
93
pub enum AliasKind {
94
94
/// A projection `<Type as Trait>::AssocType`.
95
95
/// Can get normalized away if monomorphic enough.
@@ -109,7 +109,7 @@ pub enum AliasKind {
109
109
///
110
110
/// Types written by the user start out as `hir::TyKind` and get
111
111
/// converted to this representation using `AstConv::ast_ty_to_ty`.
112
- #[ rustc_diagnostic_item = "IrTyKind" ]
112
+ #[ cfg_attr ( feature = "nightly" , rustc_diagnostic_item = "IrTyKind" ) ]
113
113
#[ derive( derivative:: Derivative ) ]
114
114
#[ derivative(
115
115
Clone ( bound = "" ) ,
@@ -119,7 +119,7 @@ pub enum AliasKind {
119
119
Ord = "feature_allow_slow_enum" ,
120
120
Hash ( bound = "" )
121
121
) ]
122
- #[ derive( TyEncodable , TyDecodable ) ]
122
+ #[ cfg_attr ( feature = "nightly" , derive( TyEncodable , TyDecodable ) ) ]
123
123
pub enum TyKind < I : Interner > {
124
124
/// The primitive boolean type. Written as `bool`.
125
125
Bool ,
@@ -407,7 +407,7 @@ impl<I: Interner> DebugWithInfcx<I> for TyKind<I> {
407
407
408
408
write ! ( f, ">" )
409
409
}
410
- Foreign ( d) => f. debug_tuple_field1_finish ( "Foreign" , d ) ,
410
+ Foreign ( d) => f. debug_tuple ( "Foreign" ) . field ( d ) . finish ( ) ,
411
411
Str => write ! ( f, "str" ) ,
412
412
Array ( t, c) => write ! ( f, "[{:?}; {:?}]" , & this. wrap( t) , & this. wrap( c) ) ,
413
413
Slice ( t) => write ! ( f, "[{:?}]" , & this. wrap( t) ) ,
@@ -423,18 +423,20 @@ impl<I: Interner> DebugWithInfcx<I> for TyKind<I> {
423
423
Mutability :: Mut => write ! ( f, "&{:?} mut {:?}" , & this. wrap( r) , & this. wrap( t) ) ,
424
424
Mutability :: Not => write ! ( f, "&{:?} {:?}" , & this. wrap( r) , & this. wrap( t) ) ,
425
425
} ,
426
- FnDef ( d, s) => f. debug_tuple_field2_finish ( "FnDef" , d , & this. wrap ( s) ) ,
426
+ FnDef ( d, s) => f. debug_tuple ( "FnDef" ) . field ( d ) . field ( & this. wrap ( s) ) . finish ( ) ,
427
427
FnPtr ( s) => write ! ( f, "{:?}" , & this. wrap( s) ) ,
428
428
Dynamic ( p, r, repr) => match repr {
429
429
DynKind :: Dyn => write ! ( f, "dyn {:?} + {:?}" , & this. wrap( p) , & this. wrap( r) ) ,
430
430
DynKind :: DynStar => {
431
431
write ! ( f, "dyn* {:?} + {:?}" , & this. wrap( p) , & this. wrap( r) )
432
432
}
433
433
} ,
434
- Closure ( d, s) => f. debug_tuple_field2_finish ( "Closure" , d, & this. wrap ( s) ) ,
435
- Coroutine ( d, s, m) => f. debug_tuple_field3_finish ( "Coroutine" , d, & this. wrap ( s) , m) ,
434
+ Closure ( d, s) => f. debug_tuple ( "Closure" ) . field ( d) . field ( & this. wrap ( s) ) . finish ( ) ,
435
+ Coroutine ( d, s, m) => {
436
+ f. debug_tuple ( "Coroutine" ) . field ( d) . field ( & this. wrap ( s) ) . field ( m) . finish ( )
437
+ }
436
438
CoroutineWitness ( d, s) => {
437
- f. debug_tuple_field2_finish ( "CoroutineWitness" , d , & this. wrap ( s) )
439
+ f. debug_tuple ( "CoroutineWitness" ) . field ( d ) . field ( & this. wrap ( s) ) . finish ( )
438
440
}
439
441
Never => write ! ( f, "!" ) ,
440
442
Tuple ( t) => {
@@ -453,7 +455,7 @@ impl<I: Interner> DebugWithInfcx<I> for TyKind<I> {
453
455
}
454
456
write ! ( f, ")" )
455
457
}
456
- Alias ( i, a) => f. debug_tuple_field2_finish ( "Alias" , i , & this. wrap ( a) ) ,
458
+ Alias ( i, a) => f. debug_tuple ( "Alias" ) . field ( i ) . field ( & this. wrap ( a) ) . finish ( ) ,
457
459
Param ( p) => write ! ( f, "{p:?}" ) ,
458
460
Bound ( d, b) => crate :: debug_bound_var ( f, * d, b) ,
459
461
Placeholder ( p) => write ! ( f, "{p:?}" ) ,
@@ -471,8 +473,9 @@ impl<I: Interner> fmt::Debug for TyKind<I> {
471
473
}
472
474
473
475
// This is not a derived impl because a derive would require `I: HashStable`
476
+ #[ cfg( feature = "nightly" ) ]
474
477
#[ allow( rustc:: usage_of_ty_tykind) ]
475
- impl < CTX : HashStableContext , I : Interner > HashStable < CTX > for TyKind < I >
478
+ impl < CTX : crate :: HashStableContext , I : Interner > HashStable < CTX > for TyKind < I >
476
479
where
477
480
I :: AdtDef : HashStable < CTX > ,
478
481
I :: DefId : HashStable < CTX > ,
@@ -583,7 +586,7 @@ where
583
586
}
584
587
585
588
#[ derive( Clone , Copy , PartialEq , Eq , PartialOrd , Ord , Hash ) ]
586
- #[ derive( Encodable , Decodable , HashStable_Generic ) ]
589
+ #[ cfg_attr ( feature = "nightly" , derive( Encodable , Decodable , HashStable_Generic ) ) ]
587
590
pub enum IntTy {
588
591
Isize ,
589
592
I8 ,
@@ -641,7 +644,7 @@ impl IntTy {
641
644
}
642
645
643
646
#[ derive( Clone , PartialEq , Eq , PartialOrd , Ord , Hash , Copy ) ]
644
- #[ derive( Encodable , Decodable , HashStable_Generic ) ]
647
+ #[ cfg_attr ( feature = "nightly" , derive( Encodable , Decodable , HashStable_Generic ) ) ]
645
648
pub enum UintTy {
646
649
Usize ,
647
650
U8 ,
@@ -699,7 +702,7 @@ impl UintTy {
699
702
}
700
703
701
704
#[ derive( Clone , Copy , PartialEq , Eq , PartialOrd , Ord , Hash ) ]
702
- #[ derive( Encodable , Decodable , HashStable_Generic ) ]
705
+ #[ cfg_attr ( feature = "nightly" , derive( Encodable , Decodable , HashStable_Generic ) ) ]
703
706
pub enum FloatTy {
704
707
F32 ,
705
708
F64 ,
@@ -733,18 +736,21 @@ pub struct FloatVarValue(pub FloatTy);
733
736
rustc_index:: newtype_index! {
734
737
/// A **ty**pe **v**ariable **ID**.
735
738
#[ debug_format = "?{}t" ]
739
+ #[ gate_rustc_only]
736
740
pub struct TyVid { }
737
741
}
738
742
739
743
rustc_index:: newtype_index! {
740
744
/// An **int**egral (`u32`, `i32`, `usize`, etc.) type **v**ariable **ID**.
741
745
#[ debug_format = "?{}i" ]
746
+ #[ gate_rustc_only]
742
747
pub struct IntVid { }
743
748
}
744
749
745
750
rustc_index:: newtype_index! {
746
751
/// A **float**ing-point (`f32` or `f64`) type **v**ariable **ID**.
747
752
#[ debug_format = "?{}f" ]
753
+ #[ gate_rustc_only]
748
754
pub struct FloatVid { }
749
755
}
750
756
@@ -753,7 +759,8 @@ rustc_index::newtype_index! {
753
759
/// E.g., if we have an empty array (`[]`), then we create a fresh
754
760
/// type variable for the element type since we won't know until it's
755
761
/// used what the element type is supposed to be.
756
- #[ derive( Clone , Copy , PartialEq , Eq , PartialOrd , Ord , Hash , Encodable , Decodable ) ]
762
+ #[ derive( Clone , Copy , PartialEq , Eq , PartialOrd , Ord , Hash ) ]
763
+ #[ cfg_attr( feature = "nightly" , derive( Encodable , Decodable ) ) ]
757
764
pub enum InferTy {
758
765
/// A type variable.
759
766
TyVar ( TyVid ) ,
@@ -786,6 +793,7 @@ pub enum InferTy {
786
793
787
794
/// Raw `TyVid` are used as the unification key for `sub_relations`;
788
795
/// they carry no values.
796
+ #[ cfg( feature = "nightly" ) ]
789
797
impl UnifyKey for TyVid {
790
798
type Value = ( ) ;
791
799
#[ inline]
@@ -801,8 +809,10 @@ impl UnifyKey for TyVid {
801
809
}
802
810
}
803
811
812
+ #[ cfg( feature = "nightly" ) ]
804
813
impl EqUnifyValue for IntVarValue { }
805
814
815
+ #[ cfg( feature = "nightly" ) ]
806
816
impl UnifyKey for IntVid {
807
817
type Value = Option < IntVarValue > ;
808
818
#[ inline] // make this function eligible for inlining - it is quite hot.
@@ -818,8 +828,10 @@ impl UnifyKey for IntVid {
818
828
}
819
829
}
820
830
831
+ #[ cfg( feature = "nightly" ) ]
821
832
impl EqUnifyValue for FloatVarValue { }
822
833
834
+ #[ cfg( feature = "nightly" ) ]
823
835
impl UnifyKey for FloatVid {
824
836
type Value = Option < FloatVarValue > ;
825
837
#[ inline]
@@ -835,10 +847,11 @@ impl UnifyKey for FloatVid {
835
847
}
836
848
}
837
849
850
+ #[ cfg( feature = "nightly" ) ]
838
851
impl < CTX > HashStable < CTX > for InferTy {
839
852
fn hash_stable ( & self , ctx : & mut CTX , hasher : & mut StableHasher ) {
840
853
use InferTy :: * ;
841
- discriminant ( self ) . hash_stable ( ctx, hasher) ;
854
+ std :: mem :: discriminant ( self ) . hash_stable ( ctx, hasher) ;
842
855
match self {
843
856
TyVar ( _) | IntVar ( _) | FloatVar ( _) => {
844
857
panic ! ( "type variables should not be hashed: {self:?}" )
0 commit comments