Skip to content

Commit 3ec38c8

Browse files
committed
Rollup merge of rust-lang#28874 - GuillaumeGomez:error_code, r=Manishearth
r? @Manishearth
2 parents e5f272e + a94f684 commit 3ec38c8

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

src/librustc_trans/diagnostics.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,21 @@
1212

1313
register_long_diagnostics! {
1414

15+
E0515: r##"
16+
A constant index expression was out of bounds. Erroneous code example:
17+
18+
```
19+
let x = &[0, 1, 2][7]; // error: const index-expr is out of bounds
20+
```
21+
22+
Please specify a valid index (not inferior to 0 or superior to array length).
23+
Example:
24+
25+
```
26+
let x = &[0, 1, 2][2]; // ok!
27+
```
28+
"##,
29+
1530
}
1631

1732
register_diagnostics! {

src/librustc_trans/trans/consts.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -628,8 +628,8 @@ fn const_expr_unadjusted<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>,
628628
if iv >= len {
629629
// FIXME #3170: report this earlier on in the const-eval
630630
// pass. Reporting here is a bit late.
631-
cx.sess().span_err(e.span,
632-
"const index-expr is out of bounds");
631+
span_err!(cx.sess(), e.span, E0515,
632+
"const index-expr is out of bounds");
633633
C_undef(val_ty(arr).element_type())
634634
} else {
635635
const_get_elt(cx, arr, &[iv as c_uint])

0 commit comments

Comments
 (0)