]> git.lizzy.rs Git - rust.git/blob - src/test/ui/hrtb/hrtb-just-for-static.rs
Rollup merge of #97317 - GuillaumeGomez:gui-settings-text-click, r=jsha
[rust.git] / src / test / ui / hrtb / hrtb-just-for-static.rs
1 // revisions: base nll
2 // ignore-compare-mode-nll
3 //[nll] compile-flags: -Z borrowck=mir
4
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.
7
8 trait Foo<X> {
9     fn foo(&self, x: X) { }
10 }
11
12 fn want_hrtb<T>()
13     where T : for<'a> Foo<&'a isize>
14 {
15 }
16
17 // AnyInt implements Foo<&'a isize> for any 'a, so it is a match.
18 struct AnyInt;
19 impl<'a> Foo<&'a isize> for AnyInt { }
20 fn give_any() {
21     want_hrtb::<AnyInt>()
22 }
23
24 // StaticInt only implements Foo<&'static isize>, so it is an error.
25 struct StaticInt;
26 impl Foo<&'static isize> for StaticInt { }
27 fn give_static() {
28     want_hrtb::<StaticInt>() //~ ERROR
29 }
30
31 // AnyInt implements Foo<&'a isize> for any 'a, so it is a match.
32 impl<'a> Foo<&'a isize> for &'a u32 { }
33 fn give_some<'a>() {
34     want_hrtb::<&'a u32>()
35     //[base]~^ ERROR
36     //[nll]~^^ ERROR lifetime may not live long enough
37     //[nll]~| ERROR implementation of `Foo` is not general enough
38 }
39
40 fn main() { }