@@ -47,6 +47,35 @@ type Disr = ConstInt;
47
47
}
48
48
49
49
50
+ macro_rules! typed_literal {
51
+ ( $tcx: expr, $ty: expr, $lit: expr) => {
52
+ match $ty {
53
+ SignedInt ( ast:: IntTy :: I8 ) => ConstInt :: I8 ( $lit) ,
54
+ SignedInt ( ast:: IntTy :: I16 ) => ConstInt :: I16 ( $lit) ,
55
+ SignedInt ( ast:: IntTy :: I32 ) => ConstInt :: I32 ( $lit) ,
56
+ SignedInt ( ast:: IntTy :: I64 ) => ConstInt :: I64 ( $lit) ,
57
+ SignedInt ( ast:: IntTy :: I128 ) => ConstInt :: I128 ( $lit) ,
58
+ SignedInt ( ast:: IntTy :: Is ) => match $tcx. sess. target. int_type {
59
+ ast:: IntTy :: I16 => ConstInt :: Isize ( ConstIsize :: Is16 ( $lit) ) ,
60
+ ast:: IntTy :: I32 => ConstInt :: Isize ( ConstIsize :: Is32 ( $lit) ) ,
61
+ ast:: IntTy :: I64 => ConstInt :: Isize ( ConstIsize :: Is64 ( $lit) ) ,
62
+ _ => bug!( ) ,
63
+ } ,
64
+ UnsignedInt ( ast:: UintTy :: U8 ) => ConstInt :: U8 ( $lit) ,
65
+ UnsignedInt ( ast:: UintTy :: U16 ) => ConstInt :: U16 ( $lit) ,
66
+ UnsignedInt ( ast:: UintTy :: U32 ) => ConstInt :: U32 ( $lit) ,
67
+ UnsignedInt ( ast:: UintTy :: U64 ) => ConstInt :: U64 ( $lit) ,
68
+ UnsignedInt ( ast:: UintTy :: U128 ) => ConstInt :: U128 ( $lit) ,
69
+ UnsignedInt ( ast:: UintTy :: Us ) => match $tcx. sess. target. uint_type {
70
+ ast:: UintTy :: U16 => ConstInt :: Usize ( ConstUsize :: Us16 ( $lit) ) ,
71
+ ast:: UintTy :: U32 => ConstInt :: Usize ( ConstUsize :: Us32 ( $lit) ) ,
72
+ ast:: UintTy :: U64 => ConstInt :: Usize ( ConstUsize :: Us64 ( $lit) ) ,
73
+ _ => bug!( ) ,
74
+ } ,
75
+ }
76
+ }
77
+ }
78
+
50
79
impl IntTypeExt for attr:: IntType {
51
80
fn to_ty < ' a , ' gcx , ' tcx > ( & self , tcx : TyCtxt < ' a , ' gcx , ' tcx > ) -> Ty < ' tcx > {
52
81
match * self {
@@ -66,30 +95,7 @@ impl IntTypeExt for attr::IntType {
66
95
}
67
96
68
97
fn initial_discriminant < ' a , ' tcx > ( & self , tcx : TyCtxt < ' a , ' tcx , ' tcx > ) -> Disr {
69
- match * self {
70
- SignedInt ( ast:: IntTy :: I8 ) => ConstInt :: I8 ( 0 ) ,
71
- SignedInt ( ast:: IntTy :: I16 ) => ConstInt :: I16 ( 0 ) ,
72
- SignedInt ( ast:: IntTy :: I32 ) => ConstInt :: I32 ( 0 ) ,
73
- SignedInt ( ast:: IntTy :: I64 ) => ConstInt :: I64 ( 0 ) ,
74
- SignedInt ( ast:: IntTy :: I128 ) => ConstInt :: I128 ( 0 ) ,
75
- SignedInt ( ast:: IntTy :: Is ) => match tcx. sess . target . int_type {
76
- ast:: IntTy :: I16 => ConstInt :: Isize ( ConstIsize :: Is16 ( 0 ) ) ,
77
- ast:: IntTy :: I32 => ConstInt :: Isize ( ConstIsize :: Is32 ( 0 ) ) ,
78
- ast:: IntTy :: I64 => ConstInt :: Isize ( ConstIsize :: Is64 ( 0 ) ) ,
79
- _ => bug ! ( ) ,
80
- } ,
81
- UnsignedInt ( ast:: UintTy :: U8 ) => ConstInt :: U8 ( 0 ) ,
82
- UnsignedInt ( ast:: UintTy :: U16 ) => ConstInt :: U16 ( 0 ) ,
83
- UnsignedInt ( ast:: UintTy :: U32 ) => ConstInt :: U32 ( 0 ) ,
84
- UnsignedInt ( ast:: UintTy :: U64 ) => ConstInt :: U64 ( 0 ) ,
85
- UnsignedInt ( ast:: UintTy :: U128 ) => ConstInt :: U128 ( 0 ) ,
86
- UnsignedInt ( ast:: UintTy :: Us ) => match tcx. sess . target . uint_type {
87
- ast:: UintTy :: U16 => ConstInt :: Usize ( ConstUsize :: Us16 ( 0 ) ) ,
88
- ast:: UintTy :: U32 => ConstInt :: Usize ( ConstUsize :: Us32 ( 0 ) ) ,
89
- ast:: UintTy :: U64 => ConstInt :: Usize ( ConstUsize :: Us64 ( 0 ) ) ,
90
- _ => bug ! ( ) ,
91
- } ,
92
- }
98
+ typed_literal ! ( tcx, * self , 0 )
93
99
}
94
100
95
101
fn assert_ty_matches ( & self , val : Disr ) {
@@ -114,7 +120,7 @@ impl IntTypeExt for attr::IntType {
114
120
-> Option < Disr > {
115
121
if let Some ( val) = val {
116
122
self . assert_ty_matches ( val) ;
117
- ( val + ConstInt :: Infer ( 1 ) ) . ok ( )
123
+ ( val + typed_literal ! ( tcx , * self , 1 ) ) . ok ( )
118
124
} else {
119
125
Some ( self . initial_discriminant ( tcx) )
120
126
}
0 commit comments