Created
August 16, 2020 09:26
-
-
Save justanotherdot/84aa09f253628da2d28fbece4f835d7f to your computer and use it in GitHub Desktop.
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
#[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