]>
Commit | Line | Data |
---|---|---|
74b04a01 XL |
1 | // Test that or-patterns are pass-through with respect to default binding modes. |
2 | ||
3 | // check-pass | |
4 | ||
5 | #![feature(or_patterns)] | |
6 | #![allow(irrefutable_let_patterns)] | |
7 | ||
8 | fn main() { | |
9 | // A regression test for a mistake we made at one point: | |
10 | match &1 { | |
11 | e @ &(1..=2) | e @ &(3..=4) => {} | |
12 | _ => {} | |
13 | } | |
14 | ||
15 | match &0 { | |
16 | 0 | &1 => {} | |
17 | _ => {} | |
18 | } | |
19 | ||
20 | type R<'a> = &'a Result<u8, u8>; | |
21 | ||
22 | let res: R<'_> = &Ok(0); | |
23 | ||
24 | match res { | |
25 | // Alternatives propagate expected type / binding mode independently. | |
26 | Ok(mut x) | &Err(mut x) => drop::<u8>(x), | |
27 | } | |
28 | match res { | |
29 | &(Ok(x) | Err(x)) => drop::<u8>(x), | |
30 | } | |
31 | match res { | |
32 | Ok(x) | Err(x) => drop::<&u8>(x), | |
33 | } | |
34 | if let Ok(mut x) | &Err(mut x) = res { | |
35 | drop::<u8>(x); | |
36 | } | |
37 | if let &(Ok(x) | Err(x)) = res { | |
38 | drop::<u8>(x); | |
39 | } | |
6a06907d | 40 | let (Ok(mut x) | &Err(mut x)) = res; |
74b04a01 XL |
41 | drop::<u8>(x); |
42 | let &(Ok(x) | Err(x)) = res; | |
43 | drop::<u8>(x); | |
6a06907d | 44 | let (Ok(x) | Err(x)) = res; |
74b04a01 XL |
45 | drop::<&u8>(x); |
46 | for Ok(mut x) | &Err(mut x) in std::iter::once(res) { | |
47 | drop::<u8>(x); | |
48 | } | |
49 | for &(Ok(x) | Err(x)) in std::iter::once(res) { | |
50 | drop::<u8>(x); | |
51 | } | |
52 | for Ok(x) | Err(x) in std::iter::once(res) { | |
53 | drop::<&u8>(x); | |
54 | } | |
55 | fn f1((Ok(mut x) | &Err(mut x)): R<'_>) { | |
56 | drop::<u8>(x); | |
57 | } | |
58 | fn f2(&(Ok(x) | Err(x)): R<'_>) { | |
59 | drop::<u8>(x); | |
60 | } | |
61 | fn f3((Ok(x) | Err(x)): R<'_>) { | |
62 | drop::<&u8>(x); | |
63 | } | |
64 | ||
65 | // Wrap inside another type (a product for a simplity with irrefutable contexts). | |
66 | #[derive(Copy, Clone)] | |
67 | struct Wrap<T>(T); | |
68 | let wres = Wrap(res); | |
69 | ||
70 | match wres { | |
71 | Wrap(Ok(mut x) | &Err(mut x)) => drop::<u8>(x), | |
72 | } | |
73 | match wres { | |
74 | Wrap(&(Ok(x) | Err(x))) => drop::<u8>(x), | |
75 | } | |
76 | match wres { | |
77 | Wrap(Ok(x) | Err(x)) => drop::<&u8>(x), | |
78 | } | |
79 | if let Wrap(Ok(mut x) | &Err(mut x)) = wres { | |
80 | drop::<u8>(x); | |
81 | } | |
82 | if let Wrap(&(Ok(x) | Err(x))) = wres { | |
83 | drop::<u8>(x); | |
84 | } | |
85 | if let Wrap(Ok(x) | Err(x)) = wres { | |
86 | drop::<&u8>(x); | |
87 | } | |
88 | let Wrap(Ok(mut x) | &Err(mut x)) = wres; | |
89 | drop::<u8>(x); | |
90 | let Wrap(&(Ok(x) | Err(x))) = wres; | |
91 | drop::<u8>(x); | |
92 | let Wrap(Ok(x) | Err(x)) = wres; | |
93 | drop::<&u8>(x); | |
94 | for Wrap(Ok(mut x) | &Err(mut x)) in std::iter::once(wres) { | |
95 | drop::<u8>(x); | |
96 | } | |
97 | for Wrap(&(Ok(x) | Err(x))) in std::iter::once(wres) { | |
98 | drop::<u8>(x); | |
99 | } | |
100 | for Wrap(Ok(x) | Err(x)) in std::iter::once(wres) { | |
101 | drop::<&u8>(x); | |
102 | } | |
103 | fn fw1(Wrap(Ok(mut x) | &Err(mut x)): Wrap<R<'_>>) { | |
104 | drop::<u8>(x); | |
105 | } | |
106 | fn fw2(Wrap(&(Ok(x) | Err(x))): Wrap<R<'_>>) { | |
107 | drop::<u8>(x); | |
108 | } | |
109 | fn fw3(Wrap(Ok(x) | Err(x)): Wrap<R<'_>>) { | |
110 | drop::<&u8>(x); | |
111 | } | |
112 | ||
113 | // Nest some more: | |
114 | ||
115 | enum Tri<P> { | |
116 | A(P), | |
117 | B(P), | |
118 | C(P), | |
119 | } | |
120 | ||
121 | let tri = &Tri::A(&Ok(0)); | |
6a06907d | 122 | let (Tri::A(Ok(mut x) | Err(mut x)) |
74b04a01 | 123 | | Tri::B(&Ok(mut x) | Err(mut x)) |
6a06907d | 124 | | &Tri::C(Ok(mut x) | Err(mut x))) = tri; |
74b04a01 XL |
125 | drop::<u8>(x); |
126 | ||
127 | match tri { | |
128 | Tri::A(Ok(mut x) | Err(mut x)) | |
129 | | Tri::B(&Ok(mut x) | Err(mut x)) | |
130 | | &Tri::C(Ok(mut x) | Err(mut x)) => drop::<u8>(x), | |
131 | } | |
132 | } |