]> git.lizzy.rs Git - rust.git/blob - src/test/ui/nll/issue-57265-return-type-wf-check.rs
Auto merge of #105121 - oli-obk:simpler-cheaper-dump_mir, r=nnethercote
[rust.git] / src / test / ui / nll / issue-57265-return-type-wf-check.rs
1 use std::any::Any;
2
3 #[derive(Debug, Clone)]
4 struct S<T: 'static>(T);
5
6 // S<&'a T> is in the return type, so we get an implied bound
7 // &'a T: 'static
8 fn foo<'a, T>(x: &'a T) -> (S<&'a T>, Box<dyn Any + 'static>) {
9     let y = S(x);
10
11     let z = Box::new(y.clone()) as Box<dyn Any + 'static>;
12     (y, z)
13 }
14
15 fn main() {
16     let x = 5;
17
18     // Check that we require that the argument is of type `&'static String`,
19     // so that the return type is well-formed.
20     let (_, z) = foo(&"hello".to_string());
21     //~^ ERROR temporary value dropped while borrowed
22
23     println!("{:?}", z.downcast_ref::<S<&'static String>>());
24 }