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