rust/tests/ui/or-patterns/consistent-bindings.rs

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

40 lines
985 B
Rust
Raw Normal View History

// Check that or-patterns with consistent bindings across arms are allowed.
// edition:2018
2019-12-27 17:53:00 +00:00
// check-pass
fn main() {
// One level:
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);
// Two levels:
2019-12-27 17:53:00 +00:00
enum Tri<S, T, U> {
V1(S),
V2(T),
V3(U),
}
use Tri::*;
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));
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));
// 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)));
}