Skip to content

Commit 2c251fa

Browse files
committed
Rollup merge of rust-lang#23294 - dotdash:coob, r=alexcrichton
Fixes rust-lang#23291
2 parents 425297a + de67c3a commit 2c251fa

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

src/librustc_trans/trans/consts.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -505,8 +505,10 @@ fn const_expr_unadjusted<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>,
505505
// pass. Reporting here is a bit late.
506506
cx.sess().span_err(e.span,
507507
"const index-expr is out of bounds");
508+
C_undef(type_of::type_of(cx, bt).element_type())
509+
} else {
510+
const_get_elt(cx, arr, &[iv as c_uint])
508511
}
509-
const_get_elt(cx, arr, &[iv as c_uint])
510512
}
511513
ast::ExprCast(ref base, _) => {
512514
let llty = type_of::type_of(cx, ety);
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// Copyright 2015 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
const FOO: [u32; 3] = [1, 2, 3];
12+
const BAR: u32 = FOO[5]; //~ ERROR const index-expr is out of bounds
13+
14+
fn main() {
15+
let _ = BAR;
16+
}

0 commit comments

Comments
 (0)