Skip to content

Mark 'match' as constant expression, if appropriate #42906

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

Closed
BenWiederhake opened this issue Jun 25, 2017 · 1 comment
Closed

Mark 'match' as constant expression, if appropriate #42906

BenWiederhake opened this issue Jun 25, 2017 · 1 comment
Labels
A-const-eval Area: Constant evaluation, covers all const contexts (static, const fn, ...) C-enhancement Category: An issue proposing an enhancement or a PR with one.

Comments

@BenWiederhake
Copy link
Contributor

Small-ish reproducing example (Play):

const N: u32 = 4;
const SPECIAL_RULE: &'static str = match N {
    3 => "Note: Must remote two cards before play.",
    6 => "Note: Must remote four cards before play.",
    _ => "No further notes.",
};

fn main() {
    println!("{}", SPECIAL_RULE);
}

Expected / desired behavior of the compiler:
Compiles without warning or error.
More generally: match expressions are allowed in definitions of constants, if the matching expression, all clauses, and all value expressions are constant. (Or something like that.)

Actual behavior of the compiler:
Compilation error [E0019]: constant contains unimplemented expression type.
More generally: match does not seem to be permitted at all.

Occurrence in bugtracker:
I have found no other instance in Google, and GitHub only lists #11411, which is the same error with a different syntax element.

Btw, if is not permitted either, so const MAGIC: u32 = if N == 4 { 42 } else { 1337 }; fails, too.

@Mark-Simulacrum Mark-Simulacrum added the C-enhancement Category: An issue proposing an enhancement or a PR with one. label Jul 28, 2017
@BenWiederhake
Copy link
Contributor Author

Closing on behalf of rust-lang/rfcs#322

@RalfJung RalfJung added the A-const-eval Area: Constant evaluation, covers all const contexts (static, const fn, ...) label Dec 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-const-eval Area: Constant evaluation, covers all const contexts (static, const fn, ...) C-enhancement Category: An issue proposing an enhancement or a PR with one.
Projects
None yet
Development

No branches or pull requests

3 participants