2023-11-18 13:29:39 -06:00
|
|
|
#![deny(deref_into_dyn_supertrait)]
|
|
|
|
use std::ops::Deref;
|
|
|
|
|
|
|
|
trait Bar<T> {}
|
|
|
|
impl<T, U> Bar<U> for T {}
|
|
|
|
|
|
|
|
trait Foo: Bar<i32> {
|
|
|
|
fn as_dyn_bar_u32<'a>(&self) -> &(dyn Bar<u32> + 'a);
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Foo for () {
|
|
|
|
fn as_dyn_bar_u32<'a>(&self) -> &(dyn Bar<u32> + 'a) {
|
|
|
|
self
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl<'a> Deref for dyn Foo + 'a {
|
2024-01-22 06:23:50 -06:00
|
|
|
//~^ ERROR this `Deref` implementation is covered by an implicit supertrait coercion
|
|
|
|
//~| WARN this will change its meaning in a future release!
|
2023-11-18 13:29:39 -06:00
|
|
|
type Target = dyn Bar<u32> + 'a;
|
|
|
|
|
|
|
|
fn deref(&self) -> &Self::Target {
|
|
|
|
self.as_dyn_bar_u32()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn take_dyn<T>(x: &dyn Bar<T>) -> T {
|
|
|
|
todo!()
|
|
|
|
}
|
|
|
|
|
|
|
|
fn main() {
|
|
|
|
let x: &dyn Foo = &();
|
|
|
|
let y = take_dyn(x);
|
|
|
|
let z: u32 = y;
|
|
|
|
}
|