Created
February 1, 2022 09:21
-
-
Save little-dude/2b309f2b683d2713e3ea6d37deb3a627 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
// This runs into https://github.com/rust-lang/rust/issues/56105 | |
pub trait MyTrait<T> { | |
fn method(&self, _:T); | |
} | |
impl<T> MyTrait<T> for Box<dyn MyTrait<T>> { | |
fn method(&self, t: T) { | |
(**self).method(t) | |
} | |
} | |
// Why does this conflict with the impl above? | |
impl<'a, T> MyTrait<&'a T> for Box<dyn for<'t> MyTrait<&'t T>> { | |
fn method(&self, t: &'a T) { | |
(**self).method(t) | |
} | |
} | |
// For the sake of the example, define | |
struct Foo; | |
impl<'t> MyTrait<&'t u32> for Foo { | |
fn method(&self, _: &'t u32) {} | |
} | |
fn func<T>(_: T) | |
where | |
T: for<'t> MyTrait<&'t u32>, | |
{ | |
} | |
fn main() { | |
let foo = Foo; | |
func(foo); | |
let boxed_foo: Box<dyn for<'t> MyTrait<&'t u32>> = Box::new(Foo); | |
func(boxed_foo); | |
} |
Author
little-dude
commented
Feb 1, 2022
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment