-
Notifications
You must be signed in to change notification settings - Fork 13.4k
Enable loop
and while
in constants behind a feature flag
#67216
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
Changes from all commits
8f3021b
57959b2
8f59902
ee233c0
99e132d
1122404
caa7c99
3325671
2add77d
a8e997c
a2a0774
b3aecd0
2b5ae1c
80581be
34ce0ba
598bed6
029725f
0f0bfc9
faa52d1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -390,8 +390,12 @@ fn check_terminator( | |
cleanup: _, | ||
} => check_operand(tcx, cond, span, def_id, body), | ||
|
||
| TerminatorKind::FalseUnwind { .. } | ||
if feature_allowed(tcx, def_id, sym::const_loop) | ||
=> Ok(()), | ||
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. This seems very fragile. What this code should be doing is a CFG cyclicity check. 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. There is one in 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. Do both run? That makes me happier, I guess, but then the 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.
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.
So, assuming const-check these days is well-structured enough that everyone is confident in its ability to do what it is supposed to do, I don't think you'll need to spend any political capital to get rid of it. Quite the contrary, at least I personally would be delighted to see it go. :) 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. I would prefer if we could wait with removing 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. There's no urgency, there are some preliminary things that can be done like eliminating the 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. You could just make the handling of As the name says, it's a "false" (or "phantom") unwind edge. It's for situations where analyses which care about unwinding / cleanup blocks need to be conservative and assume unwinding can happen "out of the blue". Everything else in const-checking ignores unwind edges (e.g. from calls) and associated cleanup blocks, because we completely bypass unwinding at compile-time. 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. See #62274 for precedent. 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. Also looks like |
||
|
||
TerminatorKind::FalseUnwind { .. } => { | ||
Err((span, "loops are not allowed in const fn".into())) | ||
}, | ||
} | ||
} | ||
} |
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"] | ||
|
||
|
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`. |
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`. |
Uh oh!
There was an error while loading. Please reload this page.