]> git.lizzy.rs Git - rust.git/blob - tests/ui/borrowck/regions-bound-missing-bound-in-impl.rs
Auto merge of #106646 - Amanieu:ilp32-object, r=Mark-Simulacrum
[rust.git] / tests / ui / borrowck / regions-bound-missing-bound-in-impl.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 pub trait Foo<'a, 't> {
10     fn no_bound<'b>(self, b: Inv<'b>);
11     fn has_bound<'b:'a>(self, b: Inv<'b>);
12     fn wrong_bound1<'b,'c,'d:'a+'b>(self, b: Inv<'b>, c: Inv<'c>, d: Inv<'d>);
13     fn wrong_bound2<'b,'c,'d:'a+'b>(self, b: Inv<'b>, c: Inv<'c>, d: Inv<'d>);
14     fn okay_bound<'b,'c,'d:'a+'b+'c>(self, b: Inv<'b>, c: Inv<'c>, d: Inv<'d>);
15     fn another_bound<'x: 'a>(self, x: Inv<'x>, y: Inv<'t>);
16 }
17
18 impl<'a, 't> Foo<'a, 't> for &'a isize {
19     fn no_bound<'b:'a>(self, b: Inv<'b>) {
20         //~^ ERROR lifetime parameters or bounds on method `no_bound` do not match
21     }
22
23     fn has_bound<'b>(self, b: Inv<'b>) {
24         //~^ ERROR lifetime parameters or bounds on method `has_bound` do not match
25     }
26
27     fn wrong_bound1<'b,'c,'d:'a+'c>(self, b: Inv<'b>, c: Inv<'c>, d: Inv<'d>) {
28         //~^ ERROR method not compatible with trait
29         //~| ERROR method not compatible with trait
30         //
31         // Note: This is a terrible error message. It is caused
32         // because, in the trait, 'b is early bound, and in the impl,
33         // 'c is early bound, so -- after substitution -- the
34         // lifetimes themselves look isomorphic.  We fail because the
35         // lifetimes that appear in the types are in the wrong
36         // order. This should really be fixed by keeping more
37         // information about the lifetime declarations in the trait so
38         // that we can compare better to the impl, even in cross-crate
39         // cases.
40     }
41
42     fn wrong_bound2(self, b: Inv, c: Inv, d: Inv) {
43         //~^ ERROR lifetime parameters or bounds on method `wrong_bound2` do not match the trait
44     }
45
46     fn okay_bound<'b,'c,'e:'b+'c>(self, b: Inv<'b>, c: Inv<'c>, e: Inv<'e>) {
47     }
48
49     fn another_bound<'x: 't>(self, x: Inv<'x>, y: Inv<'t>) {
50         //~^ ERROR E0276
51     }
52 }
53
54 fn main() { }