diff options
Diffstat (limited to 'tests/ui/regions/regions-trait-object-subtyping.rs')
-rw-r--r-- | tests/ui/regions/regions-trait-object-subtyping.rs | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/tests/ui/regions/regions-trait-object-subtyping.rs b/tests/ui/regions/regions-trait-object-subtyping.rs new file mode 100644 index 000000000..1d7a766de --- /dev/null +++ b/tests/ui/regions/regions-trait-object-subtyping.rs @@ -0,0 +1,26 @@ +trait Dummy { fn dummy(&self); } + +fn foo1<'a:'b,'b>(x: &'a mut (dyn Dummy+'a)) -> &'b mut (dyn Dummy+'b) { + // Here, we are able to coerce + x +} + +fn foo2<'a:'b,'b>(x: &'b mut (dyn Dummy+'a)) -> &'b mut (dyn Dummy+'b) { + // Here, we are able to coerce + x +} + +fn foo3<'a,'b>(x: &'a mut dyn Dummy) -> &'b mut dyn Dummy { + // Without knowing 'a:'b, we can't coerce + x + //~^ ERROR lifetime may not live long enough +} + +struct Wrapper<T>(T); +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 + //~^ ERROR lifetime may not live long enough +} + +fn main() {} |