]> git.lizzy.rs Git - rust.git/blob - tests/ui/object-lifetime/object-lifetime-default-from-rptr.rs
Rollup merge of #107615 - notriddle:notriddle/nbsp, r=GuillaumeGomez
[rust.git] / tests / ui / object-lifetime / object-lifetime-default-from-rptr.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 SomeStruct<'a> {
16     t: &'a dyn Test,
17     u: &'a (dyn Test+'a),
18 }
19
20 fn a<'a>(t: &'a dyn Test, mut ss: SomeStruct<'a>) {
21     ss.t = t;
22 }
23
24 fn b<'a>(t: &'a dyn Test, mut ss: SomeStruct<'a>) {
25     ss.u = t;
26 }
27
28 fn c<'a>(t: &'a (dyn Test+'a), mut ss: SomeStruct<'a>) {
29     ss.t = t;
30 }
31
32 fn d<'a>(t: &'a (dyn Test+'a), mut ss: SomeStruct<'a>) {
33     ss.u = t;
34 }
35
36 fn e<'a>(_: &'a (dyn Display+'static)) {}
37
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 }