Skip to content

Commit 3a8f989

Browse files
committed
Always evaluate the expression in [expr; n]
In case that there is a destination for the array, like in "let x = [expr; n]", we currently don't evaluate the given expression if n is zero. That's inconsistent with all other cases, including "[expr; 0]" without a destination. Fixes #23354
1 parent 766a4e1 commit 3a8f989

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

src/librustc_trans/trans/tvec.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,7 @@ pub fn write_content<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
293293
}
294294
SaveIn(lldest) => {
295295
match ty::eval_repeat_count(bcx.tcx(), &**count_expr) {
296-
0 => bcx,
296+
0 => expr::trans_into(bcx, &**element, Ignore),
297297
1 => expr::trans_into(bcx, &**element, SaveIn(lldest)),
298298
count => {
299299
let elem = unpack_datum!(bcx, expr::trans(bcx, &**element));

src/test/run-fail/issue-23354.rs

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+
// error-pattern:panic evaluated
12+
13+
#[allow(unused_variables)]
14+
fn main() {
15+
let x = [panic!("panic evaluated"); 0];
16+
}

0 commit comments

Comments
 (0)