]> git.lizzy.rs Git - rust.git/blob - src/test/ui/regions/region-object-lifetime-4.rs
Use the same message as type & const generics.
[rust.git] / src / test / ui / regions / region-object-lifetime-4.rs
1 // Various tests related to testing how region inference works
2 // with respect to the object receivers.
3
4 // revisions: base nll
5 // ignore-compare-mode-nll
6 //[nll] compile-flags: -Z borrowck=mir
7
8 trait Foo {
9     fn borrowed<'a>(&'a self) -> &'a ();
10 }
11
12 // Here we have two distinct lifetimes, but we try to return a pointer
13 // with the longer lifetime when (from the signature) we only know
14 // that it lives as long as the shorter lifetime. Therefore, error.
15 fn borrowed_receiver_related_lifetimes2<'a,'b>(x: &'a (dyn Foo + 'b)) -> &'b () {
16     x.borrowed()
17     //[base]~^ ERROR cannot infer
18     //[nll]~^^ ERROR lifetime may not live long enough
19 }
20
21 fn main() {}