forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rollup merge of rust-lang#67216 - ecstatic-morse:const-loop, r=oli-obk
Enable `loop` and `while` in constants behind a feature flag This PR is an initial implementation of rust-lang#52000. It adds a `const_loop` feature gate, which allows `while` and `loop` expressions through both HIR and MIR const-checkers if enabled. `for` expressions remain forbidden by the HIR const-checker, since they desugar to a call to `IntoIterator::into_iter`, which will be rejected anyways. `while` loops also require [`#![feature(const_if_match)]`](rust-lang#66507), since they have a conditional built into them. The diagnostics from the HIR const checker will suggest this to the user. r? @oli-obk cc @rust-lang/wg-const-eval
- Loading branch information
Showing
26 changed files
with
559 additions
and
127 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
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 |
---|---|---|
|
@@ -8,6 +8,7 @@ | |
|
||
#![feature(in_band_lifetimes)] | ||
#![feature(nll)] | ||
#![feature(slice_patterns)] | ||
|
||
#![recursion_limit="256"] | ||
|
||
|
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
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 |
---|---|---|
@@ -1,15 +1,21 @@ | ||
error[E0744]: `loop` is not allowed in a `const` | ||
error[E0658]: `loop` is not allowed in a `const` | ||
--> $DIR/issue-62272.rs:7:17 | ||
| | ||
LL | const FOO: () = loop { break; }; | ||
| ^^^^^^^^^^^^^^^ | ||
| | ||
= note: for more information, see https://github.com/rust-lang/rust/issues/52000 | ||
= help: add `#![feature(const_loop)]` to the crate attributes to enable | ||
|
||
error[E0744]: `loop` is not allowed in a `const` | ||
error[E0658]: `loop` is not allowed in a `const` | ||
--> $DIR/issue-62272.rs:10:20 | ||
| | ||
LL | [FOO; { let x; loop { x = 5; break; } x }]; | ||
| ^^^^^^^^^^^^^^^^^^^^^^ | ||
| | ||
= note: for more information, see https://github.com/rust-lang/rust/issues/52000 | ||
= help: add `#![feature(const_loop)]` to the crate attributes to enable | ||
|
||
error: aborting due to 2 previous errors | ||
|
||
For more information about this error, try `rustc --explain E0744`. | ||
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 |
---|---|---|
@@ -1,9 +1,13 @@ | ||
error[E0744]: `while` is not allowed in a `const` | ||
error[E0658]: `while` is not allowed in a `const` | ||
--> $DIR/const-labeled-break.rs:10:19 | ||
| | ||
LL | const CRASH: () = 'a: while break 'a {}; | ||
| ^^^^^^^^^^^^^^^^^^^^^ | ||
| | ||
= note: for more information, see https://github.com/rust-lang/rust/issues/52000 | ||
= help: add `#![feature(const_loop)]` to the crate attributes to enable | ||
= help: add `#![feature(const_if_match)]` to the crate attributes to enable | ||
|
||
error: aborting due to previous error | ||
|
||
For more information about this error, try `rustc --explain E0744`. | ||
For more information about this error, try `rustc --explain E0658`. |
Oops, something went wrong.