Auto merge of #77124 - spastorino:const-exprs-rfc-2920, r=oli-obk
Implement const expressions and patterns (RFC 2920) cc `@ecstatic-morse` `@lcnr` `@oli-obk` `@petrochenkov`
This commit is contained in:
commit
6af9846fcc
48 changed files with 301 additions and 36 deletions
6
src/test/ui/feature-gate-inline_const.rs
Normal file
6
src/test/ui/feature-gate-inline_const.rs
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
fn main() {
|
||||
let _ = const {
|
||||
//~^ ERROR inline-const is experimental [E0658]
|
||||
true
|
||||
};
|
||||
}
|
||||
12
src/test/ui/feature-gate-inline_const.stderr
Normal file
12
src/test/ui/feature-gate-inline_const.stderr
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
error[E0658]: inline-const is experimental
|
||||
--> $DIR/feature-gate-inline_const.rs:2:13
|
||||
|
|
||||
LL | let _ = const {
|
||||
| ^^^^^
|
||||
|
|
||||
= 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`.
|
||||
10
src/test/ui/inline-const/const-expr-array-init.rs
Normal file
10
src/test/ui/inline-const/const-expr-array-init.rs
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
// build-pass
|
||||
|
||||
#![allow(incomplete_features)]
|
||||
#![feature(inline_const)]
|
||||
|
||||
use std::cell::Cell;
|
||||
|
||||
fn main() {
|
||||
let _x = [const { Cell::new(0) }; 20];
|
||||
}
|
||||
14
src/test/ui/inline-const/const-expr-basic.rs
Normal file
14
src/test/ui/inline-const/const-expr-basic.rs
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
// run-pass
|
||||
|
||||
#![allow(incomplete_features)]
|
||||
#![feature(inline_const)]
|
||||
fn foo() -> i32 {
|
||||
const {
|
||||
let x = 5 + 10;
|
||||
x / 3
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {
|
||||
assert_eq!(5, foo());
|
||||
}
|
||||
15
src/test/ui/inline-const/const-expr-reference.rs
Normal file
15
src/test/ui/inline-const/const-expr-reference.rs
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
// run-pass
|
||||
|
||||
#![allow(incomplete_features)]
|
||||
#![feature(inline_const)]
|
||||
|
||||
const fn bar() -> i32 {
|
||||
const {
|
||||
2 + 3
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let x: &'static i32 = &const{bar()};
|
||||
assert_eq!(&5, x);
|
||||
}
|
||||
21
src/test/ui/inline-const/const-match-pat.rs
Normal file
21
src/test/ui/inline-const/const-match-pat.rs
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
// run-pass
|
||||
|
||||
#![allow(incomplete_features)]
|
||||
#![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
|
||||
}
|
||||
|
|
@ -13,4 +13,4 @@
|
|||
|
||||
fn f() { |[](* }
|
||||
//~^ ERROR expected one of `,` or `:`, found `(`
|
||||
//~| ERROR expected one of `&`, `(`, `)`, `-`, `...`, `..=`, `..`, `[`, `_`, `box`, `mut`, `ref`, `|`, identifier, or path, found `*`
|
||||
//~| ERROR expected one of `&`, `(`, `)`, `-`, `...`, `..=`, `..`, `[`, `_`, `box`, `const`, `mut`, `ref`, `|`, identifier, or path, found `*`
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ error: expected one of `,` or `:`, found `(`
|
|||
LL | fn f() { |[](* }
|
||||
| ^ expected one of `,` or `:`
|
||||
|
||||
error: expected one of `&`, `(`, `)`, `-`, `...`, `..=`, `..`, `[`, `_`, `box`, `mut`, `ref`, `|`, identifier, or path, found `*`
|
||||
error: expected one of `&`, `(`, `)`, `-`, `...`, `..=`, `..`, `[`, `_`, `box`, `const`, `mut`, `ref`, `|`, identifier, or path, found `*`
|
||||
--> $DIR/issue-66357-unexpected-unreachable.rs:14:14
|
||||
|
|
||||
LL | fn f() { |[](* }
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue