]> git.lizzy.rs Git - rust.git/blob - src/test/ui/pattern/usefulness/non-exhaustive-defined-here.rs
Rollup merge of #96051 - newpavlov:duration_rounding, r=nagisa,joshtriplett
[rust.git] / src / test / ui / pattern / usefulness / non-exhaustive-defined-here.rs
1 // Test the "defined here" and "not covered" diagnostic hints.
2 // We also make sure that references are peeled off from the scrutinee type
3 // so that the diagnostics work better with default binding modes.
4
5 #[derive(Clone)]
6 enum E {
7     //~^ NOTE
8     //~| NOTE
9     //~| NOTE
10     //~| NOTE
11     //~| NOTE
12     //~| NOTE
13     A,
14     B,
15     //~^ NOTE `E` defined here
16     //~| NOTE `E` defined here
17     //~| NOTE `E` defined here
18     //~| NOTE `E` defined here
19     //~| NOTE `E` defined here
20     //~| NOTE `E` defined here
21     //~| NOTE  not covered
22     //~| NOTE  not covered
23     //~| NOTE  not covered
24     //~| NOTE  not covered
25     //~| NOTE  not covered
26     //~| NOTE  not covered
27     C
28     //~^ not covered
29     //~| not covered
30     //~| not covered
31     //~| not covered
32     //~| not covered
33     //~| not covered
34 }
35
36 fn by_val(e: E) {
37     let e1 = e.clone();
38     match e1 { //~ ERROR non-exhaustive patterns: `B` and `C` not covered
39         //~^ NOTE patterns `B` and `C` not covered
40         //~| NOTE the matched value is of type `E`
41         E::A => {}
42     }
43
44     let E::A = e; //~ ERROR refutable pattern in local binding: `B` and `C` not covered
45     //~^ NOTE patterns `B` and `C` not covered
46     //~| NOTE `let` bindings require an "irrefutable pattern", like a `struct` or an `enum` with
47     //~| NOTE for more information, visit https://doc.rust-lang.org/book/ch18-02-refutability.html
48     //~| NOTE the matched value is of type `E`
49 }
50
51 fn by_ref_once(e: &E) {
52     match e { //~ ERROR non-exhaustive patterns: `&B` and `&C` not covered
53     //~^ NOTE patterns `&B` and `&C` not covered
54     //~| NOTE the matched value is of type `&E`
55         E::A => {}
56     }
57
58     let E::A = e; //~ ERROR refutable pattern in local binding: `&B` and `&C` not covered
59     //~^ NOTE patterns `&B` and `&C` not covered
60     //~| NOTE `let` bindings require an "irrefutable pattern", like a `struct` or an `enum` with
61     //~| NOTE for more information, visit https://doc.rust-lang.org/book/ch18-02-refutability.html
62     //~| NOTE the matched value is of type `&E`
63 }
64
65 fn by_ref_thrice(e: & &mut &E) {
66     match e { //~ ERROR non-exhaustive patterns: `&&mut &B` and `&&mut &C` not covered
67     //~^ NOTE patterns `&&mut &B` and `&&mut &C` not covered
68     //~| NOTE the matched value is of type `&&mut &E`
69         E::A => {}
70     }
71
72     let E::A = e;
73     //~^ ERROR refutable pattern in local binding: `&&mut &B` and `&&mut &C` not covered
74     //~| NOTE patterns `&&mut &B` and `&&mut &C` not covered
75     //~| NOTE `let` bindings require an "irrefutable pattern", like a `struct` or an `enum` with
76     //~| NOTE for more information, visit https://doc.rust-lang.org/book/ch18-02-refutability.html
77     //~| NOTE the matched value is of type `&&mut &E`
78 }
79
80 enum Opt {
81     //~^ NOTE
82     //~| NOTE
83     Some(u8),
84     None,
85     //~^ NOTE `Opt` defined here
86     //~| NOTE `Opt` defined here
87     //~| NOTE not covered
88     //~| NOTE not covered
89 }
90
91 fn ref_pat(e: Opt) {
92     match e {//~ ERROR non-exhaustive patterns: `None` not covered
93         //~^ NOTE pattern `None` not covered
94         //~| NOTE the matched value is of type `Opt`
95         Opt::Some(ref _x) => {}
96     }
97
98     let Opt::Some(ref _x) = e; //~ ERROR refutable pattern in local binding: `None` not covered
99     //~^ NOTE the matched value is of type `Opt`
100     //~| NOTE pattern `None` not covered
101     //~| NOTE `let` bindings require an "irrefutable pattern", like a `struct` or an `enum` with
102     //~| NOTE for more information, visit https://doc.rust-lang.org/book/ch18-02-refutability.html
103 }
104
105 fn main() {}