]> git.proxmox.com Git - rustc.git/blob - src/test/ui/nll/ty-outlives/issue-53789-2.rs
New upstream version 1.41.1+dfsg1
[rustc.git] / src / test / ui / nll / ty-outlives / issue-53789-2.rs
1 // Regression test for #53789.
2 //
3 // check-pass
4
5 use std::collections::BTreeMap;
6 use std::ops::Range;
7 use std::cmp::Ord;
8
9 macro_rules! valuetree {
10 () => {
11 type ValueTree =
12 <Self::Strategy as $crate::Strategy>::Value;
13 };
14 }
15
16 macro_rules! product_unpack {
17 ($factor: pat) => {
18 ($factor,)
19 };
20 ($($factor: pat),*) => {
21 ( $( $factor ),* )
22 };
23 ($($factor: pat),*,) => {
24 ( $( $factor ),* )
25 };
26 }
27
28 macro_rules! product_type {
29 ($factor: ty) => {
30 ($factor,)
31 };
32 ($($factor: ty),*) => {
33 ( $( $factor, )* )
34 };
35 ($($factor: ty),*,) => {
36 ( $( $factor, )* )
37 };
38 }
39
40 macro_rules! default {
41 ($type: ty, $val: expr) => {
42 impl Default for $type {
43 fn default() -> Self { $val.into() }
44 }
45 };
46 }
47
48 // Pervasive internal sugar
49 macro_rules! mapfn {
50 ($(#[$meta:meta])* [$($vis:tt)*]
51 fn $name:ident[$($gen:tt)*]($parm:ident: $input:ty) -> $output:ty {
52 $($body:tt)*
53 }) => {
54 $(#[$meta])*
55 #[derive(Clone, Copy)]
56 $($vis)* struct $name;
57 impl $($gen)* statics::MapFn<$input> for $name {
58 type Output = $output;
59 }
60 }
61 }
62
63 macro_rules! opaque_strategy_wrapper {
64 ($(#[$smeta:meta])* pub struct $stratname:ident
65 [$($sgen:tt)*][$($swhere:tt)*]
66 ($innerstrat:ty) -> $stratvtty:ty;
67
68 $(#[$vmeta:meta])* pub struct $vtname:ident
69 [$($vgen:tt)*][$($vwhere:tt)*]
70 ($innervt:ty) -> $actualty:ty;
71 ) => {
72 $(#[$smeta])* struct $stratname $($sgen)* (std::marker::PhantomData<(K, V)>)
73 $($swhere)*;
74
75 $(#[$vmeta])* struct $vtname $($vgen)* ($innervt) $($vwhere)*;
76
77 impl $($sgen)* Strategy for $stratname $($sgen)* $($swhere)* {
78 type Value = $stratvtty;
79 }
80
81 impl $($vgen)* ValueTree for $vtname $($vgen)* $($vwhere)* {
82 type Value = $actualty;
83 }
84 }
85 }
86
87 trait ValueTree {
88 type Value;
89 }
90
91 trait Strategy {
92 type Value : ValueTree;
93 }
94
95 #[derive(Clone)]
96 struct VecStrategy<T : Strategy> {
97 element: T,
98 size: Range<usize>,
99 }
100
101 fn vec<T : Strategy>(element: T, size: Range<usize>)
102 -> VecStrategy<T> {
103 VecStrategy {
104 element: element,
105 size: size,
106 }
107 }
108
109 type ValueFor<S> = <<S as Strategy>::Value as ValueTree>::Value;
110
111 trait Arbitrary<'a>: Sized {
112 fn arbitrary_with(args: Self::Parameters) -> Self::Strategy;
113
114 type Parameters: Default;
115 type Strategy: Strategy<Value = Self::ValueTree>;
116 type ValueTree: ValueTree<Value = Self>;
117 }
118
119 type StrategyFor<A> = StrategyType<'static, A>;
120 type StrategyType<'a, A> = <A as Arbitrary<'a>>::Strategy;
121
122 //#[derive(Clone, PartialEq, Eq, Hash, Debug, From, Into)]
123 struct SizeBounds(Range<usize>);
124 default!(SizeBounds, 0..100);
125
126
127 impl From<Range<usize>> for SizeBounds {
128 fn from(high: Range<usize>) -> Self {
129 unimplemented!()
130 }
131 }
132
133 impl From<SizeBounds> for Range<usize> {
134 fn from(high: SizeBounds) -> Self {
135 unimplemented!()
136 }
137 }
138
139
140 fn any_with<'a, A: Arbitrary<'a>>(args: A::Parameters)
141 -> StrategyType<'a, A> {
142 unimplemented!()
143 }
144
145 impl<K: ValueTree, V: ValueTree> Strategy for (K, V) where
146 <K as ValueTree>::Value: Ord {
147 type Value = TupleValueTree<(K, V)>;
148 }
149
150 impl<K: ValueTree, V: ValueTree> ValueTree for TupleValueTree<(K, V)> where
151 <K as ValueTree>::Value: Ord {
152 type Value = BTreeMapValueTree<K, V>;
153 }
154
155 #[derive(Clone)]
156 struct VecValueTree<T : ValueTree> {
157 elements: Vec<T>,
158 }
159
160 #[derive(Clone, Copy)]
161 struct TupleValueTree<T> {
162 tree: T,
163 }
164
165 opaque_strategy_wrapper! {
166 #[derive(Clone)]
167 pub struct BTreeMapStrategy[<K, V>]
168 [where K : Strategy, V : Strategy, ValueFor<K> : Ord](
169 statics::Filter<statics::Map<VecStrategy<(K,V)>,
170 VecToBTreeMap>, MinSize>)
171 -> BTreeMapValueTree<K::Value, V::Value>;
172
173 #[derive(Clone)]
174 pub struct BTreeMapValueTree[<K, V>]
175 [where K : ValueTree, V : ValueTree, K::Value : Ord](
176 statics::Filter<statics::Map<VecValueTree<TupleValueTree<(K, V)>>,
177 VecToBTreeMap>, MinSize>)
178 -> BTreeMap<K::Value, V::Value>;
179 }
180
181 type RangedParams2<A, B> = product_type![SizeBounds, A, B];
182
183 impl<'a, A, B> Arbitrary<'a> for BTreeMap<A, B>
184 where
185 A: Arbitrary<'static> + Ord,
186 B: Arbitrary<'static>,
187 StrategyFor<A>: 'static,
188 StrategyFor<B>: 'static,
189 {
190 valuetree!();
191 type Parameters = RangedParams2<A::Parameters, B::Parameters>;
192 type Strategy = BTreeMapStrategy<A::Strategy, B::Strategy>;
193 fn arbitrary_with(args: Self::Parameters) -> Self::Strategy {
194 let product_unpack![range, a, b] = args;
195 btree_map(any_with::<A>(a), any_with::<B>(b), range.into())
196 }
197 }
198
199 #[derive(Clone, Copy)]
200 struct MinSize(usize);
201
202 mapfn! {
203 [] fn VecToBTreeMap[<K : Ord, V>]
204 (vec: Vec<(K, V)>) -> BTreeMap<K, V>
205 {
206 vec.into_iter().collect()
207 }
208 }
209
210 fn btree_map<K : Strategy + 'static, V : Strategy + 'static>
211 (key: K, value: V, size: Range<usize>)
212 -> BTreeMapStrategy<K, V>
213 where ValueFor<K> : Ord {
214 unimplemented!()
215 }
216
217 mod statics {
218 pub(super) trait MapFn<T> {
219 type Output;
220 }
221
222 #[derive(Clone)]
223 pub struct Filter<S, F> {
224 source: S,
225 fun: F,
226 }
227
228 impl<S, F> Filter<S, F> {
229 pub fn new(source: S, whence: String, filter: F) -> Self {
230 unimplemented!()
231 }
232 }
233
234 #[derive(Clone)]
235 pub struct Map<S, F> {
236 source: S,
237 fun: F,
238 }
239
240 impl<S, F> Map<S, F> {
241 pub fn new(source: S, fun: F) -> Self {
242 unimplemented!()
243 }
244 }
245 }
246
247 fn main() { }