2019-09-03 02:32:50 +00:00
|
|
|
// Check that or-patterns with consistent bindings across arms are allowed.
|
|
|
|
|
|
|
|
// edition:2018
|
|
|
|
|
2019-12-27 17:53:00 +00:00
|
|
|
// check-pass
|
|
|
|
|
2019-09-03 02:32:50 +00:00
|
|
|
fn main() {
|
|
|
|
// One level:
|
2021-02-13 00:04:37 +00:00
|
|
|
let (Ok(a) | Err(a)) = Ok(0);
|
|
|
|
let (Ok(ref a) | Err(ref a)) = Ok(0);
|
|
|
|
let (Ok(ref mut a) | Err(ref mut a)) = Ok(0);
|
2019-09-03 02:32:50 +00:00
|
|
|
|
|
|
|
// Two levels:
|
2019-12-27 17:53:00 +00:00
|
|
|
enum Tri<S, T, U> {
|
|
|
|
V1(S),
|
|
|
|
V2(T),
|
|
|
|
V3(U),
|
|
|
|
}
|
2019-09-03 02:32:50 +00:00
|
|
|
use Tri::*;
|
|
|
|
|
2021-02-13 00:04:37 +00:00
|
|
|
let (Ok((V1(a) | V2(a) | V3(a), b)) | Err(Ok((a, b)) | Err((a, b)))): Result<_, Result<_, _>> =
|
2019-12-27 17:53:00 +00:00
|
|
|
Ok((V1(1), 1));
|
2019-09-03 02:32:50 +00:00
|
|
|
|
2021-02-13 00:04:37 +00:00
|
|
|
let (Ok((V1(a) | V2(a) | V3(a), ref b)) | Err(Ok((a, ref b)) | Err((a, ref b)))): Result<
|
2019-12-27 17:53:00 +00:00
|
|
|
_,
|
|
|
|
Result<_, _>,
|
|
|
|
> = Ok((V1(1), 1));
|
2019-09-03 02:32:50 +00:00
|
|
|
|
|
|
|
// Three levels:
|
|
|
|
let (
|
2019-12-27 17:53:00 +00:00
|
|
|
a,
|
|
|
|
Err((ref mut b, ref c, d))
|
|
|
|
| Ok((
|
|
|
|
Ok(V1((ref c, d)) | V2((d, ref c)) | V3((ref c, Ok((_, d)) | Err((d, _)))))
|
|
|
|
| Err((ref c, d)),
|
|
|
|
ref mut b,
|
|
|
|
)),
|
|
|
|
): (_, Result<_, _>) = (1, Ok((Ok(V3((1, Ok::<_, (i32, i32)>((1, 1))))), 1)));
|
2019-09-03 02:32:50 +00:00
|
|
|
}
|