]> git.lizzy.rs Git - rust.git/blob - src/test/ui/object-lifetime/object-lifetime-default-inferred.rs
Rollup merge of #104024 - noeddl:unused-must-use, r=compiler-errors
[rust.git] / src / test / ui / object-lifetime / object-lifetime-default-inferred.rs
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 {
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
22 fn a<'a, const N: usize>(_: [u8; N], t: &'a (dyn Test+'a), mut ss: SomeStruct<'a>) {
23     ss.t = t;
24 }
25
26 fn b<'a, T>(_: T, t: &'a (dyn Test+'a), mut ss: SomeStruct<'a>) {
27     ss.u = t;
28 }
29
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 }