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