2014-11-10 17:47:32 -06:00
|
|
|
// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
|
|
|
|
// file at the top-level directory of this distribution and at
|
|
|
|
// http://rust-lang.org/COPYRIGHT.
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
|
|
|
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
|
|
|
// option. This file may not be copied, modified, or distributed
|
|
|
|
// except according to those terms.
|
|
|
|
|
2014-12-22 11:04:23 -06:00
|
|
|
use std::ops::Deref;
|
|
|
|
|
2015-01-08 05:02:42 -06:00
|
|
|
struct MyPtr<'a>(&'a mut usize);
|
2015-01-01 13:53:20 -06:00
|
|
|
impl<'a> Deref for MyPtr<'a> {
|
2015-01-08 05:02:42 -06:00
|
|
|
type Target = usize;
|
2015-01-01 13:53:20 -06:00
|
|
|
|
2015-01-08 05:02:42 -06:00
|
|
|
fn deref<'b>(&'b self) -> &'b usize { self.0 }
|
2014-11-10 17:47:32 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
trait Tr {
|
2015-01-08 05:02:42 -06:00
|
|
|
fn poke(&self, s: &mut usize);
|
2014-11-10 17:47:32 -06:00
|
|
|
}
|
|
|
|
|
2015-01-08 05:02:42 -06:00
|
|
|
impl Tr for usize {
|
|
|
|
fn poke(&self, s: &mut usize) {
|
2014-11-10 17:47:32 -06:00
|
|
|
*s = 2;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn main() {
|
2015-02-18 04:42:01 -06:00
|
|
|
let s = &mut 1_usize;
|
2014-11-10 17:47:32 -06:00
|
|
|
|
|
|
|
MyPtr(s).poke(s);
|
|
|
|
//~^ ERROR cannot borrow `*s` as mutable more than once at a time
|
|
|
|
}
|