]> git.lizzy.rs Git - rust.git/blob - src/test/ui/higher-rank-trait-bounds/hrtb-just-for-static.rs
Rollup merge of #100462 - zohnannor:master, r=thomcc
[rust.git] / src / test / ui / higher-rank-trait-bounds / hrtb-just-for-static.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.
3
4 trait Foo<X> {
5     fn foo(&self, x: X) { }
6 }
7
8 fn want_hrtb<T>()
9     where T : for<'a> Foo<&'a isize>
10 {
11 }
12
13 // AnyInt implements Foo<&'a isize> for any 'a, so it is a match.
14 struct AnyInt;
15 impl<'a> Foo<&'a isize> for AnyInt { }
16 fn give_any() {
17     want_hrtb::<AnyInt>()
18 }
19
20 // StaticInt only implements Foo<&'static isize>, so it is an error.
21 struct StaticInt;
22 impl Foo<&'static isize> for StaticInt { }
23 fn give_static() {
24     want_hrtb::<StaticInt>() //~ ERROR
25 }
26
27 // &'a u32 only implements Foo<&'a isize> for specific 'a, so it is an error.
28 impl<'a> Foo<&'a isize> for &'a u32 { }
29 fn give_some<'a>() {
30     want_hrtb::<&'a u32>()
31     //~^ ERROR lifetime may not live long enough
32     //~| ERROR implementation of `Foo` is not general enough
33 }
34
35 fn main() { }