]> git.lizzy.rs Git - rust.git/blob - tests/ui/borrowck/borrowck-swap-mut-base-ptr.rs
Rollup merge of #106709 - khuey:disable_split_dwarf_inlining_by_default, r=davidtwco
[rust.git] / tests / ui / borrowck / borrowck-swap-mut-base-ptr.rs
1 // Test that attempt to swap `&mut` pointer while pointee is borrowed
2 // yields an error.
3 //
4 // Example from compiler/rustc_borrowck/borrowck/README.md
5
6 use std::mem::swap;
7
8
9
10 fn foo<'a>(mut t0: &'a mut isize,
11            mut t1: &'a mut isize) {
12     let p: &isize = &*t0;     // Freezes `*t0`
13     swap(&mut t0, &mut t1); //~ ERROR cannot borrow `t0`
14     *t1 = 22;
15     p.use_ref();
16 }
17
18 fn main() {
19 }
20
21 trait Fake { fn use_mut(&mut self) { } fn use_ref(&self) { }  }
22 impl<T> Fake for T { }