Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement const expressions and patterns (RFC 2920) #77124

Merged
merged 11 commits into from
Oct 17, 2020
Prev Previous commit
Next Next commit
Add inline const tests
  • Loading branch information
spastorino committed Oct 16, 2020
commit 54596c9b560472b682eaf2487672e135809b7583
2 changes: 1 addition & 1 deletion src/test/ui/feature-gate-inline_const.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
fn main() {
let _ = const {
//~^ ERROR expected expression, found keyword `const`
//~^ ERROR inline-const is experimental [E0658]
true
};
}
8 changes: 6 additions & 2 deletions src/test/ui/feature-gate-inline_const.stderr
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
error: expected expression, found keyword `const`
error[E0658]: inline-const is experimental
--> $DIR/feature-gate-inline_const.rs:2:13
|
LL | let _ = const {
| ^^^^^ expected expression
| ^^^^^
|
= note: see issue #76001 <https://github.com/rust-lang/rust/issues/76001> for more information
= help: add `#![feature(inline_const)]` to the crate attributes to enable

error: aborting due to previous error

For more information about this error, try `rustc --explain E0658`.
9 changes: 9 additions & 0 deletions src/test/ui/inline-const/const-expr-array-init.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// build-pass

#![feature(inline_const)]

use std::cell::Cell;

fn main() {
let _x = [const { Cell::new(0) }; 20];
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
// check-pass
// compile-flags: -Z parse-only
// run-pass

#![feature(inline_const)]
fn foo() -> i32 {
Expand All @@ -8,3 +7,7 @@ fn foo() -> i32 {
x / 3
}
}

fn main() {
assert_eq!(5, foo());
}
14 changes: 14 additions & 0 deletions src/test/ui/inline-const/const-expr-reference.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// run-pass

#![feature(inline_const)]

const fn bar() -> i32 {
const {
2 + 3
}
}

fn main() {
let x: &'static i32 = &const{bar()};
assert_eq!(&5, x);
}
20 changes: 20 additions & 0 deletions src/test/ui/inline-const/const-match-pat.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// run-pass

#![feature(inline_const)]
const MMIO_BIT1: u8 = 4;
const MMIO_BIT2: u8 = 5;

fn main() {
let s = match read_mmio() {
0 => "FOO",
const { 1 << MMIO_BIT1 } => "BAR",
const { 1 << MMIO_BIT2 } => "BAZ",
_ => unreachable!(),
};

assert_eq!("BAZ", s);
}

fn read_mmio() -> i32 {
1 << 5
}
20 changes: 0 additions & 20 deletions src/test/ui/parser/inline_const/const_match_pat_parses.rs

This file was deleted.