2013-05-26 04:48:04 -05:00
|
|
|
// Test that attempt to swap `&mut` pointer while pointee is borrowed
|
|
|
|
// yields an error.
|
|
|
|
//
|
2015-02-18 21:34:55 -06:00
|
|
|
// Example from src/librustc_borrowck/borrowck/README.md
|
2013-05-26 04:48:04 -05:00
|
|
|
|
2014-01-31 14:35:36 -06:00
|
|
|
use std::mem::swap;
|
2013-05-26 04:48:04 -05:00
|
|
|
|
2018-08-14 18:16:05 -05:00
|
|
|
|
|
|
|
|
2015-01-08 04:54:35 -06:00
|
|
|
fn foo<'a>(mut t0: &'a mut isize,
|
|
|
|
mut t1: &'a mut isize) {
|
|
|
|
let p: &isize = &*t0; // Freezes `*t0`
|
2013-05-26 04:48:04 -05:00
|
|
|
swap(&mut t0, &mut t1); //~ ERROR cannot borrow `t0`
|
|
|
|
*t1 = 22;
|
2018-08-14 18:16:05 -05:00
|
|
|
p.use_ref();
|
2013-05-26 04:48:04 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
fn main() {
|
2013-09-23 19:20:36 -05:00
|
|
|
}
|
2018-08-14 18:16:05 -05:00
|
|
|
|
|
|
|
trait Fake { fn use_mut(&mut self) { } fn use_ref(&self) { } }
|
|
|
|
impl<T> Fake for T { }
|