rust/tests/ui/object-lifetime/object-lifetime-default-from-rptr.rs

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

43 lines
769 B
Rust
Raw Normal View History

// run-pass
// Test that the lifetime of the enclosing `&` is used for the object
// lifetime bound.
// pretty-expanded FIXME #23616
#![allow(dead_code)]
use std::fmt::Display;
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),
}
2019-05-28 13:47:21 -05:00
fn a<'a>(t: &'a dyn Test, mut ss: SomeStruct<'a>) {
ss.t = t;
}
2019-05-28 13:47:21 -05:00
fn b<'a>(t: &'a dyn Test, mut ss: SomeStruct<'a>) {
ss.u = t;
}
2019-05-28 13:47:21 -05:00
fn c<'a>(t: &'a (dyn Test+'a), mut ss: SomeStruct<'a>) {
ss.t = t;
}
2019-05-28 13:47:21 -05:00
fn d<'a>(t: &'a (dyn Test+'a), mut ss: SomeStruct<'a>) {
ss.u = t;
}
2019-05-28 13:47:21 -05:00
fn e<'a>(_: &'a (dyn Display+'static)) {}
fn main() {
// 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);
}