1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
//! It turns out that `fn(Input<'_>) -> Output<'_>`, when you think about it,
//! is also:
//! - a real Rust type;
//! - which conceptually expresses the `For!(Output<'_>)` property:
//!
//! That is, one can feed a `'_` to it by feeding `Input<'_>` to the `FnOnce`
//! trait, and then querying the resulting `Output` type.
//!
//! Sadly, this only seems to work when using, _verbatim_, the real `FnOnce`
//! trait.
//!
//! That is, no amount of stable-polyfill _à la_:
//!
//! ```rust ,compile_fail
//! use ::higher_kinded_types::{*, advanced::WithLifetime};
//!
//! type For<'lt> = &'lt ();
//!
//! /// coherence wrappers
//! struct A<F>(F);
//! struct B<F>(F);
//!
//! impl<'lt, F, R> WithLifetime<'lt> for A<F>
//! where
//! F : FnOnce(For<'lt>) -> R,
//! F : Send + Sync + Unpin,
//! {
//! type Of = R;
//! }
//!
//! impl<'lt, F> WithLifetime<'lt> for B<F>
//! where
//! F : MyFnOnce<For<'lt>>,
//! F : Send + Sync + Unpin,
//! {
//! type Of = F::Ret;
//! }
//!
//! trait MyFnOnce<A>
//! where
//! Self : FnOnce(A) -> Self::Ret,
//! {
//! type Ret;
//! }
//! impl<F, A, R> MyFnOnce<A> for F
//! where
//! Self : FnOnce(A) -> R,
//! {
//! type Ret = R;
//! }
//!
//! fn test<Ret : ForLt>(_: impl FnOnce(&str) -> Ret::Of<'_>)
//! {}
//!
//! /// `For!(&str)`.
//! type StrRef = fn(For<'_>) -> &str;
//!
//! test::<A<StrRef>>(|s| s);
//! test::<B<StrRef>>(|s| s);
//! ```
//!
//! is able to make it work.
//!
/** They yield:
error: implementation of `WithLifetime` is not general enough
--> src/fn_traits.rs:59:1
|
48 | test::<A<StrRef>>(|s| s);
| ^^^^^^^^^^^^^^^^^ implementation of `WithLifetime` is not general enough
|
= note: `A<for<'r> fn(&'r ()) -> &'r str>` must implement `WithLifetime<'0>`, for any lifetime `'0`...
= note: ...but it actually implements `WithLifetime<'1>`, for some specific lifetime `'1`
error: implementation of `WithLifetime` is not general enough
--> src/fn_traits.rs:60:1
|
49 | test::<B<StrRef>>(|s| s);
| ^^^^^^^^^^^^^^^^^ implementation of `WithLifetime` is not general enough
|
= note: `B<for<'r> fn(&'r ()) -> &'r str>` must implement `WithLifetime<'0>`, for any lifetime `'0`...
= note: ...but it actually implements `WithLifetime<'1>`, for some specific lifetime `'1`
**/
use crateWithLifetime;
pub