2019-07-26 16:54:25 -05:00
|
|
|
// run-pass
|
2015-02-11 18:45:19 -06:00
|
|
|
// Test that the lifetime of the enclosing `&` is used for the object
|
|
|
|
// lifetime bound.
|
|
|
|
|
2015-03-22 15:13:15 -05:00
|
|
|
// pretty-expanded FIXME #23616
|
|
|
|
|
2015-02-11 18:45:19 -06:00
|
|
|
#![allow(dead_code)]
|
|
|
|
|
2017-01-25 09:32:44 -06:00
|
|
|
use std::fmt::Display;
|
|
|
|
|
2015-02-11 18:45:19 -06:00
|
|
|
trait Test {
|
|
|
|
fn foo(&self) { }
|
|
|
|
}
|
|
|
|
|
|
|
|
struct SomeStruct<'a> {
|
2019-05-28 13:47:21 -05:00
|
|
|
t: &'a dyn Test,
|
|
|
|
u: &'a (dyn Test+'a),
|
2015-02-11 18:45:19 -06:00
|
|
|
}
|
|
|
|
|
2019-05-28 13:47:21 -05:00
|
|
|
fn a<'a>(t: &'a dyn Test, mut ss: SomeStruct<'a>) {
|
2015-02-11 18:45:19 -06:00
|
|
|
ss.t = t;
|
|
|
|
}
|
|
|
|
|
2019-05-28 13:47:21 -05:00
|
|
|
fn b<'a>(t: &'a dyn Test, mut ss: SomeStruct<'a>) {
|
2015-02-11 18:45:19 -06:00
|
|
|
ss.u = t;
|
|
|
|
}
|
|
|
|
|
2019-05-28 13:47:21 -05:00
|
|
|
fn c<'a>(t: &'a (dyn Test+'a), mut ss: SomeStruct<'a>) {
|
2015-02-11 18:45:19 -06:00
|
|
|
ss.t = t;
|
|
|
|
}
|
|
|
|
|
2019-05-28 13:47:21 -05:00
|
|
|
fn d<'a>(t: &'a (dyn Test+'a), mut ss: SomeStruct<'a>) {
|
2015-02-11 18:45:19 -06:00
|
|
|
ss.u = t;
|
|
|
|
}
|
|
|
|
|
2019-05-28 13:47:21 -05:00
|
|
|
fn e<'a>(_: &'a (dyn Display+'static)) {}
|
2015-02-11 18:45:19 -06:00
|
|
|
|
|
|
|
fn main() {
|
2017-01-25 09:32:44 -06:00
|
|
|
// Inside a function body, we can just infer both
|
|
|
|
// lifetimes, to allow &'tmp (Display+'static).
|
2019-05-28 13:47:21 -05:00
|
|
|
e(&0 as &dyn Display);
|
2015-02-11 18:45:19 -06:00
|
|
|
}
|