rust/tests/ui/regions/regions-trait-object-subtyping.rs

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

27 lines
663 B
Rust
Raw Normal View History

trait Dummy { fn dummy(&self); }
2019-05-28 18:46:13 +00:00
fn foo1<'a:'b,'b>(x: &'a mut (dyn Dummy+'a)) -> &'b mut (dyn Dummy+'b) {
// Here, we are able to coerce
x
}
2019-05-28 18:46:13 +00:00
fn foo2<'a:'b,'b>(x: &'b mut (dyn Dummy+'a)) -> &'b mut (dyn Dummy+'b) {
// Here, we are able to coerce
x
}
2019-05-28 18:46:13 +00:00
fn foo3<'a,'b>(x: &'a mut dyn Dummy) -> &'b mut dyn Dummy {
// Without knowing 'a:'b, we can't coerce
x
2022-04-01 17:13:25 +00:00
//~^ ERROR lifetime may not live long enough
}
struct Wrapper<T>(T);
2019-05-28 18:46:13 +00:00
fn foo4<'a:'b,'b>(x: Wrapper<&'a mut dyn Dummy>) -> Wrapper<&'b mut dyn Dummy> {
// We can't coerce because it is packed in `Wrapper`
x
2022-04-01 17:13:25 +00:00
//~^ ERROR lifetime may not live long enough
}
fn main() {}