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 {
foo(&self)12 fn foo(&self) { }
13 }
14
15 struct SomeStruct<'a> {
16 t: &'a dyn Test,
17 u: &'a (dyn Test+'a),
18 }
19
a<'a>(t: &'a dyn Test, mut ss: SomeStruct<'a>)20 fn a<'a>(t: &'a dyn Test, mut ss: SomeStruct<'a>) {
21 ss.t = t;
22 }
23
b<'a>(t: &'a dyn Test, mut ss: SomeStruct<'a>)24 fn b<'a>(t: &'a dyn Test, mut ss: SomeStruct<'a>) {
25 ss.u = t;
26 }
27
c<'a>(t: &'a (dyn Test+'a), mut ss: SomeStruct<'a>)28 fn c<'a>(t: &'a (dyn Test+'a), mut ss: SomeStruct<'a>) {
29 ss.t = t;
30 }
31
d<'a>(t: &'a (dyn Test+'a), mut ss: SomeStruct<'a>)32 fn d<'a>(t: &'a (dyn Test+'a), mut ss: SomeStruct<'a>) {
33 ss.u = t;
34 }
35
e<'a>(_: &'a (dyn Display+'static))36 fn e<'a>(_: &'a (dyn Display+'static)) {}
37
main()38 fn main() {
39 // Inside a function body, we can just infer both
40 // lifetimes, to allow &'tmp (Display+'static).
41 e(&0 as &dyn Display);
42 }
43