]>
git.proxmox.com Git - rustc.git/blob - src/test/ui/hrtb/hrtb-perfect-forwarding.rs
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
13 where F
: Foo
<X
> + Bar
<X
>
17 impl<'a
,X
,F
> Bar
<X
> for &'a
mut F
22 fn no_hrtb
<'b
,T
>(mut t
: T
)
23 where T
: Bar
<&'b
isize>
25 // OK -- `T : Bar<&'b isize>`, and thus the impl above ensures that
26 // `&mut T : Bar<&'b isize>`.
30 fn bar_hrtb
<T
>(mut t
: T
)
31 where 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
)
40 where T
: for<'a
> Foo
<&'a
isize> + Bar
<&'b
isize>
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>`.
46 foo_hrtb_bar_not(&mut t
); //~ ERROR mismatched types
47 //~| ERROR mismatched types
50 fn foo_hrtb_bar_hrtb
<T
>(mut t
: T
)
51 where T
: for<'a
> Foo
<&'a
isize> + for<'b
> Bar
<&'b
isize>
53 // OK -- now we have `T : for<'b> Bar&'b isize>`.
54 foo_hrtb_bar_hrtb(&mut t
);