1 // Copyright 2018 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.
13 fn coerce(self) -> Self::Image;
16 impl<T> Mirror for T {
18 fn coerce(self) -> Self { self }
22 fn foo(self) -> &'x T;
25 impl<'s, 'x, T: 'x> Foo<'x, T> for &'s T where &'s T: Foo2<'x, T> {
26 fn foo(self) -> &'x T { self.foo2() }
30 fn foo2(self) -> &'x T;
33 // example 1 - fails leak check
34 impl<'x> Foo2<'x, u32> for &'x u32
36 fn foo2(self) -> &'x u32 { self }
39 // example 2 - OK with this issue
40 impl<'x, 'a: 'x> Foo2<'x, i32> for &'a i32
42 fn foo2(self) -> &'x i32 { self }
45 // example 3 - fails due to issue #XYZ + Leak-check
46 impl<'x, T> Foo2<'x, u64> for T
47 where T: Mirror<Image=&'x u64>
49 fn foo2(self) -> &'x u64 { self.coerce() }
52 // example 4 - fails due to issue #XYZ
53 impl<'x, 'a: 'x, T> Foo2<'x, i64> for T
54 where T: Mirror<Image=&'a i64>
56 fn foo2(self) -> &'x i64 { self.coerce() }
61 fn ref_foo(&self) -> &'static T;
64 impl<T> RefFoo<T> for T where for<'a> &'a T: Foo<'static, T> {
65 fn ref_foo(&self) -> &'static T {
71 fn coerce_lifetime1(a: &u32) -> &'static u32
73 <u32 as RefFoo<u32>>::ref_foo(a)
74 //~^ ERROR the trait bound `for<'a> &'a u32: Foo2<'_, u32>` is not satisfied
77 fn coerce_lifetime2(a: &i32) -> &'static i32
79 <i32 as RefFoo<i32>>::ref_foo(a)
80 //~^ ERROR the requirement `for<'a> 'a : ` is not satisfied
83 fn coerce_lifetime3(a: &u64) -> &'static u64
85 <u64 as RefFoo<u64>>::ref_foo(a)
86 //~^ ERROR type mismatch resolving `for<'a> <&'a u64 as Mirror>::Image == &u64`
89 fn coerce_lifetime4(a: &i64) -> &'static i64
91 <i64 as RefFoo<i64>>::ref_foo(a)
92 //~^ ERROR type mismatch resolving `for<'a> <&'a i64 as Mirror>::Image == &i64`