Skip to content

Commit fa5b9f0

Browse files
committed
rustdoc-search: stress test for associated types
1 parent bcc3f19 commit fa5b9f0

File tree

3 files changed

+259
-0
lines changed

3 files changed

+259
-0
lines changed
+245
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,245 @@
1+
#![feature(associated_type_defaults)]
2+
3+
use std::cmp::Ord;
4+
use std::fmt::{Debug, Formatter};
5+
use std::hash::Hash;
6+
use std::ops::ControlFlow;
7+
8+
pub trait Interner: Sized {
9+
type DefId: Copy + Debug + Hash + Ord;
10+
type AdtDef: Copy + Debug + Hash + Ord;
11+
type GenericArgs: Copy
12+
+ DebugWithInfcx<Self>
13+
+ Hash
14+
+ Ord
15+
+ IntoIterator<Item = Self::GenericArg>;
16+
type GenericArg: Copy + DebugWithInfcx<Self> + Hash + Ord;
17+
type Term: Copy + Debug + Hash + Ord;
18+
type Binder<T: TypeVisitable<Self>>: BoundVars<Self> + TypeSuperVisitable<Self>;
19+
type BoundVars: IntoIterator<Item = Self::BoundVar>;
20+
type BoundVar;
21+
type CanonicalVars: Copy + Debug + Hash + Eq + IntoIterator<Item = CanonicalVarInfo<Self>>;
22+
type Ty: Copy
23+
+ DebugWithInfcx<Self>
24+
+ Hash
25+
+ Ord
26+
+ Into<Self::GenericArg>
27+
+ IntoKind<Kind = TyKind<Self>>
28+
+ TypeSuperVisitable<Self>
29+
+ Flags
30+
+ Ty<Self>;
31+
type Tys: Copy + Debug + Hash + Ord + IntoIterator<Item = Self::Ty>;
32+
type AliasTy: Copy + DebugWithInfcx<Self> + Hash + Ord;
33+
type ParamTy: Copy + Debug + Hash + Ord;
34+
type BoundTy: Copy + Debug + Hash + Ord;
35+
type PlaceholderTy: Copy + Debug + Hash + Ord + PlaceholderLike;
36+
type ErrorGuaranteed: Copy + Debug + Hash + Ord;
37+
type BoundExistentialPredicates: Copy + DebugWithInfcx<Self> + Hash + Ord;
38+
type PolyFnSig: Copy + DebugWithInfcx<Self> + Hash + Ord;
39+
type AllocId: Copy + Debug + Hash + Ord;
40+
type Const: Copy
41+
+ DebugWithInfcx<Self>
42+
+ Hash
43+
+ Ord
44+
+ Into<Self::GenericArg>
45+
+ IntoKind<Kind = ConstKind<Self>>
46+
+ ConstTy<Self>
47+
+ TypeSuperVisitable<Self>
48+
+ Flags
49+
+ Const<Self>;
50+
type AliasConst: Copy + DebugWithInfcx<Self> + Hash + Ord;
51+
type PlaceholderConst: Copy + Debug + Hash + Ord + PlaceholderLike;
52+
type ParamConst: Copy + Debug + Hash + Ord;
53+
type BoundConst: Copy + Debug + Hash + Ord;
54+
type ValueConst: Copy + Debug + Hash + Ord;
55+
type ExprConst: Copy + DebugWithInfcx<Self> + Hash + Ord;
56+
type Region: Copy
57+
+ DebugWithInfcx<Self>
58+
+ Hash
59+
+ Ord
60+
+ Into<Self::GenericArg>
61+
+ IntoKind<Kind = RegionKind<Self>>
62+
+ Flags
63+
+ Region<Self>;
64+
type EarlyParamRegion: Copy + Debug + Hash + Ord;
65+
type LateParamRegion: Copy + Debug + Hash + Ord;
66+
type BoundRegion: Copy + Debug + Hash + Ord;
67+
type InferRegion: Copy + DebugWithInfcx<Self> + Hash + Ord;
68+
type PlaceholderRegion: Copy + Debug + Hash + Ord + PlaceholderLike;
69+
type Predicate: Copy + Debug + Hash + Eq + TypeSuperVisitable<Self> + Flags;
70+
type TraitPredicate: Copy + Debug + Hash + Eq;
71+
type RegionOutlivesPredicate: Copy + Debug + Hash + Eq;
72+
type TypeOutlivesPredicate: Copy + Debug + Hash + Eq;
73+
type ProjectionPredicate: Copy + Debug + Hash + Eq;
74+
type NormalizesTo: Copy + Debug + Hash + Eq;
75+
type SubtypePredicate: Copy + Debug + Hash + Eq;
76+
type CoercePredicate: Copy + Debug + Hash + Eq;
77+
type ClosureKind: Copy + Debug + Hash + Eq;
78+
79+
// Required method
80+
fn mk_canonical_var_infos(
81+
self,
82+
infos: &[CanonicalVarInfo<Self>]
83+
) -> Self::CanonicalVars;
84+
}
85+
86+
pub trait DebugWithInfcx<I: Interner>: Debug {
87+
// Required method
88+
fn fmt<Infcx: InferCtxtLike<Interner = I>>(
89+
this: WithInfcx<'_, Infcx, &Self>,
90+
f: &mut Formatter<'_>
91+
) -> std::fmt::Result;
92+
}
93+
94+
pub trait TypeVisitable<I: Interner>: Debug + Clone {
95+
// Required method
96+
fn visit_with<V: TypeVisitor<I>>(&self, visitor: &mut V) -> V::Result;
97+
}
98+
99+
pub trait BoundVars<I: Interner> {
100+
// Required methods
101+
fn bound_vars(&self) -> I::BoundVars;
102+
fn has_no_bound_vars(&self) -> bool;
103+
}
104+
105+
pub trait TypeSuperVisitable<I: Interner>: TypeVisitable<I> {
106+
// Required method
107+
fn super_visit_with<V: TypeVisitor<I>>(&self, visitor: &mut V) -> V::Result;
108+
}
109+
110+
pub struct CanonicalVarInfo<I: Interner> {
111+
pub kind: CanonicalVarKind<I>,
112+
}
113+
114+
pub struct CanonicalVarKind<I>(std::marker::PhantomData<I>);
115+
116+
pub struct TyKind<I>(std::marker::PhantomData<I>);
117+
118+
pub trait IntoKind {
119+
type Kind;
120+
121+
// Required method
122+
fn kind(self) -> Self::Kind;
123+
}
124+
pub trait Flags {
125+
// Required methods
126+
fn flags(&self) -> TypeFlags;
127+
fn outer_exclusive_binder(&self) -> DebruijnIndex;
128+
}
129+
pub struct TypeFlags;
130+
131+
pub trait Ty<I: Interner<Ty = Self>> {
132+
// Required method
133+
fn new_anon_bound(
134+
interner: I,
135+
debruijn: DebruijnIndex,
136+
var: BoundVar
137+
) -> Self;
138+
}
139+
140+
pub trait PlaceholderLike {
141+
// Required methods
142+
fn universe(self) -> UniverseIndex;
143+
fn var(self) -> BoundVar;
144+
fn with_updated_universe(self, ui: UniverseIndex) -> Self;
145+
fn new(ui: UniverseIndex, var: BoundVar) -> Self;
146+
}
147+
148+
pub struct UniverseIndex;
149+
150+
pub struct BoundVar;
151+
152+
pub struct ConstKind<I>(std::marker::PhantomData<I>);
153+
pub trait Const<I: Interner<Const = Self>> {
154+
// Required method
155+
fn new_anon_bound(
156+
interner: I,
157+
debruijn: DebruijnIndex,
158+
var: BoundVar,
159+
ty: I::Ty
160+
) -> Self;
161+
}
162+
163+
pub trait ConstTy<I: Interner> {
164+
// Required method
165+
fn ty(self) -> I::Ty;
166+
}
167+
168+
pub struct DebruijnIndex;
169+
170+
pub struct RegionKind<I>(std::marker::PhantomData<I>);
171+
pub trait Region<I: Interner<Region = Self>> {
172+
// Required method
173+
fn new_anon_bound(
174+
interner: I,
175+
debruijn: DebruijnIndex,
176+
var: BoundVar
177+
) -> Self;
178+
}
179+
180+
pub trait TypeVisitor<I: Interner>: Sized {
181+
type Result: VisitorResult = ();
182+
183+
// Provided methods
184+
fn visit_binder<T: TypeVisitable<I>>(
185+
&mut self,
186+
t: &I::Binder<T>
187+
) -> Self::Result { unimplemented!() }
188+
fn visit_ty(&mut self, t: I::Ty) -> Self::Result { unimplemented!() }
189+
fn visit_region(&mut self, _r: I::Region) -> Self::Result { unimplemented!() }
190+
fn visit_const(&mut self, c: I::Const) -> Self::Result { unimplemented!() }
191+
fn visit_predicate(&mut self, p: I::Predicate) -> Self::Result { unimplemented!() }
192+
}
193+
194+
pub trait VisitorResult {
195+
type Residual;
196+
197+
// Required methods
198+
fn output() -> Self;
199+
fn from_residual(residual: Self::Residual) -> Self;
200+
fn from_branch(b: ControlFlow<Self::Residual>) -> Self;
201+
fn branch(self) -> ControlFlow<Self::Residual>;
202+
}
203+
204+
impl VisitorResult for () {
205+
type Residual = ();
206+
fn output() -> Self {}
207+
fn from_residual(_: Self::Residual) -> Self {}
208+
fn from_branch(_: ControlFlow<Self::Residual>) -> Self {}
209+
fn branch(self) -> ControlFlow<Self::Residual> { ControlFlow::Continue(()) }
210+
}
211+
212+
pub struct WithInfcx<'a, Infcx: InferCtxtLike, T> {
213+
pub data: T,
214+
pub infcx: &'a Infcx,
215+
}
216+
217+
pub trait InferCtxtLike {
218+
type Interner: Interner;
219+
220+
// Required methods
221+
fn interner(&self) -> Self::Interner;
222+
fn universe_of_ty(&self, ty: TyVid) -> Option<UniverseIndex>;
223+
fn root_ty_var(&self, vid: TyVid) -> TyVid;
224+
fn probe_ty_var(
225+
&self,
226+
vid: TyVid
227+
) -> Option<<Self::Interner as Interner>::Ty>;
228+
fn universe_of_lt(
229+
&self,
230+
lt: <Self::Interner as Interner>::InferRegion
231+
) -> Option<UniverseIndex>;
232+
fn opportunistic_resolve_lt_var(
233+
&self,
234+
vid: <Self::Interner as Interner>::InferRegion
235+
) -> Option<<Self::Interner as Interner>::Region>;
236+
fn universe_of_ct(&self, ct: ConstVid) -> Option<UniverseIndex>;
237+
fn root_ct_var(&self, vid: ConstVid) -> ConstVid;
238+
fn probe_ct_var(
239+
&self,
240+
vid: ConstVid
241+
) -> Option<<Self::Interner as Interner>::Const>;
242+
}
243+
244+
pub struct TyVid;
245+
pub struct ConstVid;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// https://github.com/rust-lang/rust/pull/122247
2+
// exact-check
3+
4+
const EXPECTED = {
5+
'query': 'canonicalvarinfo, intoiterator -> intoiterator',
6+
'others': [
7+
{ 'path': 'looks_like_rustc_interner::Interner', 'name': 'mk_canonical_var_infos' },
8+
],
9+
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
//@ aux-crate:interner=interner.rs
2+
// https://github.com/rust-lang/rust/pull/122247
3+
extern crate interner;
4+
#[doc(inline)]
5+
pub use interner::*;

0 commit comments

Comments
 (0)