]> git.proxmox.com Git - rustc.git/blame - src/test/ui/pattern/usefulness/non-exhaustive-defined-here.rs
Update unsuspicious file list
[rustc.git] / src / test / ui / pattern / usefulness / non-exhaustive-defined-here.rs
CommitLineData
e1599b0c
XL
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)]
6enum E {
5e7ed085
FG
7 //~^ NOTE
8 //~| NOTE
9 //~| NOTE
10 //~| NOTE
11 //~| NOTE
12 //~| NOTE
e1599b0c
XL
13 A,
14 B,
5e7ed085
FG
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
e1599b0c
XL
27 C
28 //~^ not covered
29 //~| not covered
30 //~| not covered
31 //~| not covered
32 //~| not covered
33 //~| not covered
34}
35
36fn by_val(e: E) {
37 let e1 = e.clone();
f2b60f7d
FG
38 match e1 { //~ ERROR non-exhaustive patterns: `E::B` and `E::C` not covered
39 //~^ NOTE patterns `E::B` and `E::C` not covered
5e7ed085 40 //~| NOTE the matched value is of type `E`
e1599b0c
XL
41 E::A => {}
42 }
43
f2b60f7d
FG
44 let E::A = e; //~ ERROR refutable pattern in local binding: `E::B` and `E::C` not covered
45 //~^ NOTE patterns `E::B` and `E::C` not covered
5e7ed085
FG
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`
e1599b0c
XL
49}
50
51fn by_ref_once(e: &E) {
f2b60f7d
FG
52 match e { //~ ERROR non-exhaustive patterns: `&E::B` and `&E::C` not covered
53 //~^ NOTE patterns `&E::B` and `&E::C` not covered
5e7ed085 54 //~| NOTE the matched value is of type `&E`
e1599b0c
XL
55 E::A => {}
56 }
57
f2b60f7d
FG
58 let E::A = e; //~ ERROR refutable pattern in local binding: `&E::B` and `&E::C` not covered
59 //~^ NOTE patterns `&E::B` and `&E::C` not covered
5e7ed085
FG
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`
e1599b0c
XL
63}
64
65fn by_ref_thrice(e: & &mut &E) {
f2b60f7d
FG
66 match e { //~ ERROR non-exhaustive patterns: `&&mut &E::B` and `&&mut &E::C` not covered
67 //~^ NOTE patterns `&&mut &E::B` and `&&mut &E::C` not covered
5e7ed085 68 //~| NOTE the matched value is of type `&&mut &E`
e1599b0c
XL
69 E::A => {}
70 }
71
72 let E::A = e;
f2b60f7d
FG
73 //~^ ERROR refutable pattern in local binding: `&&mut &E::B` and `&&mut &E::C` not covered
74 //~| NOTE patterns `&&mut &E::B` and `&&mut &E::C` not covered
5e7ed085
FG
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`
e1599b0c
XL
78}
79
80enum Opt {
5e7ed085
FG
81 //~^ NOTE
82 //~| NOTE
e1599b0c
XL
83 Some(u8),
84 None,
5e7ed085
FG
85 //~^ NOTE `Opt` defined here
86 //~| NOTE `Opt` defined here
87 //~| NOTE not covered
88 //~| NOTE not covered
e1599b0c
XL
89}
90
91fn ref_pat(e: Opt) {
f2b60f7d
FG
92 match e {//~ ERROR non-exhaustive patterns: `Opt::None` not covered
93 //~^ NOTE pattern `Opt::None` not covered
5e7ed085 94 //~| NOTE the matched value is of type `Opt`
e1599b0c
XL
95 Opt::Some(ref _x) => {}
96 }
97
f2b60f7d 98 let Opt::Some(ref _x) = e; //~ ERROR refutable pattern in local binding: `Opt::None` not covered
5e7ed085 99 //~^ NOTE the matched value is of type `Opt`
f2b60f7d 100 //~| NOTE pattern `Opt::None` not covered
5e7ed085
FG
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
e1599b0c
XL
103}
104
105fn main() {}