]>
git.proxmox.com Git - rustc.git/blob - src/test/compile-fail/hrtb-perfect-forwarding.rs
1 // Copyright 2014 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
11 // Test a case where you have an impl of `Foo<X>` for all `X` that
12 // is being applied to `for<'a> Foo<&'a mut X>`. Issue #19730.
15 fn foo(&mut self, x
: X
) { }
19 fn bar(&mut self, x
: X
) { }
22 impl<'a
,X
,F
> Foo
<X
> for &'a
mut F
23 where F
: Foo
<X
> + Bar
<X
>
27 impl<'a
,X
,F
> Bar
<X
> for &'a
mut F
32 fn no_hrtb
<'b
,T
>(mut t
: T
)
33 where T
: Bar
<&'b
isize>
35 // OK -- `T : Bar<&'b isize>`, and thus the impl above ensures that
36 // `&mut T : Bar<&'b isize>`.
40 fn bar_hrtb
<T
>(mut t
: T
)
41 where T
: for<'b
> Bar
<&'b
isize>
43 // OK -- `T : for<'b> Bar<&'b isize>`, and thus the impl above
44 // ensures that `&mut T : for<'b> Bar<&'b isize>`. This is an
45 // example of a "perfect forwarding" impl.
49 fn foo_hrtb_bar_not
<'b
,T
>(mut t
: T
)
50 where T
: for<'a
> Foo
<&'a
isize> + Bar
<&'b
isize>
52 // Not OK -- The forwarding impl for `Foo` requires that `Bar` also
53 // be implemented. Thus to satisfy `&mut T : for<'a> Foo<&'a
54 // isize>`, we require `T : for<'a> Bar<&'a isize>`, but the where
55 // clause only specifies `T : Bar<&'b isize>`.
56 foo_hrtb_bar_not(&mut t
); //~ ERROR `for<'a> T: Bar<&'a isize>` is not satisfied
59 fn foo_hrtb_bar_hrtb
<T
>(mut t
: T
)
60 where T
: for<'a
> Foo
<&'a
isize> + for<'b
> Bar
<&'b
isize>
62 // OK -- now we have `T : for<'b> Bar&'b isize>`.
63 foo_hrtb_bar_hrtb(&mut t
);