Open
Description
The following code compiles:
trait Foo {
const C: i32;
}
impl<T> Foo for T {
const C: i32 = 0;
}
fn bar<T>() {
match 0 {
<T as Foo>::C => (),
_ => (),
}
}
but adding a trait bound of Foo
to bar
:
trait Foo {
const C: i32;
}
impl<T> Foo for T {
const C: i32 = 0;
}
fn bar<T: Foo>() {
match 0 {
<T as Foo>::C => (),
_ => (),
}
}
causes compilation to fail with:
error[E0158]: associated consts cannot be referenced in patterns
--> src/main.rs:14:9
|
14 | <T as Foo>::C => (),
| ^^^^^^^^^^^^^
error: aborting due to previous error
For more information about this error, try `rustc --explain E0158`.
error: could not compile `playground`.
To learn more, run the command again with --verbose.
I would expect these two cases to behave identically instead of one working and the other failing. (it seems like both cases should be disallowed, but I don't have a good grasp of the current state of relevant features)
This is reproducible in the rust playground on the stable, beta, and nightly channels
Metadata
Metadata
Assignees
Labels
Area: Associated items (types, constants & functions)Area: Constant evaluation, covers all const contexts (static, const fn, ...)Relating to patterns and pattern matchingArea: Trait systemCategory: This is a bug.Relevant to the compiler team, which will review and decide on the PR/issue.Relevant to the types team, which will review and decide on the PR/issue.