1 // This file tests the exhaustiveness algorithm on opaque constants. Most of the examples give
2 // unnecessary warnings because const_to_pat.rs converts a constant pattern to a wildcard when the
3 // constant is not allowed as a pattern. This is an edge case so we may not care to fix it.
4 // See also https://github.com/rust-lang/rust/issues/78057
6 #![deny(unreachable_patterns)]
11 const FOO: Foo = Foo(42);
12 const FOO_REF: &Foo = &Foo(42);
13 const FOO_REF_REF: &&Foo = &&Foo(42);
26 const BAZ: Baz = Baz::Baz1;
28 type Quux = fn(usize, usize) -> usize;
29 fn quux(a: usize, b: usize) -> usize { a + b }
30 const QUUX: Quux = quux;
35 //~^ ERROR must be annotated with `#[derive(PartialEq, Eq)]`
36 _ => {} // should not be emitting unreachable warning
37 //~^ ERROR unreachable pattern
42 //~^ ERROR must be annotated with `#[derive(PartialEq, Eq)]`
43 Foo(_) => {} // should not be emitting unreachable warning
44 //~^ ERROR unreachable pattern
47 // This used to cause an ICE (https://github.com/rust-lang/rust/issues/78071)
50 //~^ WARNING must be annotated with `#[derive(PartialEq, Eq)]`
51 //~| WARNING this was previously accepted by the compiler but is being phased out
57 BAR => {} // should not be emitting unreachable warning
58 //~^ ERROR must be annotated with `#[derive(PartialEq, Eq)]`
59 //~| ERROR unreachable pattern
61 //~^ ERROR unreachable pattern
66 //~^ ERROR must be annotated with `#[derive(PartialEq, Eq)]`
67 Bar => {} // should not be emitting unreachable warning
68 //~^ ERROR unreachable pattern
70 //~^ ERROR unreachable pattern
75 //~^ ERROR must be annotated with `#[derive(PartialEq, Eq)]`
76 BAR => {} // should not be emitting unreachable warning
77 //~^ ERROR must be annotated with `#[derive(PartialEq, Eq)]`
78 //~| ERROR unreachable pattern
79 _ => {} // should not be emitting unreachable warning
80 //~^ ERROR unreachable pattern
85 //~^ ERROR must be annotated with `#[derive(PartialEq, Eq)]`
86 Baz::Baz1 => {} // should not be emitting unreachable warning
87 //~^ ERROR unreachable pattern
89 //~^ ERROR unreachable pattern
95 //~^ ERROR must be annotated with `#[derive(PartialEq, Eq)]`
97 //~^ ERROR unreachable pattern
102 //~^ ERROR must be annotated with `#[derive(PartialEq, Eq)]`
103 Baz::Baz2 => {} // should not be emitting unreachable warning
104 //~^ ERROR unreachable pattern
105 _ => {} // should not be emitting unreachable warning
106 //~^ ERROR unreachable pattern