From 218caa410aa38c29984be31a5229b9fa717560ee Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Wed, 17 Apr 2024 14:19:13 +0200 Subject: Merging upstream version 1.68.2+dfsg1. Signed-off-by: Daniel Baumann --- tests/ui/traits/object/issue-44454-3.rs | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 tests/ui/traits/object/issue-44454-3.rs (limited to 'tests/ui/traits/object/issue-44454-3.rs') 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: 'static {} + +trait Projector { + type Foo; +} + +impl Projector for dyn Animal { + type Foo = X; +} + +fn make_static<'a, T>(t: &'a T) -> &'static T { + let x: as Projector>::Foo = t; + let any = generic::, &'a T>(x); + //~^ ERROR: lifetime may not live long enough + any.downcast_ref::<&'static T>().unwrap() +} + +fn generic + ?Sized, U>(x: ::Foo) -> Box { + make_static_any(x) +} + +fn make_static_any(u: U) -> Box { + Box::new(u) +} + +fn main() { + let a = make_static(&"salut".to_string()); + println!("{}", *a); +} -- cgit v1.2.3