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.
5 fn foo(&mut self, x: X) {}
9 fn bar(&mut self, x: X) {}
12 impl<'a, X, F> Foo<X> for &'a mut F where F: Foo<X> + Bar<X> {}
14 impl<'a, X, F> Bar<X> for &'a mut F where F: Bar<X> {}
16 fn no_hrtb<'b, T>(mut t: T)
20 // OK -- `T : Bar<&'b isize>`, and thus the impl above ensures that
21 // `&mut T : Bar<&'b isize>`.
25 fn bar_hrtb<T>(mut t: T)
27 T: for<'b> Bar<&'b isize>,
29 // OK -- `T : for<'b> Bar<&'b isize>`, and thus the impl above
30 // ensures that `&mut T : for<'b> Bar<&'b isize>`. This is an
31 // example of a "perfect forwarding" impl.
35 fn foo_hrtb_bar_not<'b, T>(mut t: T)
37 T: for<'a> Foo<&'a isize> + Bar<&'b isize>,
39 // Not OK -- The forwarding impl for `Foo` requires that `Bar` also
40 // be implemented. Thus to satisfy `&mut T : for<'a> Foo<&'a
41 // isize>`, we require `T : for<'a> Bar<&'a isize>`, but the where
42 // clause only specifies `T : Bar<&'b isize>`.
43 foo_hrtb_bar_not(&mut t);
44 //~^ ERROR implementation of `Bar` is not general enough
45 //~| ERROR implementation of `Bar` is not general enough
48 fn foo_hrtb_bar_hrtb<T>(mut t: T)
50 T: for<'a> Foo<&'a isize> + for<'b> Bar<&'b isize>,
52 // OK -- now we have `T : for<'b> Bar<&'b isize>`.
53 foo_hrtb_bar_hrtb(&mut t);