diff options
Diffstat (limited to '')
-rw-r--r-- | tests/ui/traits/object/issue-44454-3.rs | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/tests/ui/traits/object/issue-44454-3.rs b/tests/ui/traits/object/issue-44454-3.rs new file mode 100644 index 000000000..bff727035 --- /dev/null +++ b/tests/ui/traits/object/issue-44454-3.rs @@ -0,0 +1,33 @@ +// Taken from https://github.com/rust-lang/rust/issues/44454#issuecomment-1332781290 + +use std::any::Any; + +trait Animal<X>: 'static {} + +trait Projector { + type Foo; +} + +impl<X> Projector for dyn Animal<X> { + type Foo = X; +} + +fn make_static<'a, T>(t: &'a T) -> &'static T { + let x: <dyn Animal<&'a T> as Projector>::Foo = t; + let any = generic::<dyn Animal<&'a T>, &'a T>(x); + //~^ ERROR: lifetime may not live long enough + any.downcast_ref::<&'static T>().unwrap() +} + +fn generic<T: Projector + Animal<U> + ?Sized, U>(x: <T as Projector>::Foo) -> Box<dyn Any> { + make_static_any(x) +} + +fn make_static_any<U: 'static>(u: U) -> Box<dyn Any> { + Box::new(u) +} + +fn main() { + let a = make_static(&"salut".to_string()); + println!("{}", *a); +} |