Closed
Description
STR
use std::ops::{Deref, DerefMut};
struct Foo;
impl Foo {
fn foo(&self) {}
fn foo_mut(&mut self) {}
}
struct Bar(Foo);
impl Deref for Bar {
type Target = Foo;
fn deref(&self) -> &Foo {
&self.0
}
}
impl DerefMut for Bar {
fn deref_mut(&mut self) -> &mut Foo {
&mut self.0
}
}
#[cfg(not(works))]
fn test(mut bar: Box<Bar>) {
bar.foo(); // OK
bar.foo_mut();
//~^ error: cannot borrow immutable borrowed content as mutable (WRONG)
}
#[cfg(works)]
fn test(mut bar: Box<Bar>) {
bar.deref_mut().foo_mut();
//~^ but this actually works!
}
fn main() {}
Version
rustc 1.2.0-nightly (613e57b44 2015-06-01) (built 2015-06-02)