]> git.lizzy.rs Git - rust.git/blob - src/test/ui/issues/issue-54302-cases.rs
Rollup merge of #62337 - Mark-Simulacrum:fix-cpu-usage-script, r=alexcrichton
[rust.git] / src / test / ui / issues / issue-54302-cases.rs
1 trait Mirror {
2     type Image;
3     fn coerce(self) -> Self::Image;
4 }
5
6 impl<T> Mirror for T {
7     type Image = T;
8     fn coerce(self) -> Self { self }
9 }
10
11 trait Foo<'x, T> {
12     fn foo(self) -> &'x T;
13 }
14
15 impl<'s, 'x, T: 'x> Foo<'x, T> for &'s T where &'s T: Foo2<'x, T> {
16     fn foo(self) -> &'x T { self.foo2() }
17 }
18
19 trait Foo2<'x, T> {
20     fn foo2(self) -> &'x T;
21 }
22
23 // example 1 - fails leak check
24 impl<'x> Foo2<'x, u32> for &'x u32
25 {
26     fn foo2(self) -> &'x u32 { self }
27 }
28
29 // example 2 - OK with this issue
30 impl<'x, 'a: 'x> Foo2<'x, i32> for &'a i32
31 {
32     fn foo2(self) -> &'x i32 { self }
33 }
34
35 // example 3 - fails due to issue #XYZ + Leak-check
36 impl<'x, T> Foo2<'x, u64> for T
37     where T: Mirror<Image=&'x u64>
38 {
39     fn foo2(self) -> &'x u64 { self.coerce() }
40 }
41
42 // example 4 - fails due to issue #XYZ
43 impl<'x, 'a: 'x, T> Foo2<'x, i64> for T
44     where T: Mirror<Image=&'a i64>
45 {
46     fn foo2(self) -> &'x i64 { self.coerce() }
47 }
48
49
50 trait RefFoo<T> {
51     fn ref_foo(&self) -> &'static T;
52 }
53
54 impl<T> RefFoo<T> for T where for<'a> &'a T: Foo<'static, T> {
55     fn ref_foo(&self) -> &'static T {
56         self.foo()
57     }
58 }
59
60
61 fn coerce_lifetime1(a: &u32) -> &'static u32
62 {
63     <u32 as RefFoo<u32>>::ref_foo(a)
64     //~^ ERROR not general enough
65 }
66
67 fn coerce_lifetime2(a: &i32) -> &'static i32
68 {
69     <i32 as RefFoo<i32>>::ref_foo(a)
70     //~^ ERROR not general enough
71 }
72
73 fn coerce_lifetime3(a: &u64) -> &'static u64
74 {
75     <u64 as RefFoo<u64>>::ref_foo(a)
76     //~^ ERROR not general enough
77 }
78
79 fn coerce_lifetime4(a: &i64) -> &'static i64
80 {
81     <i64 as RefFoo<i64>>::ref_foo(a)
82     //~^ ERROR not general enough
83 }
84
85 fn main() {}