diff options
| author | Jonas Schievink <jonasschievink@gmail.com> | 2021-07-18 03:34:50 +0200 |
|---|---|---|
| committer | Jonas Schievink <jonasschievink@gmail.com> | 2021-07-29 23:21:54 +0200 |
| commit | dbd126901ac7d6ee886e0a234e630b1fbfec9afd (patch) | |
| tree | e5b1eae2ecbc3a582207071f2c59f63f8152a4ec /src/test | |
| parent | a985d8e6c7f0519fa1e147854430a381ac4eadf8 (diff) | |
| download | rust-dbd126901ac7d6ee886e0a234e630b1fbfec9afd.tar.gz rust-dbd126901ac7d6ee886e0a234e630b1fbfec9afd.zip | |
Add feature gates for `for` and `?` in consts
Diffstat (limited to 'src/test')
| -rw-r--r-- | src/test/ui/consts/const-for-feature-gate.rs | 8 | ||||
| -rw-r--r-- | src/test/ui/consts/const-for-feature-gate.stderr | 11 | ||||
| -rw-r--r-- | src/test/ui/consts/const-try-feature-gate.rs | 9 | ||||
| -rw-r--r-- | src/test/ui/consts/const-try-feature-gate.stderr | 11 | ||||
| -rw-r--r-- | src/test/ui/consts/const-try.rs | 39 |
5 files changed, 78 insertions, 0 deletions
diff --git a/src/test/ui/consts/const-for-feature-gate.rs b/src/test/ui/consts/const-for-feature-gate.rs new file mode 100644 index 00000000000..bec7b808905 --- /dev/null +++ b/src/test/ui/consts/const-for-feature-gate.rs @@ -0,0 +1,8 @@ +// gate-test-const_for + +const _: () = { + for _ in 0..5 {} + //~^ error: `for` is not allowed in a `const` +}; + +fn main() {} diff --git a/src/test/ui/consts/const-for-feature-gate.stderr b/src/test/ui/consts/const-for-feature-gate.stderr new file mode 100644 index 00000000000..c1b46ef7376 --- /dev/null +++ b/src/test/ui/consts/const-for-feature-gate.stderr @@ -0,0 +1,11 @@ +error[E0658]: `for` is not allowed in a `const` + --> $DIR/const-for-feature-gate.rs:4:5 + | +LL | for _ in 0..5 {} + | ^^^^^^^^^^^^^^^^ + | + = help: add `#![feature(const_for)]` 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/consts/const-try-feature-gate.rs b/src/test/ui/consts/const-try-feature-gate.rs new file mode 100644 index 00000000000..0839c23a0b9 --- /dev/null +++ b/src/test/ui/consts/const-try-feature-gate.rs @@ -0,0 +1,9 @@ +// gate-test-const_try + +const fn t() -> Option<()> { + Some(())?; + //~^ error: `?` is not allowed in a `const fn` + None +} + +fn main() {} diff --git a/src/test/ui/consts/const-try-feature-gate.stderr b/src/test/ui/consts/const-try-feature-gate.stderr new file mode 100644 index 00000000000..9e3aa09ab00 --- /dev/null +++ b/src/test/ui/consts/const-try-feature-gate.stderr @@ -0,0 +1,11 @@ +error[E0658]: `?` is not allowed in a `const fn` + --> $DIR/const-try-feature-gate.rs:4:5 + | +LL | Some(())?; + | ^^^^^^^^^ + | + = help: add `#![feature(const_try)]` 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/consts/const-try.rs b/src/test/ui/consts/const-try.rs new file mode 100644 index 00000000000..e199fd9ff8a --- /dev/null +++ b/src/test/ui/consts/const-try.rs @@ -0,0 +1,39 @@ +// check-pass + +// Demonstrates what's needed to make use of `?` in const contexts. + +#![crate_type = "lib"] +#![feature(try_trait_v2)] +#![feature(const_trait_impl)] +#![feature(const_try)] + +use std::ops::{ControlFlow, FromResidual, Try}; + +struct TryMe; +struct Error; + +impl const FromResidual<Error> for TryMe { + fn from_residual(residual: Error) -> Self { + TryMe + } +} + +impl const Try for TryMe { + type Output = (); + type Residual = Error; + fn from_output(output: Self::Output) -> Self { + TryMe + } + fn branch(self) -> ControlFlow<Self::Residual, Self::Output> { + ControlFlow::Break(Error) + } +} + +const fn t() -> TryMe { + TryMe?; + TryMe +} + +const _: () = { + t(); +}; |
