1 // run-pass
2 // Test that even with prior inferred parameters, object lifetimes of objects after are still
3 // valid.
4
5 // pretty-expanded FIXME #23616
6
7 #![allow(dead_code)]
8 #![feature(generic_arg_infer)]
9
10 trait Test {
foo(&self)11 fn foo(&self) { }
12 }
13
14 struct Foo;
15 impl Test for Foo {}
16
17 struct SomeStruct<'a> {
18 t: &'a dyn Test,
19 u: &'a (dyn Test+'a),
20 }
21
a<'a, const N: usize>(_: [u8; N], t: &'a (dyn Test+'a), mut ss: SomeStruct<'a>)22 fn a<'a, const N: usize>(_: [u8; N], t: &'a (dyn Test+'a), mut ss: SomeStruct<'a>) {
23 ss.t = t;
24 }
25
b<'a, T>(_: T, t: &'a (dyn Test+'a), mut ss: SomeStruct<'a>)26 fn b<'a, T>(_: T, t: &'a (dyn Test+'a), mut ss: SomeStruct<'a>) {
27 ss.u = t;
28 }
29
main()30 fn main() {
31 // Inside a function body, we can just infer both
32 // lifetimes, to allow &'tmp (Display+'static).
33 a::<_>([], &Foo as &dyn Test, SomeStruct{t:&Foo,u:&Foo});
34 b::<_>(0u8, &Foo as &dyn Test, SomeStruct{t:&Foo,u:&Foo});
35 }
36