-
Notifications
You must be signed in to change notification settings - Fork 13.1k
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Constants in patterns can contain equality-less types #34784
Comments
This is a pointer pattern, it shouldn't compile AFAIK. cc @arielb1 |
This should be a constant pattern. Why it is destructuring through the pointer? |
As far as I remember, the constant-evaluated initializer expression gets used as a pattern, i.e. the code below and in the report are equivalent for MIR builder: const C: *const str = "abcd";
fn main() {
match C {
"abcd" => {}
_ => {}
}
} Which is caught by the proper-typeck and is why the mir-typeck is complaining. |
This is more general than raw pointers const C: fn() = main;
fn foo(x: fn()) {
match x {
C => {}
_ => {}
}
}
fn main() {} However, other cases result in a const-eval error: const C: *const u8 = &0; //~ ERROR error: constant evaluation error: unimplemented constant expression: address operator [E0471]
fn foo(x: *const u8) {
match x {
C => {}
_ => {}
}
}
fn main() {} I think this is the right solution. |
cc @oli-obk |
One more test, for thin pointers: const C: *const [u8; 4] = b"abcd";
fn main() {
match C {
C => {}
_ => {}
}
} Gives |
The issue is that the mir-building process calls rust/src/librustc_mir/hair/cx/pattern.rs Line 68 in f93aaf8
consts::const_expr (rust/src/librustc_trans/_match.rs Line 288 in f93aaf8
It should work if instead of calling |
The problem is that the code compiles. We should not be doing |
Code:
Diagnostics:
Reproduces on stable/beta/nightly.
The text was updated successfully, but these errors were encountered: