]> git.lizzy.rs Git - rust.git/blob - src/test/ui/borrowck/issue-51348-multi-ref-mut-in-guard.rs
Rollup merge of #52769 - sinkuu:stray_test, r=alexcrichton
[rust.git] / src / test / ui / borrowck / issue-51348-multi-ref-mut-in-guard.rs
1 // Copyright 2018 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
4 //
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
10
11 // We used to ICE if you had a single match arm with multiple
12 // candidate patterns with `ref mut` identifiers used in the arm's
13 // guard.
14 //
15 // Also, this test expands on the original bug's example by actually
16 // trying to double check that we are matching against the right part
17 // of the input data based on which candidate pattern actually fired.
18
19 // run-pass
20
21 #![feature(nll)]
22
23 fn foo(x: &mut Result<(u32, u32), (u32, u32)>) -> u32 {
24     match *x {
25         Ok((ref mut v, _)) | Err((_, ref mut v)) if *v > 0 => { *v }
26         _ => { 0 }
27     }
28 }
29
30 fn main() {
31     assert_eq!(foo(&mut Ok((3, 4))), 3);
32     assert_eq!(foo(&mut Err((3, 4))), 4);
33 }