-
Notifications
You must be signed in to change notification settings - Fork 13k
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
allow const function calls in consts that are used in patterns #30141
Conversation
Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @arielb1 (or someone else) soon. If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. Due to the way GitHub handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes. Please see the contribution instructions for more information. |
Why are you using |
it's already done for everything that is not a pattern directly. Like if you have an integral operation in a constant, it'll just defer it to |
example: this won't work, since the enum is not directly in a const: enum Cake {
BlackForest,
Marmor,
}
use Cake::*;
const BOO: (Cake, Cake) = (Marmor, BlackForest);
const FOO: Cake = BOO.1;
fn main() {
match BlackForest {
FOO => println!("hi"),
_ => println!("bye"),
}
} |
The only expressions that are handled without the const evaluator are |
At least add a test that these kinds of abuse result in an error rather than an ICE. |
added a test and noticed that the error is reported twice for the const fn. So now I'm bailing out in case the error was repeated previously. do you mean "abuse" in the "you shouldn't do this" way or in the "complex situation" way? |
According to @nikomatsakis we are going to change constant patterns to eliminate that possibility - but still we should not ICE. |
I removed the commit that bailed early, |
☔ The latest upstream changes (presumably #30084) made this pull request unmergeable. Please resolve the merge conflicts. |
rebased |
I'm not sure what possibility is going to be eliminated, but the following already works, because it hits something (a tuple index op) that will be const evaluated: #![feature(const_fn)]
const BOO: (i32, i64) = (5, bla());
const fn bla() -> i64 { 6 }
const FOO: i64 = BOO.1;
fn main() {
match 6 {
FOO => println!("hi"),
_ => println!("bye"),
}
} all this PR does is to make sure the following also works #![feature(const_fn)]
const fn bla() -> i64 { 6 }
const FOO: i64 = bla();
fn main() {
match 6 {
FOO => println!("hi"),
_ => println!("bye"),
}
} |
@bors r+ |
📌 Commit c71dcca has been approved by |
r? @arielb1