]>
Commit | Line | Data |
---|---|---|
1a4d82fc JJ |
1 | // Test a case where you have an impl of `Foo<X>` for all `X` that |
2 | // is being applied to `for<'a> Foo<&'a mut X>`. Issue #19730. | |
3 | ||
4 | trait Foo<X> { | |
5 | fn foo(&mut self, x: X) { } | |
6 | } | |
7 | ||
8 | trait Bar<X> { | |
9 | fn bar(&mut self, x: X) { } | |
10 | } | |
11 | ||
12 | impl<'a,X,F> Foo<X> for &'a mut F | |
13 | where F : Foo<X> + Bar<X> | |
14 | { | |
15 | } | |
16 | ||
17 | impl<'a,X,F> Bar<X> for &'a mut F | |
18 | where F : Bar<X> | |
19 | { | |
20 | } | |
21 | ||
22 | fn no_hrtb<'b,T>(mut t: T) | |
23 | where T : Bar<&'b isize> | |
24 | { | |
25 | // OK -- `T : Bar<&'b isize>`, and thus the impl above ensures that | |
26 | // `&mut T : Bar<&'b isize>`. | |
27 | no_hrtb(&mut t); | |
28 | } | |
29 | ||
30 | fn bar_hrtb<T>(mut t: T) | |
31 | where T : for<'b> Bar<&'b isize> | |
32 | { | |
33 | // OK -- `T : for<'b> Bar<&'b isize>`, and thus the impl above | |
34 | // ensures that `&mut T : for<'b> Bar<&'b isize>`. This is an | |
35 | // example of a "perfect forwarding" impl. | |
36 | bar_hrtb(&mut t); | |
37 | } | |
38 | ||
39 | fn foo_hrtb_bar_not<'b,T>(mut t: T) | |
40 | where T : for<'a> Foo<&'a isize> + Bar<&'b isize> | |
41 | { | |
42 | // Not OK -- The forwarding impl for `Foo` requires that `Bar` also | |
43 | // be implemented. Thus to satisfy `&mut T : for<'a> Foo<&'a | |
44 | // isize>`, we require `T : for<'a> Bar<&'a isize>`, but the where | |
45 | // clause only specifies `T : Bar<&'b isize>`. | |
9fa01778 | 46 | foo_hrtb_bar_not(&mut t); //~ ERROR mismatched types |
dfeec247 | 47 | //~| ERROR mismatched types |
1a4d82fc JJ |
48 | } |
49 | ||
50 | fn foo_hrtb_bar_hrtb<T>(mut t: T) | |
51 | where T : for<'a> Foo<&'a isize> + for<'b> Bar<&'b isize> | |
52 | { | |
53 | // OK -- now we have `T : for<'b> Bar&'b isize>`. | |
54 | foo_hrtb_bar_hrtb(&mut t); | |
55 | } | |
56 | ||
57 | fn main() { } |