1 // Test that or-patterns are pass-through with respect to default binding modes.
5 #![allow(irrefutable_let_patterns)]
8 // A regression test for a mistake we made at one point:
10 e @ &(1..=2) | e @ &(3..=4) => {}
19 type R<'a> = &'a Result<u8, u8>;
21 let res: R<'_> = &Ok(0);
24 // Alternatives propagate expected type / binding mode independently.
25 Ok(mut x) | &Err(mut x) => drop::<u8>(x),
28 &(Ok(x) | Err(x)) => drop::<u8>(x),
31 Ok(x) | Err(x) => drop::<&u8>(x),
33 if let Ok(mut x) | &Err(mut x) = res {
36 if let &(Ok(x) | Err(x)) = res {
39 let (Ok(mut x) | &Err(mut x)) = res;
41 let &(Ok(x) | Err(x)) = res;
43 let (Ok(x) | Err(x)) = res;
45 for Ok(mut x) | &Err(mut x) in std::iter::once(res) {
48 for &(Ok(x) | Err(x)) in std::iter::once(res) {
51 for Ok(x) | Err(x) in std::iter::once(res) {
54 fn f1((Ok(mut x) | &Err(mut x)): R<'_>) {
57 fn f2(&(Ok(x) | Err(x)): R<'_>) {
60 fn f3((Ok(x) | Err(x)): R<'_>) {
64 // Wrap inside another type (a product for a simplity with irrefutable contexts).
65 #[derive(Copy, Clone)]
70 Wrap(Ok(mut x) | &Err(mut x)) => drop::<u8>(x),
73 Wrap(&(Ok(x) | Err(x))) => drop::<u8>(x),
76 Wrap(Ok(x) | Err(x)) => drop::<&u8>(x),
78 if let Wrap(Ok(mut x) | &Err(mut x)) = wres {
81 if let Wrap(&(Ok(x) | Err(x))) = wres {
84 if let Wrap(Ok(x) | Err(x)) = wres {
87 let Wrap(Ok(mut x) | &Err(mut x)) = wres;
89 let Wrap(&(Ok(x) | Err(x))) = wres;
91 let Wrap(Ok(x) | Err(x)) = wres;
93 for Wrap(Ok(mut x) | &Err(mut x)) in std::iter::once(wres) {
96 for Wrap(&(Ok(x) | Err(x))) in std::iter::once(wres) {
99 for Wrap(Ok(x) | Err(x)) in std::iter::once(wres) {
102 fn fw1(Wrap(Ok(mut x) | &Err(mut x)): Wrap<R<'_>>) {
105 fn fw2(Wrap(&(Ok(x) | Err(x))): Wrap<R<'_>>) {
108 fn fw3(Wrap(Ok(x) | Err(x)): Wrap<R<'_>>) {
120 let tri = &Tri::A(&Ok(0));
121 let (Tri::A(Ok(mut x) | Err(mut x))
122 | Tri::B(&Ok(mut x) | Err(mut x))
123 | &Tri::C(Ok(mut x) | Err(mut x))) = tri;
127 Tri::A(Ok(mut x) | Err(mut x))
128 | Tri::B(&Ok(mut x) | Err(mut x))
129 | &Tri::C(Ok(mut x) | Err(mut x)) => drop::<u8>(x),