diff options
| author | Eduard Burtescu <edy.burt@gmail.com> | 2016-05-26 22:09:48 +0300 |
|---|---|---|
| committer | Eduard Burtescu <edy.burt@gmail.com> | 2016-06-05 14:41:04 +0300 |
| commit | 1447fbf183e2c6c7889257bb363de3228324fb6e (patch) | |
| tree | e095608c1ba935b6cd2af4c57dd4427d1b5f9ae3 /src/librustc_const_eval | |
| parent | afc598e07543cc0c927e976c7e3621e44843135c (diff) | |
| download | rust-1447fbf183e2c6c7889257bb363de3228324fb6e.tar.gz rust-1447fbf183e2c6c7889257bb363de3228324fb6e.zip | |
rustc_const_eval: track the length and index in IndexOutOfBounds.
Diffstat (limited to 'src/librustc_const_eval')
| -rw-r--r-- | src/librustc_const_eval/eval.rs | 19 |
1 files changed, 14 insertions, 5 deletions
diff --git a/src/librustc_const_eval/eval.rs b/src/librustc_const_eval/eval.rs index b7cdb05a5d7..785b734b799 100644 --- a/src/librustc_const_eval/eval.rs +++ b/src/librustc_const_eval/eval.rs @@ -390,7 +390,7 @@ pub enum ErrKind { IndexedNonVec, IndexNegative, IndexNotInt, - IndexOutOfBounds, + IndexOutOfBounds { len: u64, index: u64 }, RepeatCountNotNatural, RepeatCountNotInt, @@ -441,7 +441,10 @@ impl ConstEvalErr { IndexedNonVec => "indexing is only supported for arrays".into_cow(), IndexNegative => "indices must be non-negative integers".into_cow(), IndexNotInt => "indices must be integers".into_cow(), - IndexOutOfBounds => "array index out of bounds".into_cow(), + IndexOutOfBounds { len, index } => { + format!("index out of bounds: the len is {} but the index is {}", + len, index).into_cow() + } RepeatCountNotNatural => "repeat count must be a natural number".into_cow(), RepeatCountNotInt => "repeat count must be integers".into_cow(), @@ -835,7 +838,9 @@ pub fn eval_const_expr_partial<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, }; assert_eq!(idx as usize as u64, idx); match arr { - Array(_, n) if idx >= n => signal!(e, IndexOutOfBounds), + Array(_, n) if idx >= n => { + signal!(e, IndexOutOfBounds { len: n, index: idx }) + } Array(v, n) => if let hir::ExprVec(ref v) = tcx.map.expect_expr(v).node { assert_eq!(n as usize as u64, n); eval_const_expr_partial(tcx, &v[idx as usize], ty_hint, fn_args)? @@ -843,7 +848,9 @@ pub fn eval_const_expr_partial<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, bug!() }, - Repeat(_, n) if idx >= n => signal!(e, IndexOutOfBounds), + Repeat(_, n) if idx >= n => { + signal!(e, IndexOutOfBounds { len: n, index: idx }) + } Repeat(elem, _) => eval_const_expr_partial( tcx, &tcx.map.expect_expr(elem), @@ -851,7 +858,9 @@ pub fn eval_const_expr_partial<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, fn_args, )?, - ByteStr(ref data) if idx >= data.len() as u64 => signal!(e, IndexOutOfBounds), + ByteStr(ref data) if idx >= data.len() as u64 => { + signal!(e, IndexOutOfBounds { len: data.len() as u64, index: idx }) + } ByteStr(data) => { Integral(U8(data[idx as usize])) }, |
