// Test a case where you have an impl of `Foo` for all `X` that // is being applied to `for<'a> Foo<&'a mut X>`. Issue #19730. trait Foo { fn foo(&mut self, x: X) { } } trait Bar { fn bar(&mut self, x: X) { } } impl<'a,X,F> Foo for &'a mut F where F : Foo + Bar { } impl<'a,X,F> Bar for &'a mut F where F : Bar { } fn no_hrtb<'b,T>(mut t: T) where T : Bar<&'b isize> { // OK -- `T : Bar<&'b isize>`, and thus the impl above ensures that // `&mut T : Bar<&'b isize>`. no_hrtb(&mut t); } fn bar_hrtb(mut t: T) where T : for<'b> Bar<&'b isize> { // OK -- `T : for<'b> Bar<&'b isize>`, and thus the impl above // ensures that `&mut T : for<'b> Bar<&'b isize>`. This is an // example of a "perfect forwarding" impl. bar_hrtb(&mut t); } fn foo_hrtb_bar_not<'b,T>(mut t: T) where T : for<'a> Foo<&'a isize> + Bar<&'b isize> { // Not OK -- The forwarding impl for `Foo` requires that `Bar` also // be implemented. Thus to satisfy `&mut T : for<'a> Foo<&'a // isize>`, we require `T : for<'a> Bar<&'a isize>`, but the where // clause only specifies `T : Bar<&'b isize>`. foo_hrtb_bar_not(&mut t); //~ ERROR mismatched types //~| ERROR mismatched types } fn foo_hrtb_bar_hrtb(mut t: T) where T : for<'a> Foo<&'a isize> + for<'b> Bar<&'b isize> { // OK -- now we have `T : for<'b> Bar&'b isize>`. foo_hrtb_bar_hrtb(&mut t); } fn main() { }