File tree Expand file tree Collapse file tree 3 files changed +34
-2
lines changed Expand file tree Collapse file tree 3 files changed +34
-2
lines changed Original file line number Diff line number Diff line change @@ -23,7 +23,7 @@ refs/tags/0.9: 36870b185fc5f5486636d4515f0e22677493f225
23
23
refs/tags/0.10: ac33f2b15782272ae348dbd7b14b8257b2148b5a
24
24
refs/tags/0.11.0: e1247cb1d0d681be034adb4b558b5a0c0d5720f9
25
25
refs/tags/0.12.0: f0c419429ef30723ceaf6b42f9b5a2aeb5d2e2d1
26
- refs/heads/beta: 6ee60037f9cee27d9de70195d7e63d4946465a2f
26
+ refs/heads/beta: 54b15c7160e165621f0a7ae6a71db30dded254df
27
27
refs/tags/1.0.0-alpha: e42bd6d93a1d3433c486200587f8f9e12590a4d7
28
28
refs/heads/tmp: e06d2ad9fcd5027bcaac5b08fc9aa39a49d0ecd3
29
29
refs/tags/1.0.0-alpha.2: 4c705f6bc559886632d3871b04f58aab093bfa2f
Original file line number Diff line number Diff line change @@ -743,7 +743,21 @@ pub fn eval_const_expr_partial<'tcx>(tcx: &TyCtxt<'tcx>,
743
743
}
744
744
} ;
745
745
746
- let val = try!( eval_const_expr_partial ( tcx, & base, base_hint, fn_args) ) ;
746
+ let val = match eval_const_expr_partial ( tcx, & base, base_hint, fn_args) {
747
+ Ok ( val) => val,
748
+ Err ( ConstEvalErr { kind : InferredWrongType ( val) , .. } ) => {
749
+ // Something like `5i8 as usize` doesn't need a type hint for the base
750
+ // instead take the type hint from the inner value
751
+ let hint = match val. int_type ( ) {
752
+ Some ( IntType :: UnsignedInt ( ty) ) => ty_hint. checked_or ( tcx. mk_mach_uint ( ty) ) ,
753
+ Some ( IntType :: SignedInt ( ty) ) => ty_hint. checked_or ( tcx. mk_mach_int ( ty) ) ,
754
+ // we had a type hint, so we can't have an unknown type
755
+ None => unreachable ! ( ) ,
756
+ } ;
757
+ try!( eval_const_expr_partial ( tcx, & base, hint, fn_args) )
758
+ } ,
759
+ Err ( e) => return Err ( e) ,
760
+ } ;
747
761
match cast_const ( tcx, val, ety) {
748
762
Ok ( val) => val,
749
763
Err ( kind) => return Err ( ConstEvalErr { span : e. span , kind : kind } ) ,
Original file line number Diff line number Diff line change 9
9
// except according to those terms.
10
10
11
11
use std:: cmp:: Ordering ;
12
+ use syntax:: attr:: IntType ;
13
+ use syntax:: ast:: { IntTy , UintTy } ;
12
14
13
15
use super :: is:: * ;
14
16
use super :: us:: * ;
@@ -258,6 +260,22 @@ impl ConstInt {
258
260
ConstInt :: Infer ( _) | ConstInt :: InferSigned ( _) => panic ! ( "no type info for const int" ) ,
259
261
}
260
262
}
263
+
264
+ pub fn int_type ( self ) -> Option < IntType > {
265
+ match self {
266
+ ConstInt :: I8 ( _) => Some ( IntType :: SignedInt ( IntTy :: I8 ) ) ,
267
+ ConstInt :: I16 ( _) => Some ( IntType :: SignedInt ( IntTy :: I16 ) ) ,
268
+ ConstInt :: I32 ( _) => Some ( IntType :: SignedInt ( IntTy :: I32 ) ) ,
269
+ ConstInt :: I64 ( _) => Some ( IntType :: SignedInt ( IntTy :: I64 ) ) ,
270
+ ConstInt :: Isize ( _) => Some ( IntType :: SignedInt ( IntTy :: Is ) ) ,
271
+ ConstInt :: U8 ( _) => Some ( IntType :: UnsignedInt ( UintTy :: U8 ) ) ,
272
+ ConstInt :: U16 ( _) => Some ( IntType :: UnsignedInt ( UintTy :: U16 ) ) ,
273
+ ConstInt :: U32 ( _) => Some ( IntType :: UnsignedInt ( UintTy :: U32 ) ) ,
274
+ ConstInt :: U64 ( _) => Some ( IntType :: UnsignedInt ( UintTy :: U64 ) ) ,
275
+ ConstInt :: Usize ( _) => Some ( IntType :: UnsignedInt ( UintTy :: Us ) ) ,
276
+ _ => None ,
277
+ }
278
+ }
261
279
}
262
280
263
281
impl :: std:: cmp:: PartialOrd for ConstInt {
You can’t perform that action at this time.
0 commit comments