Skip to content

Commit 54596c9

Browse files
committed
Add inline const tests
1 parent 85b5ce2 commit 54596c9

7 files changed

+55
-25
lines changed
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
fn main() {
22
let _ = const {
3-
//~^ ERROR expected expression, found keyword `const`
3+
//~^ ERROR inline-const is experimental [E0658]
44
true
55
};
66
}
Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
1-
error: expected expression, found keyword `const`
1+
error[E0658]: inline-const is experimental
22
--> $DIR/feature-gate-inline_const.rs:2:13
33
|
44
LL | let _ = const {
5-
| ^^^^^ expected expression
5+
| ^^^^^
6+
|
7+
= note: see issue #76001 <https://github.com/rust-lang/rust/issues/76001> for more information
8+
= help: add `#![feature(inline_const)]` to the crate attributes to enable
69

710
error: aborting due to previous error
811

12+
For more information about this error, try `rustc --explain E0658`.
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// build-pass
2+
3+
#![feature(inline_const)]
4+
5+
use std::cell::Cell;
6+
7+
fn main() {
8+
let _x = [const { Cell::new(0) }; 20];
9+
}
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
// check-pass
2-
// compile-flags: -Z parse-only
1+
// run-pass
32

43
#![feature(inline_const)]
54
fn foo() -> i32 {
@@ -8,3 +7,7 @@ fn foo() -> i32 {
87
x / 3
98
}
109
}
10+
11+
fn main() {
12+
assert_eq!(5, foo());
13+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// run-pass
2+
3+
#![feature(inline_const)]
4+
5+
const fn bar() -> i32 {
6+
const {
7+
2 + 3
8+
}
9+
}
10+
11+
fn main() {
12+
let x: &'static i32 = &const{bar()};
13+
assert_eq!(&5, x);
14+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// run-pass
2+
3+
#![feature(inline_const)]
4+
const MMIO_BIT1: u8 = 4;
5+
const MMIO_BIT2: u8 = 5;
6+
7+
fn main() {
8+
let s = match read_mmio() {
9+
0 => "FOO",
10+
const { 1 << MMIO_BIT1 } => "BAR",
11+
const { 1 << MMIO_BIT2 } => "BAZ",
12+
_ => unreachable!(),
13+
};
14+
15+
assert_eq!("BAZ", s);
16+
}
17+
18+
fn read_mmio() -> i32 {
19+
1 << 5
20+
}

src/test/ui/parser/inline_const/const_match_pat_parses.rs

Lines changed: 0 additions & 20 deletions
This file was deleted.

0 commit comments

Comments
 (0)