Skip to content

Commit 457c3aa

Browse files
Add additional const tests
1 parent 717c64e commit 457c3aa

File tree

4 files changed

+46
-0
lines changed

4 files changed

+46
-0
lines changed

src/test/ui/consts/const-if.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
const _X: i32 = if true { 5 } else { 6 };
2+
//~^ ERROR constant contains unimplemented expression type
3+
//~| ERROR constant contains unimplemented expression type
4+
5+
fn main() {}

src/test/ui/consts/const-if.stderr

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
error[E0019]: constant contains unimplemented expression type
2+
--> $DIR/const-if.rs:1:20
3+
|
4+
LL | const _X: i32 = if true { 5 } else { 6 };
5+
| ^^^^
6+
7+
error[E0019]: constant contains unimplemented expression type
8+
--> $DIR/const-if.rs:1:17
9+
|
10+
LL | const _X: i32 = if true { 5 } else { 6 };
11+
| ^^^^^^^^^^^^^^^^^^^^^^^^
12+
13+
error: aborting due to 2 previous errors
14+
15+
For more information about this error, try `rustc --explain E0019`.

src/test/ui/consts/const-multi-ref.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
const _X: i32 = {
2+
let mut a = 5;
3+
let p = &mut a; //~ ERROR references in constants may only refer to immutable values
4+
5+
let reborrow = {p}; //~ ERROR references in constants may only refer to immutable values
6+
let pp = &reborrow;
7+
let ppp = &pp;
8+
***ppp
9+
};
10+
11+
fn main() {}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
error[E0017]: references in constants may only refer to immutable values
2+
--> $DIR/const-multi-ref.rs:3:13
3+
|
4+
LL | let p = &mut a;
5+
| ^^^^^^ constants require immutable values
6+
7+
error[E0017]: references in constants may only refer to immutable values
8+
--> $DIR/const-multi-ref.rs:5:21
9+
|
10+
LL | let reborrow = {p};
11+
| ^ constants require immutable values
12+
13+
error: aborting due to 2 previous errors
14+
15+
For more information about this error, try `rustc --explain E0017`.

0 commit comments

Comments
 (0)