-
Notifications
You must be signed in to change notification settings - Fork 13.6k
Open
Labels
A-const-evalArea: Constant evaluation, covers all const contexts (static, const fn, ...)Area: Constant evaluation, covers all const contexts (static, const fn, ...)A-patternsRelating to patterns and pattern matchingRelating to patterns and pattern matchingA-strArea: str and StringArea: str and StringC-bugCategory: This is a bug.Category: This is a bug.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.
Description
Basically, this feels like an artifical restriction due to the fact that both str::as_bytes
and matching on byte strings is possible in constants:
const fn byte_string_workaround(x: &str) -> u8 {
match x.as_bytes() {
b"hello" | b"world" => 1,
b"goodbye" | b"nonworld" => 2,
_ => 3,
}
}
const fn string_failure(x: &str) -> u8 {
match x {
"hello" | "world" => 1,
"goodbye" | "nonworld" => 2,
_ => 3,
}
}
Note that byte_string_workaround
compiles fine on stable but string_failure
returns an error saying that strings can't be matched in constants.
hanna-kruppe, bvanjoi and estebank
Metadata
Metadata
Assignees
Labels
A-const-evalArea: Constant evaluation, covers all const contexts (static, const fn, ...)Area: Constant evaluation, covers all const contexts (static, const fn, ...)A-patternsRelating to patterns and pattern matchingRelating to patterns and pattern matchingA-strArea: str and StringArea: str and StringC-bugCategory: This is a bug.Category: This is a bug.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.