]> git.lizzy.rs Git - rust.git/blob - src/test/ui/coercion/coerce-overloaded-autoderef.rs
Auto merge of #54720 - davidtwco:issue-51191, r=nikomatsakis
[rust.git] / src / test / ui / coercion / coerce-overloaded-autoderef.rs
1 // Copyright 2014 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 // revisions: ast mir
12 //[mir]compile-flags: -Z borrowck=mir
13
14 fn borrow_mut<T>(x: &mut T) -> &mut T { x }
15 fn borrow<T>(x: &T) -> &T { x }
16
17 fn borrow_mut2<T>(_: &mut T, _: &mut T) {}
18 fn borrow2<T>(_: &mut T, _: &T) {}
19
20 fn double_mut_borrow<T>(x: &mut Box<T>) {
21     let y = borrow_mut(x);
22     let z = borrow_mut(x);
23     //[ast]~^ ERROR cannot borrow `*x` as mutable more than once at a time
24     //[mir]~^^ ERROR cannot borrow `*x` as mutable more than once at a time
25     drop((y, z));
26 }
27
28 fn double_imm_borrow(x: &mut Box<i32>) {
29     let y = borrow(x);
30     let z = borrow(x);
31     **x += 1;
32     //[ast]~^ ERROR cannot assign to `**x` because it is borrowed
33     //[mir]~^^ ERROR cannot assign to `**x` because it is borrowed
34     drop((y, z));
35 }
36
37 fn double_mut_borrow2<T>(x: &mut Box<T>) {
38     borrow_mut2(x, x);
39     //[ast]~^ ERROR cannot borrow `*x` as mutable more than once at a time
40     //[mir]~^^ ERROR cannot borrow `*x` as mutable more than once at a time
41 }
42
43 fn double_borrow2<T>(x: &mut Box<T>) {
44     borrow2(x, x);
45     //[ast]~^ ERROR cannot borrow `*x` as immutable because it is also borrowed as mutable
46     //[mir]~^^ ERROR cannot borrow `*x` as immutable because it is also borrowed as mutable
47 }
48
49 pub fn main() {}