-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
Add feature gates for for
and ?
in consts
#87237
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
dbd1269
Add feature gates for `for` and `?` in consts
jonas-schievink 3c6678a
Add `const_for` test
jonas-schievink 4ee1840
Add tracking issues
jonas-schievink 550948c
Update tests
jonas-schievink c5a29f9
Update error code description
jonas-schievink 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
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
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,12 @@ | ||
error[E0658]: `for` is not allowed in a `const` | ||
--> $DIR/const-for-feature-gate.rs:4:5 | ||
| | ||
LL | for _ in 0..5 {} | ||
| ^^^^^^^^^^^^^^^^ | ||
| | ||
= note: see issue #87575 <https://github.com/rust-lang/rust/issues/87575> for more information | ||
= 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,10 @@ | ||
#![feature(const_for)] | ||
#![feature(const_mut_refs)] | ||
|
||
const _: () = { | ||
for _ in 0..5 {} | ||
//~^ error: calls in constants are limited to | ||
//~| error: calls in constants are limited to | ||
}; | ||
|
||
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,15 @@ | ||
error[E0015]: calls in constants are limited to constant functions, tuple structs and tuple variants | ||
--> $DIR/const-for.rs:5:14 | ||
| | ||
LL | for _ in 0..5 {} | ||
| ^^^^ | ||
|
||
error[E0015]: calls in constants are limited to constant functions, tuple structs and tuple variants | ||
--> $DIR/const-for.rs:5:14 | ||
| | ||
LL | for _ in 0..5 {} | ||
| ^^^^ | ||
|
||
error: aborting due to 2 previous errors | ||
|
||
For more information about this error, try `rustc --explain E0015`. |
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,12 @@ | ||
error[E0658]: `?` is not allowed in a `const fn` | ||
--> $DIR/const-try-feature-gate.rs:4:5 | ||
| | ||
LL | Some(())?; | ||
| ^^^^^^^^^ | ||
| | ||
= note: see issue #74935 <https://github.com/rust-lang/rust/issues/74935> for more information | ||
= 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(); | ||
}; |
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,19 +1,25 @@ | ||
error[E0744]: `for` is not allowed in a `const` | ||
error[E0658]: `for` is not allowed in a `const` | ||
--> $DIR/loop.rs:53:5 | ||
| | ||
LL | / for i in 0..4 { | ||
LL | | x += i; | ||
LL | | } | ||
| |_____^ | ||
| | ||
= note: see issue #87575 <https://github.com/rust-lang/rust/issues/87575> for more information | ||
= help: add `#![feature(const_for)]` to the crate attributes to enable | ||
|
||
error[E0744]: `for` is not allowed in a `const` | ||
error[E0658]: `for` is not allowed in a `const` | ||
--> $DIR/loop.rs:57:5 | ||
| | ||
LL | / for i in 0..4 { | ||
LL | | x += i; | ||
LL | | } | ||
| |_____^ | ||
| | ||
= note: see issue #87575 <https://github.com/rust-lang/rust/issues/87575> for more information | ||
= help: add `#![feature(const_for)]` 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,12 @@ | ||
error[E0744]: `?` is not allowed in a `const fn` | ||
error[E0658]: `?` is not allowed in a `const fn` | ||
--> $DIR/try.rs:6:5 | ||
| | ||
LL | x?; | ||
| ^^ | ||
| | ||
= note: see issue #74935 <https://github.com/rust-lang/rust/issues/74935> for more information | ||
= 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 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
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,9 +1,12 @@ | ||
error[E0744]: `?` is not allowed in a `const fn` | ||
error[E0658]: `?` is not allowed in a `const fn` | ||
--> $DIR/hir-const-check.rs:11:9 | ||
| | ||
LL | Some(())?; | ||
| ^^^^^^^^^ | ||
| | ||
= note: see issue #74935 <https://github.com/rust-lang/rust/issues/74935> for more information | ||
= 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 E0744`. | ||
For more information about this error, try `rustc --explain E0658`. |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess we should start printing the function's name in the diagnostic. Very uninformative this error XD