2 // ignore-compare-mode-nll
3 //[nll] compile-flags: -Z borrowck=mir
5 // Test a case where you have an impl of `Foo<X>` for all `X` that
6 // is being applied to `for<'a> Foo<&'a mut X>`. Issue #19730.
9 fn foo(&mut self, x: X) {}
13 fn bar(&mut self, x: X) {}
16 impl<'a, X, F> Foo<X> for &'a mut F where F: Foo<X> + Bar<X> {}
18 impl<'a, X, F> Bar<X> for &'a mut F where F: Bar<X> {}
20 fn no_hrtb<'b, T>(mut t: T) //[nll]~ WARN function cannot return
24 // OK -- `T : Bar<&'b isize>`, and thus the impl above ensures that
25 // `&mut T : Bar<&'b isize>`.
29 fn bar_hrtb<T>(mut t: T) //[nll]~ WARN function cannot return
31 T: for<'b> Bar<&'b isize>,
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.
39 fn foo_hrtb_bar_not<'b, T>(mut t: T) //[nll]~ WARN function cannot return
41 T: for<'a> Foo<&'a isize> + Bar<&'b isize>,
43 // Not OK -- The forwarding impl for `Foo` requires that `Bar` also
44 // be implemented. Thus to satisfy `&mut T : for<'a> Foo<&'a
45 // isize>`, we require `T : for<'a> Bar<&'a isize>`, but the where
46 // clause only specifies `T : Bar<&'b isize>`.
47 foo_hrtb_bar_not(&mut t);
48 //~^ ERROR implementation of `Bar` is not general enough
49 //[base]~^^ ERROR implementation of `Bar` is not general enough
50 //[nll]~^^^ ERROR lifetime may not live long enough
53 fn foo_hrtb_bar_hrtb<T>(mut t: T) //[nll]~ WARN function cannot return
55 T: for<'a> Foo<&'a isize> + for<'b> Bar<&'b isize>,
57 // OK -- now we have `T : for<'b> Bar<&'b isize>`.
58 foo_hrtb_bar_hrtb(&mut t);