1 An associated `const`, `const` parameter or `static` has been referenced
4 Erroneous code example:
16 fn test<A: Bar>(arg: Foo) {
18 A::X => println!("A::X"), // error: E0158: associated consts cannot be
19 // referenced in patterns
20 Foo::Two => println!("Two")
25 Associated `const`s cannot be referenced in patterns because it is impossible
26 for the compiler to prove exhaustiveness (that some pattern will always match).
27 Take the above example, because Rust does type checking in the *generic*
28 method, not the *monomorphized* specific instance. So because `Bar` could have
29 theoretically infinite implementations, there's no way to always be sure that
30 `A::X` is `Foo::One`. So this code must be rejected. Even if code can be
31 proven exhaustive by a programmer, the compiler cannot currently prove this.
33 The same holds true of `const` parameters and `static`s.
35 If you want to match against an associated `const`, `const` parameter or
36 `static` consider using a guard instead:
43 static FOO: char = 'j';
45 fn test<A: Trait, const Y: char>(arg: char) {
47 c if c == A::X => println!("A::X"),
48 c if c == Y => println!("Y"),
49 c if c == FOO => println!("FOO"),