]> git.lizzy.rs Git - rust.git/blob - src/test/ui/borrowck/borrowck-report-with-custom-diagnostic.rs
Unit test from #57866.
[rust.git] / src / test / ui / borrowck / borrowck-report-with-custom-diagnostic.rs
1 #![feature(rustc_attrs)]
2 #![allow(dead_code)]
3 fn main() { #![rustc_error] // rust-lang/rust#49855
4     // Original borrow ends at end of function
5     let mut x = 1;
6     let y = &mut x;
7     //~^ mutable borrow occurs here
8     let z = &x; //~ ERROR cannot borrow
9     //~^ immutable borrow occurs here
10     z.use_ref();
11     y.use_mut();
12 }
13
14 fn foo() {
15     match true {
16         true => {
17             // Original borrow ends at end of match arm
18             let mut x = 1;
19             let y = &x;
20             //~^ immutable borrow occurs here
21             let z = &mut x; //~ ERROR cannot borrow
22             //~^ mutable borrow occurs here
23             z.use_mut();
24             y.use_ref();
25         }
26         false => ()
27     }
28 }
29
30 fn bar() {
31     // Original borrow ends at end of closure
32     || {
33         let mut x = 1;
34         let y = &mut x;
35         //~^ first mutable borrow occurs here
36         let z = &mut x; //~ ERROR cannot borrow
37         //~^ second mutable borrow occurs here
38         z.use_mut();
39         y.use_mut();
40     };
41 }
42
43 trait Fake { fn use_mut(&mut self) { } fn use_ref(&self) { }  }
44 impl<T> Fake for T { }