]>
git.proxmox.com Git - rustc.git/blob - src/test/ui/nll/ty-outlives/issue-53789-2.rs
1 // Regression test for #53789.
5 use std
::collections
::BTreeMap
;
9 macro_rules
! valuetree
{
12 <Self::Strategy
as $
crate::Strategy
>::Value
;
16 macro_rules
! product_unpack
{
20 ($
($factor
: pat
),*) => {
23 ($
($factor
: pat
),*,) => {
28 macro_rules
! product_type
{
32 ($
($factor
: ty
),*) => {
35 ($
($factor
: ty
),*,) => {
40 macro_rules
! default {
41 ($
type: ty
, $val
: expr
) => {
42 impl Default
for $
type {
43 fn default() -> Self { $val.into() }
48 // Pervasive internal sugar
50 ($
(#[$meta:meta])* [$($vis:tt)*]
51 fn $name
:ident
[$
($gen
:tt
)*]($parm
:ident
: $input
:ty
) -> $output
:ty
{
55 #[derive(Clone, Copy)]
56 $
($vis
)* struct $name
;
57 impl $
($gen
)* statics
::MapFn
<$input
> for $name
{
58 type Output
= $output
;
63 macro_rules
! opaque_strategy_wrapper
{
64 ($
(#[$smeta:meta])* pub struct $stratname:ident
65 [$
($sgen
:tt
)*][$
($swhere
:tt
)*]
66 ($innerstrat
:ty
) -> $stratvtty
:ty
;
68 $
(#[$vmeta:meta])* pub struct $vtname:ident
69 [$
($vgen
:tt
)*][$
($vwhere
:tt
)*]
70 ($innervt
:ty
) -> $actualty
:ty
;
72 $
(#[$smeta])* struct $stratname $($sgen)* (std::marker::PhantomData<(K, V)>)
75 $
(#[$vmeta])* struct $vtname $($vgen)* ($innervt) $($vwhere)*;
77 impl $
($sgen
)* Strategy
for $stratname $
($sgen
)* $
($swhere
)* {
78 type Value
= $stratvtty
;
81 impl $
($vgen
)* ValueTree
for $vtname $
($vgen
)* $
($vwhere
)* {
82 type Value
= $actualty
;
92 type Value
: ValueTree
;
96 struct VecStrategy
<T
: Strategy
> {
101 fn vec
<T
: Strategy
>(element
: T
, size
: Range
<usize>)
109 type ValueFor
<S
> = <<S
as Strategy
>::Value
as ValueTree
>::Value
;
111 trait Arbitrary
<'a
>: Sized
{
112 fn arbitrary_with(args
: Self::Parameters
) -> Self::Strategy
;
114 type Parameters
: Default
;
115 type Strategy
: Strategy
<Value
= Self::ValueTree
>;
116 type ValueTree
: ValueTree
<Value
= Self>;
119 type StrategyFor
<A
> = StrategyType
<'
static, A
>;
120 type StrategyType
<'a
, A
> = <A
as Arbitrary
<'a
>>::Strategy
;
122 //#[derive(Clone, PartialEq, Eq, Hash, Debug, From, Into)]
123 struct SizeBounds(Range
<usize>);
124 default!(SizeBounds
, 0..100);
127 impl From
<Range
<usize>> for SizeBounds
{
128 fn from(high
: Range
<usize>) -> Self {
133 impl From
<SizeBounds
> for Range
<usize> {
134 fn from(high
: SizeBounds
) -> Self {
140 fn any_with
<'a
, A
: Arbitrary
<'a
>>(args
: A
::Parameters
)
141 -> StrategyType
<'a
, A
> {
145 impl<K
: ValueTree
, V
: ValueTree
> Strategy
for (K
, V
) where
146 <K
as ValueTree
>::Value
: Ord
{
147 type Value
= TupleValueTree
<(K
, V
)>;
150 impl<K
: ValueTree
, V
: ValueTree
> ValueTree
for TupleValueTree
<(K
, V
)> where
151 <K
as ValueTree
>::Value
: Ord
{
152 type Value
= BTreeMapValueTree
<K
, V
>;
156 struct VecValueTree
<T
: ValueTree
> {
160 #[derive(Clone, Copy)]
161 struct TupleValueTree
<T
> {
165 opaque_strategy_wrapper
! {
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
>;
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
>;
181 type RangedParams2
<A
, B
> = product_type
![SizeBounds
, A
, B
];
183 impl<'a
, A
, B
> Arbitrary
<'a
> for BTreeMap
<A
, B
>
185 A
: Arbitrary
<'
static> + Ord
,
186 B
: Arbitrary
<'
static>,
187 StrategyFor
<A
>: '
static,
188 StrategyFor
<B
>: '
static,
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())
199 #[derive(Clone, Copy)]
200 struct MinSize(usize);
203 [] fn VecToBTreeMap
[<K
: Ord
, V
>]
204 (vec
: Vec
<(K
, V
)>) -> BTreeMap
<K
, V
>
206 vec
.into_iter().collect()
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
{
218 pub(super) trait MapFn
<T
> {
223 pub struct Filter
<S
, F
> {
228 impl<S
, F
> Filter
<S
, F
> {
229 pub fn new(source
: S
, whence
: String
, filter
: F
) -> Self {
235 pub struct Map
<S
, F
> {
240 impl<S
, F
> Map
<S
, F
> {
241 pub fn new(source
: S
, fun
: F
) -> Self {