]> git.lizzy.rs Git - rust.git/blob - src/test/ui/coercion/coerce-overloaded-autoderef-fail.rs
Rollup merge of #100112 - RalfJung:assert_send_and_sync, r=m-ou-se
[rust.git] / src / test / ui / coercion / coerce-overloaded-autoderef-fail.rs
1 fn borrow_mut<T>(x: &mut T) -> &mut T { x }
2 fn borrow<T>(x: &T) -> &T { x }
3
4 fn borrow_mut2<T>(_: &mut T, _: &mut T) {}
5 fn borrow2<T>(_: &mut T, _: &T) {}
6
7 fn double_mut_borrow<T>(x: &mut Box<T>) {
8     let y = borrow_mut(x);
9     let z = borrow_mut(x);
10     //~^ ERROR cannot borrow `*x` as mutable more than once at a time
11     drop((y, z));
12 }
13
14 fn double_imm_borrow(x: &mut Box<i32>) {
15     let y = borrow(x);
16     let z = borrow(x);
17     **x += 1;
18     //~^ ERROR cannot assign to `**x` because it is borrowed
19     drop((y, z));
20 }
21
22 fn double_mut_borrow2<T>(x: &mut Box<T>) {
23     borrow_mut2(x, x);
24     //~^ ERROR cannot borrow `*x` as mutable more than once at a time
25 }
26
27 fn double_borrow2<T>(x: &mut Box<T>) {
28     borrow2(x, x);
29     //~^ ERROR cannot borrow `*x` as mutable because it is also borrowed as immutable
30 }
31
32 pub fn main() {}