-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
Confusing error message when matching on &str
in const fn
#90237
Comments
I'm not familiar with how matching on const fn foo(input: &'static str) {
input == "a";
}
@rustbot modify labels: +A-const-eval +D-confusing |
Note also that a byte string literal is fine: const fn decode_bytes(b: &[u8]) -> Option<u8> {
match b {
b"0" => Some(0),
_ => None,
}
} ☝️ compiles on 1.64, but const fn decode_string(s: &str) -> Option<u8> {
match s {
"0" => Some(0),
_ => None,
}
} ...fails with:
|
I ran into this as well. It's definitely calling The const_str crate gets around this by converting to bytes for the comparison. Here's a working example: https://play.rust-lang.org/?version=nightly&mode=debug&edition=2021&gist=286b897bb518dec6617d3da197cd318b Note, this seems related to #103040 . |
…sg, r=b-naber Better error for non const `PartialEq` call generated by `match` Resolves rust-lang#90237
…sg, r=b-naber Better error for non const `PartialEq` call generated by `match` Resolves rust-lang#90237
…sg, r=b-naber Better error for non const `PartialEq` call generated by `match` Resolves rust-lang#90237
Given the following code: https://play.rust-lang.org/?version=nightly&mode=debug&edition=2021&gist=bc51fb79544b1be00dd8a4285103ff07
The current output is:
I feel like it's pretty self-explanatory, but this is obviously a very confusing error. A match arm for a string literal is not a "call" by any usual meaning of the word. In fact, I have no idea what actual objection
rustc
has to this code, if any.As far as I can tell, this error is the same on all current versions of the compiler (stable, beta, nightly) per the submission of this issue.
The text was updated successfully, but these errors were encountered: