-
Notifications
You must be signed in to change notification settings - Fork 13.4k
Enable if
and match
in constants behind a feature flag
#66507
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
54d51bc
Allow multiple cfgs per comment in "revisions:" tests
ecstatic-morse 701f6e5
Fix broken incremental test
ecstatic-morse ae22938
Change some tests to use the shorter comment style
ecstatic-morse c537f22
Give name to full regex capture
ecstatic-morse 365d123
Add feature gate for const `if` and `match`
ecstatic-morse e969fb2
Don't transform short-circuiting logic if `const_if_match` enabled
ecstatic-morse a98d20a
Allow `Downcast` projections if `const_if_match` enabled
ecstatic-morse 929ff68
Hold a `TyCtxt` in the HIR const-checker
ecstatic-morse f4b9dc7
Make `name` work for `MatchSource`
ecstatic-morse ccb6e98
Suggest `const_if_match` on nightly
ecstatic-morse 26d93f3
Add entry for `const_if_match` in unstable book
ecstatic-morse 5c377f3
Reorganize, bless and add tests for const control flow
ecstatic-morse 25122d0
Const-check the discriminant of a `SwitchInt`
ecstatic-morse b09bb15
Allow `Downcast` projections in `qualify_min_const_fn`
ecstatic-morse File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
14 changes: 14 additions & 0 deletions
14
src/doc/unstable-book/src/language-features/const-if-match.md
This file contains hidden or 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,14 @@ | ||
# `const_if_match` | ||
|
||
The tracking issue for this feature is: [#49146] | ||
|
||
[#49146]: https://github.com/rust-lang/rust/issues/49146 | ||
|
||
------------------------ | ||
|
||
Allows for the use of conditionals (`if` and `match`) in a const context. | ||
Const contexts include `static`, `static mut`, `const`, `const fn`, const | ||
generics, and array initializers. Enabling this feature flag will also make | ||
`&&` and `||` function normally in a const-context by removing the hack that | ||
replaces them with their non-short-circuiting equivalents, `&` and `|`, in a | ||
`const` or `static`. |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 |
---|---|---|
|
@@ -529,6 +529,9 @@ declare_features! ( | |
/// Allows using the `#[register_attr]` attribute. | ||
(active, register_tool, "1.41.0", Some(66079), None), | ||
|
||
/// Allows the use of `if` and `match` in constants. | ||
(active, const_if_match, "1.41.0", Some(49146), None), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Btw: a useful trick for the future, if you want to avoid rebasing due to this, is to move this before |
||
|
||
// ------------------------------------------------------------------------- | ||
// feature-group-end: actual feature gates | ||
// ------------------------------------------------------------------------- | ||
|
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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,11 +1,13 @@ | ||
error[E0744]: `match` is not allowed in a `static` | ||
error[E0658]: `match` is not allowed in a `static` | ||
--> $DIR/issue-64453.rs:4:31 | ||
| | ||
LL | static settings_dir: String = format!(""); | ||
| ^^^^^^^^^^^ | ||
| | ||
= note: for more information, see https://github.com/rust-lang/rust/issues/49146 | ||
= help: add `#![feature(const_if_match)]` to the crate attributes to enable | ||
= note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info) | ||
|
||
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`. |
This file contains hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.