]> git.lizzy.rs Git - rust.git/blob - tests/ui/regions/regions-bounded-method-type-parameters-trait-bound.rs
internally change regions to be covariant
[rust.git] / tests / ui / regions / regions-bounded-method-type-parameters-trait-bound.rs
1 // Check that explicit region bounds are allowed on the various
2 // nominal types (but not on other types) and that they are type
3 // checked.
4
5 struct Inv<'a> { // invariant w/r/t 'a
6     x: &'a mut &'a isize
7 }
8
9 trait Foo<'x> {
10     fn method<'y:'x>(self, y: Inv<'y>);
11 }
12
13 fn caller1<'a,'b,F:Foo<'a>>(a: Inv<'a>, b: Inv<'b>, f: F) {
14     // Here the value provided for 'y is 'a, and hence 'a:'a holds.
15     f.method(a);
16 }
17
18 fn caller2<'a,'b,F:Foo<'a>>(a: Inv<'a>, b: Inv<'b>, f: F) {
19     // Here the value provided for 'y is 'b, and hence 'b:'a does not hold.
20     f.method(b);
21     //~^ ERROR lifetime may not live long enough
22 }
23
24 fn caller3<'a,'b:'a,F:Foo<'a>>(a: Inv<'a>, b: Inv<'b>, f: F) {
25     // Here the value provided for 'y is 'b, and hence 'b:'a holds.
26     f.method(b);
27 }
28
29 fn main() { }