Skip to content

Instantly share code, notes, and snippets.

@skeleten
Created October 9, 2015 01:03
Show Gist options
  • Save skeleten/6aebc7e372e63e6c0d30 to your computer and use it in GitHub Desktop.
Save skeleten/6aebc7e372e63e6c0d30 to your computer and use it in GitHub Desktop.
Issue 19509 for rust-lang/rust
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