@@ -308,7 +308,7 @@ pub enum ErrKind {
308
308
NotOnArray ,
309
309
NotOnRepeat ,
310
310
NotOnRef ,
311
-
311
+
312
312
DerefInt ,
313
313
DerefUInt ,
314
314
DerefBool ,
@@ -344,7 +344,7 @@ pub enum ErrKind {
344
344
IndexOutOfBounds ,
345
345
RepeatCountNotNatural ,
346
346
RepeatCountNotInt ,
347
- MutableRef ,
347
+ MutableRef ,
348
348
349
349
MiscBinaryOp ,
350
350
MiscCatchAll ,
@@ -377,7 +377,7 @@ impl ConstEvalErr {
377
377
NotOnArray => "not on array" . into_cow ( ) ,
378
378
NotOnRepeat => "not on repeat" . into_cow ( ) ,
379
379
NotOnRef => "not on ref" . into_cow ( ) ,
380
-
380
+
381
381
DerefInt => "deref on int" . into_cow ( ) ,
382
382
DerefUInt => "deref on unsigned int" . into_cow ( ) ,
383
383
DerefBool => "deref on float" . into_cow ( ) ,
@@ -413,7 +413,7 @@ impl ConstEvalErr {
413
413
IndexOutOfBounds => "array index out of bounds" . into_cow ( ) ,
414
414
RepeatCountNotNatural => "repeat count must be a natural number" . into_cow ( ) ,
415
415
RepeatCountNotInt => "repeat count must be integers" . into_cow ( ) ,
416
- MutableRef => "cannot get a mutable reference to a constant" . into_cow ( ) ,
416
+ MutableRef => "cannot get a mutable reference to a constant" . into_cow ( ) ,
417
417
418
418
MiscBinaryOp => "bad operands for binary" . into_cow ( ) ,
419
419
MiscCatchAll => "unsupported constant expr" . into_cow ( ) ,
@@ -887,13 +887,17 @@ pub fn eval_const_expr_partial<'tcx>(tcx: &ty::ctxt<'tcx>,
887
887
ast:: ExprPath ( ..) => {
888
888
let opt_def = tcx. def_map . borrow ( ) . get ( & e. id ) . map ( |d| d. full_def ( ) ) ;
889
889
let ( const_expr, const_ty) = match opt_def {
890
- Some ( def:: DefConst ( def_id) ) => {
890
+ Some ( def:: DefConst ( def_id) )
891
+ | Some ( def:: DefStatic ( def_id, false ) ) => {
891
892
if ast_util:: is_local ( def_id) {
892
893
match tcx. map . find ( def_id. node ) {
893
894
Some ( ast_map:: NodeItem ( it) ) => match it. node {
894
895
ast:: ItemConst ( ref ty, ref expr) => {
895
896
( Some ( & * * expr) , Some ( & * * ty) )
896
897
}
898
+ ast:: ItemStatic ( ref ty, ast:: MutImmutable , ref expr) => {
899
+ ( Some ( & * * expr) , Some ( & * * ty) )
900
+ }
897
901
_ => ( None , None )
898
902
} ,
899
903
_ => ( None , None )
@@ -974,12 +978,21 @@ pub fn eval_const_expr_partial<'tcx>(tcx: &ty::ctxt<'tcx>,
974
978
} else {
975
979
unreachable ! ( )
976
980
} ,
981
+
977
982
const_val:: Repeat ( _, n) if idx >= n => signal ! ( e, IndexOutOfBounds ) ,
978
983
const_val:: Repeat ( elem, _) => try!( eval_const_expr_partial (
979
984
tcx,
980
985
& * tcx. map . expect_expr ( elem) ,
981
986
None ,
982
- ) ) ,
987
+ ) ) ,
988
+
989
+ const_val:: const_binary( ref data) if idx as usize >= data. len ( )
990
+ => signal ! ( e, IndexOutOfBounds ) ,
991
+ const_val:: const_binary( data) => const_val:: const_uint ( data[ idx as usize ] as u64 ) ,
992
+
993
+ const_val:: const_str( ref s) if idx as usize >= s. len ( )
994
+ => signal ! ( e, IndexOutOfBounds ) ,
995
+ const_val:: const_str( _) => unimplemented ! ( ) , // there's no const_char type
983
996
_ => signal ! ( e, IndexedNonVec ) ,
984
997
}
985
998
}
0 commit comments