Skip to content

Instantly share code, notes, and snippets.

@justanotherdot
Created August 16, 2020 09:26
Show Gist options
  • Save justanotherdot/84aa09f253628da2d28fbece4f835d7f to your computer and use it in GitHub Desktop.
Save justanotherdot/84aa09f253628da2d28fbece4f835d7f to your computer and use it in GitHub Desktop.
#[derive(Debug)]
struct X(pub i32);
impl AsRef<X> for X {
fn as_ref(&self) -> &X {
self
}
}
fn f<A: AsRef<X> + std::fmt::Debug>(x: A) {
dbg!("f", x);
}
trait K {
fn h(&self);
}
impl K for X {
fn h(&self) {
// fine.
f(self)
}
}
impl X where Self: AsRef<X> {
fn g(&self) {
// not fine.
f(self);
}
fn p<A: K + AsRef<X> + std::fmt::Debug>(x: A) {
f(x);
}
}
fn main() {
let v = X(42);
v.g();
v.h();
X::p(v);
X::g(v);
f(v);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment