Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add feature gates for
for
and ?
in consts
- Loading branch information
1 parent
a985d8e
commit dbd1269
Showing
8 changed files
with
91 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
// gate-test-const_for | ||
|
||
const _: () = { | ||
for _ in 0..5 {} | ||
//~^ error: `for` is not allowed in a `const` | ||
}; | ||
|
||
fn main() {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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`. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
// gate-test-const_try | ||
|
||
const fn t() -> Option<()> { | ||
Some(())?; | ||
//~^ error: `?` is not allowed in a `const fn` | ||
None | ||
} | ||
|
||
fn main() {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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`. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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(); | ||
}; |