Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.
Sign upConstants in patterns can contain equality-less types #34784
Comments
eddyb
added
the
A-mir
label
Jul 12, 2016
This comment has been minimized.
This comment has been minimized.
|
This is a pointer pattern, it shouldn't compile AFAIK. cc @arielb1 |
This comment has been minimized.
This comment has been minimized.
|
This should be a constant pattern. Why it is destructuring through the pointer? |
arielb1
added
the
I-ICE
label
Jul 13, 2016
This comment has been minimized.
This comment has been minimized.
|
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. |
arielb1
added
I-nominated
T-lang
T-compiler
and removed
A-mir
labels
Jul 17, 2016
arielb1
changed the title
warning: broken MIR: expected: &str, found: *const str
Constants in patterns can contain equality-less types
Jul 17, 2016
This comment has been minimized.
This comment has been minimized.
|
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. |
arielb1
removed
I-nominated
T-lang
labels
Jul 17, 2016
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
arielb1
referenced this issue
Jul 17, 2016
Closed
ICE: librustc_const_eval/eval.rs: impossible case reached #34782
This comment has been minimized.
This comment has been minimized.
|
cc @oli-obk |
This comment has been minimized.
This comment has been minimized.
|
One more test, for thin pointers: const C: *const [u8; 4] = b"abcd";
fn main() {
match C {
C => {}
_ => {}
}
}Gives |
This comment has been minimized.
This comment has been minimized.
|
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 |
This comment has been minimized.
This comment has been minimized.
|
The problem is that the code compiles. We should not be doing |
petrochenkov commentedJul 12, 2016
•
edited by apasel422
Code:
Diagnostics:
Reproduces on stable/beta/nightly.