2014-12-22 09:04:23 -08:00
|
|
|
use std::ops::Deref;
|
|
|
|
|
2015-01-08 22:02:42 +11:00
|
|
|
struct MyPtr<'a>(&'a mut usize);
|
2015-01-01 14:53:20 -05:00
|
|
|
impl<'a> Deref for MyPtr<'a> {
|
2015-01-08 22:02:42 +11:00
|
|
|
type Target = usize;
|
2015-01-01 14:53:20 -05:00
|
|
|
|
2015-01-08 22:02:42 +11:00
|
|
|
fn deref<'b>(&'b self) -> &'b usize { self.0 }
|
2014-11-10 16:47:32 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
trait Tr {
|
2015-01-08 22:02:42 +11:00
|
|
|
fn poke(&self, s: &mut usize);
|
2014-11-10 16:47:32 -07:00
|
|
|
}
|
|
|
|
|
2015-01-08 22:02:42 +11:00
|
|
|
impl Tr for usize {
|
|
|
|
fn poke(&self, s: &mut usize) {
|
2014-11-10 16:47:32 -07:00
|
|
|
*s = 2;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn main() {
|
2015-03-03 10:42:26 +02:00
|
|
|
let s = &mut 1;
|
2014-11-10 16:47:32 -07:00
|
|
|
|
|
|
|
MyPtr(s).poke(s);
|
|
|
|
//~^ ERROR cannot borrow `*s` as mutable more than once at a time
|
|
|
|
}
|