Created
October 9, 2015 01:03
-
-
Save skeleten/6aebc7e372e63e6c0d30 to your computer and use it in GitHub Desktop.
Issue 19509 for rust-lang/rust
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use std::ops::Deref; | |
pub struct Foo { | |
baz: Bar, | |
} | |
pub struct Bar; | |
impl Foo { | |
pub fn foo_method(&self) { | |
/* do something, doesn't really matter */ | |
} | |
} | |
impl Bar { | |
pub fn bar_method(&self) { | |
} | |
} | |
impl Deref for Foo { | |
type Target = Bar; | |
fn deref<'a>(&'a self) -> &'a Self::Target { | |
&self.baz | |
} | |
} | |
impl Deref for Bar { | |
type Target = Foo; | |
fn deref<'a>(&'a self) -> &'a Self::Target { | |
panic!() | |
} | |
} | |
fn main() { | |
let foo = Foo { | |
baz: Bar, | |
}; | |
let bar = Bar; | |
// should work | |
foo.bar_method(); | |
// should compile but panic | |
bar.foo_method(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment