@@ -390,7 +390,7 @@ pub enum ErrKind {
390390 IndexedNonVec ,
391391 IndexNegative ,
392392 IndexNotInt ,
393- IndexOutOfBounds ,
393+ IndexOutOfBounds { len : u64 , index : u64 } ,
394394 RepeatCountNotNatural ,
395395 RepeatCountNotInt ,
396396
@@ -441,7 +441,10 @@ impl ConstEvalErr {
441441 IndexedNonVec => "indexing is only supported for arrays" . into_cow ( ) ,
442442 IndexNegative => "indices must be non-negative integers" . into_cow ( ) ,
443443 IndexNotInt => "indices must be integers" . into_cow ( ) ,
444- IndexOutOfBounds => "array index out of bounds" . into_cow ( ) ,
444+ IndexOutOfBounds { len, index } => {
445+ format ! ( "index out of bounds: the len is {} but the index is {}" ,
446+ len, index) . into_cow ( )
447+ }
445448 RepeatCountNotNatural => "repeat count must be a natural number" . into_cow ( ) ,
446449 RepeatCountNotInt => "repeat count must be integers" . into_cow ( ) ,
447450
@@ -835,23 +838,29 @@ pub fn eval_const_expr_partial<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
835838 } ;
836839 assert_eq ! ( idx as usize as u64 , idx) ;
837840 match arr {
838- Array ( _, n) if idx >= n => signal ! ( e, IndexOutOfBounds ) ,
841+ Array ( _, n) if idx >= n => {
842+ signal ! ( e, IndexOutOfBounds { len: n, index: idx } )
843+ }
839844 Array ( v, n) => if let hir:: ExprVec ( ref v) = tcx. map . expect_expr ( v) . node {
840845 assert_eq ! ( n as usize as u64 , n) ;
841846 eval_const_expr_partial ( tcx, & v[ idx as usize ] , ty_hint, fn_args) ?
842847 } else {
843848 bug ! ( )
844849 } ,
845850
846- Repeat ( _, n) if idx >= n => signal ! ( e, IndexOutOfBounds ) ,
851+ Repeat ( _, n) if idx >= n => {
852+ signal ! ( e, IndexOutOfBounds { len: n, index: idx } )
853+ }
847854 Repeat ( elem, _) => eval_const_expr_partial (
848855 tcx,
849856 & tcx. map . expect_expr ( elem) ,
850857 ty_hint,
851858 fn_args,
852859 ) ?,
853860
854- ByteStr ( ref data) if idx >= data. len ( ) as u64 => signal ! ( e, IndexOutOfBounds ) ,
861+ ByteStr ( ref data) if idx >= data. len ( ) as u64 => {
862+ signal ! ( e, IndexOutOfBounds { len: data. len( ) as u64 , index: idx } )
863+ }
855864 ByteStr ( data) => {
856865 Integral ( U8 ( data[ idx as usize ] ) )
857866 } ,
0 commit comments