Skip to content

Commit 30adf25

Browse files
committed
Add test for attempting to use array indexing for conditional const eval
1 parent 226e7ce commit 30adf25

File tree

2 files changed

+43
-0
lines changed

2 files changed

+43
-0
lines changed
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// Copyright 2018 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 X: u32 = 5;
12+
const Y: u32 = 6;
13+
const FOO: u32 = [X - Y, Y - X][(X < Y) as usize]; //~ E0080
14+
15+
fn main() {
16+
println!("{}", FOO); //~ E0080
17+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
error[E0080]: constant evaluation error
2+
--> $DIR/conditional_array_execution.rs:13:19
3+
|
4+
13 | const FOO: u32 = [X - Y, Y - X][(X < Y) as usize]; //~ E0080
5+
| ^^^^^ attempt to subtract with overflow
6+
|
7+
note: inside call to FOO
8+
--> $DIR/conditional_array_execution.rs:13:1
9+
|
10+
13 | const FOO: u32 = [X - Y, Y - X][(X < Y) as usize]; //~ E0080
11+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
12+
13+
error[E0080]: constant evaluation error
14+
--> $DIR/conditional_array_execution.rs:16:20
15+
|
16+
16 | println!("{}", FOO); //~ E0080
17+
| ^^^ attempt to subtract with overflow
18+
|
19+
note: inside call to main
20+
--> $DIR/conditional_array_execution.rs:16:20
21+
|
22+
16 | println!("{}", FOO); //~ E0080
23+
| ^^^
24+
25+
error: aborting due to 2 previous errors
26+

0 commit comments

Comments
 (0)