]> git.lizzy.rs Git - rust.git/blob - tests/ui/object-lifetime/object-lifetime-default-from-ref-struct.rs
Rollup merge of #106664 - chenyukang:yukang/fix-106597-remove-lseek, r=cuviper
[rust.git] / tests / ui / object-lifetime / object-lifetime-default-from-ref-struct.rs
1 // run-pass
2 // Test that the lifetime of the enclosing `&` is used for the object
3 // lifetime bound.
4
5 // pretty-expanded FIXME #23616
6
7 #![allow(dead_code)]
8
9 use std::fmt::Display;
10
11 trait Test {
12     fn foo(&self) { }
13 }
14
15 struct Ref<'a,T:'a+?Sized> {
16     r: &'a T
17 }
18
19 struct Ref2<'a,'b,T:'a+'b+?Sized> {
20     a: &'a T,
21     b: &'b T
22 }
23
24 struct SomeStruct<'a> {
25     t: Ref<'a, dyn Test>,
26     u: Ref<'a, dyn Test+'a>,
27 }
28
29 fn a<'a>(t: Ref<'a, dyn Test>, mut ss: SomeStruct<'a>) {
30     ss.t = t;
31 }
32
33 fn b<'a>(t: Ref<'a, dyn Test>, mut ss: SomeStruct<'a>) {
34     ss.u = t;
35 }
36
37 fn c<'a>(t: Ref<'a, dyn Test+'a>, mut ss: SomeStruct<'a>) {
38     ss.t = t;
39 }
40
41 fn d<'a>(t: Ref<'a, dyn Test+'a>, mut ss: SomeStruct<'a>) {
42     ss.u = t;
43 }
44
45 fn e<'a>(_: Ref<'a, dyn Display+'static>) {}
46 fn g<'a, 'b>(_: Ref2<'a, 'b, dyn Display+'static>) {}
47
48
49 fn main() {
50     // Inside a function body, we can just infer all
51     // lifetimes, to allow Ref<'tmp, Display+'static>
52     // and Ref2<'tmp, 'tmp, Display+'static>.
53     let x = &0 as &(dyn Display+'static);
54     let r: Ref<dyn Display> = Ref { r: x };
55     let r2: Ref2<dyn Display> = Ref2 { a: x, b: x };
56     e(r);
57     g(r2);
58 }