diff options
| author | bors <bors@rust-lang.org> | 2020-10-17 14:44:51 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2020-10-17 14:44:51 +0000 |
| commit | 6af9846fcc8797bf97e9fb387385208c2219f3d0 (patch) | |
| tree | 527522b82ce55cd2bcc37b14096e6c1de63660bc /src/test/ui | |
| parent | dda2b5e3e260c14b868c494008af1c8981eaa5a8 (diff) | |
| parent | 03321b8cca91cd5d1f9c82a447add69329e52cea (diff) | |
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`
Diffstat (limited to 'src/test/ui')
| -rw-r--r-- | src/test/ui/feature-gate-inline_const.rs | 6 | ||||
| -rw-r--r-- | src/test/ui/feature-gate-inline_const.stderr | 12 | ||||
| -rw-r--r-- | src/test/ui/inline-const/const-expr-array-init.rs | 10 | ||||
| -rw-r--r-- | src/test/ui/inline-const/const-expr-basic.rs | 14 | ||||
| -rw-r--r-- | src/test/ui/inline-const/const-expr-reference.rs | 15 | ||||
| -rw-r--r-- | src/test/ui/inline-const/const-match-pat.rs | 21 | ||||
| -rw-r--r-- | src/test/ui/parser/issue-66357-unexpected-unreachable.rs | 2 | ||||
| -rw-r--r-- | src/test/ui/parser/issue-66357-unexpected-unreachable.stderr | 2 |
8 files changed, 80 insertions, 2 deletions
diff --git a/src/test/ui/feature-gate-inline_const.rs b/src/test/ui/feature-gate-inline_const.rs new file mode 100644 index 00000000000..43ff90d234c --- /dev/null +++ b/src/test/ui/feature-gate-inline_const.rs @@ -0,0 +1,6 @@ +fn main() { + let _ = const { + //~^ ERROR inline-const is experimental [E0658] + true + }; +} diff --git a/src/test/ui/feature-gate-inline_const.stderr b/src/test/ui/feature-gate-inline_const.stderr new file mode 100644 index 00000000000..be2f567155c --- /dev/null +++ b/src/test/ui/feature-gate-inline_const.stderr @@ -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`. diff --git a/src/test/ui/inline-const/const-expr-array-init.rs b/src/test/ui/inline-const/const-expr-array-init.rs new file mode 100644 index 00000000000..8bb5dab1fa0 --- /dev/null +++ b/src/test/ui/inline-const/const-expr-array-init.rs @@ -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]; +} diff --git a/src/test/ui/inline-const/const-expr-basic.rs b/src/test/ui/inline-const/const-expr-basic.rs new file mode 100644 index 00000000000..9254c96a1e7 --- /dev/null +++ b/src/test/ui/inline-const/const-expr-basic.rs @@ -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()); +} diff --git a/src/test/ui/inline-const/const-expr-reference.rs b/src/test/ui/inline-const/const-expr-reference.rs new file mode 100644 index 00000000000..747f14e4bd0 --- /dev/null +++ b/src/test/ui/inline-const/const-expr-reference.rs @@ -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); +} diff --git a/src/test/ui/inline-const/const-match-pat.rs b/src/test/ui/inline-const/const-match-pat.rs new file mode 100644 index 00000000000..c0dc90d971a --- /dev/null +++ b/src/test/ui/inline-const/const-match-pat.rs @@ -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 +} diff --git a/src/test/ui/parser/issue-66357-unexpected-unreachable.rs b/src/test/ui/parser/issue-66357-unexpected-unreachable.rs index 5ec143fae23..7b95bc775ba 100644 --- a/src/test/ui/parser/issue-66357-unexpected-unreachable.rs +++ b/src/test/ui/parser/issue-66357-unexpected-unreachable.rs @@ -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 `*` diff --git a/src/test/ui/parser/issue-66357-unexpected-unreachable.stderr b/src/test/ui/parser/issue-66357-unexpected-unreachable.stderr index c3810999d23..5549f73920d 100644 --- a/src/test/ui/parser/issue-66357-unexpected-unreachable.stderr +++ b/src/test/ui/parser/issue-66357-unexpected-unreachable.stderr @@ -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() { |[](* } |
