|
1 | 1 | use crate::clean::auto_trait::AutoTraitFinder;
|
2 | 2 | use crate::clean::blanket_impl::BlanketImplFinder;
|
3 | 3 | use crate::clean::{
|
4 |
| - inline, Clean, Crate, ExternalCrate, FnDecl, FnRetTy, Generic, GenericArg, GenericArgs, |
5 |
| - GenericBound, Generics, GetDefId, ImportSource, Item, ItemKind, Lifetime, MacroKind, Path, |
6 |
| - PathSegment, Primitive, PrimitiveType, ResolvedPath, Type, TypeBinding, TypeKind, |
7 |
| - WherePredicate, |
| 4 | + inline, Clean, Crate, ExternalCrate, Generic, GenericArg, GenericArgs, ImportSource, Item, |
| 5 | + ItemKind, Lifetime, MacroKind, Path, PathSegment, Primitive, PrimitiveType, ResolvedPath, Type, |
| 6 | + TypeBinding, TypeKind, |
8 | 7 | };
|
9 | 8 | use crate::core::DocContext;
|
10 | 9 |
|
@@ -160,125 +159,6 @@ pub(super) fn external_path(
|
160 | 159 | }
|
161 | 160 | }
|
162 | 161 |
|
163 |
| -/// The point of this function is to replace bounds with types. |
164 |
| -/// |
165 |
| -/// i.e. `[T, U]` when you have the following bounds: `T: Display, U: Option<T>` will return |
166 |
| -/// `[Display, Option]` (we just returns the list of the types, we don't care about the |
167 |
| -/// wrapped types in here). |
168 |
| -crate fn get_real_types( |
169 |
| - generics: &Generics, |
170 |
| - arg: &Type, |
171 |
| - cx: &DocContext<'_>, |
172 |
| - recurse: i32, |
173 |
| -) -> FxHashSet<(Type, TypeKind)> { |
174 |
| - fn insert(res: &mut FxHashSet<(Type, TypeKind)>, cx: &DocContext<'_>, ty: Type) { |
175 |
| - if let Some(kind) = ty.def_id().map(|did| cx.tcx.def_kind(did).clean(cx)) { |
176 |
| - res.insert((ty, kind)); |
177 |
| - } else if ty.is_primitive() { |
178 |
| - // This is a primitive, let's store it as such. |
179 |
| - res.insert((ty, TypeKind::Primitive)); |
180 |
| - } |
181 |
| - } |
182 |
| - let mut res = FxHashSet::default(); |
183 |
| - if recurse >= 10 { |
184 |
| - // FIXME: remove this whole recurse thing when the recursion bug is fixed |
185 |
| - return res; |
186 |
| - } |
187 |
| - |
188 |
| - if arg.is_full_generic() { |
189 |
| - let arg_s = Symbol::intern(&arg.print(&cx.cache).to_string()); |
190 |
| - if let Some(where_pred) = generics.where_predicates.iter().find(|g| match g { |
191 |
| - WherePredicate::BoundPredicate { ty, .. } => ty.def_id() == arg.def_id(), |
192 |
| - _ => false, |
193 |
| - }) { |
194 |
| - let bounds = where_pred.get_bounds().unwrap_or_else(|| &[]); |
195 |
| - for bound in bounds.iter() { |
196 |
| - if let GenericBound::TraitBound(poly_trait, _) = bound { |
197 |
| - for x in poly_trait.generic_params.iter() { |
198 |
| - if !x.is_type() { |
199 |
| - continue; |
200 |
| - } |
201 |
| - if let Some(ty) = x.get_type() { |
202 |
| - let adds = get_real_types(generics, &ty, cx, recurse + 1); |
203 |
| - if !adds.is_empty() { |
204 |
| - res.extend(adds); |
205 |
| - } else if !ty.is_full_generic() { |
206 |
| - insert(&mut res, cx, ty); |
207 |
| - } |
208 |
| - } |
209 |
| - } |
210 |
| - } |
211 |
| - } |
212 |
| - } |
213 |
| - if let Some(bound) = generics.params.iter().find(|g| g.is_type() && g.name == arg_s) { |
214 |
| - for bound in bound.get_bounds().unwrap_or_else(|| &[]) { |
215 |
| - if let Some(ty) = bound.get_trait_type() { |
216 |
| - let adds = get_real_types(generics, &ty, cx, recurse + 1); |
217 |
| - if !adds.is_empty() { |
218 |
| - res.extend(adds); |
219 |
| - } else if !ty.is_full_generic() { |
220 |
| - insert(&mut res, cx, ty); |
221 |
| - } |
222 |
| - } |
223 |
| - } |
224 |
| - } |
225 |
| - } else { |
226 |
| - insert(&mut res, cx, arg.clone()); |
227 |
| - if let Some(gens) = arg.generics() { |
228 |
| - for gen in gens.iter() { |
229 |
| - if gen.is_full_generic() { |
230 |
| - let adds = get_real_types(generics, gen, cx, recurse + 1); |
231 |
| - if !adds.is_empty() { |
232 |
| - res.extend(adds); |
233 |
| - } |
234 |
| - } else { |
235 |
| - insert(&mut res, cx, gen.clone()); |
236 |
| - } |
237 |
| - } |
238 |
| - } |
239 |
| - } |
240 |
| - res |
241 |
| -} |
242 |
| - |
243 |
| -/// Return the full list of types when bounds have been resolved. |
244 |
| -/// |
245 |
| -/// i.e. `fn foo<A: Display, B: Option<A>>(x: u32, y: B)` will return |
246 |
| -/// `[u32, Display, Option]`. |
247 |
| -crate fn get_all_types( |
248 |
| - generics: &Generics, |
249 |
| - decl: &FnDecl, |
250 |
| - cx: &DocContext<'_>, |
251 |
| -) -> (Vec<(Type, TypeKind)>, Vec<(Type, TypeKind)>) { |
252 |
| - let mut all_types = FxHashSet::default(); |
253 |
| - for arg in decl.inputs.values.iter() { |
254 |
| - if arg.type_.is_self_type() { |
255 |
| - continue; |
256 |
| - } |
257 |
| - let args = get_real_types(generics, &arg.type_, cx, 0); |
258 |
| - if !args.is_empty() { |
259 |
| - all_types.extend(args); |
260 |
| - } else { |
261 |
| - if let Some(kind) = arg.type_.def_id().map(|did| cx.tcx.def_kind(did).clean(cx)) { |
262 |
| - all_types.insert((arg.type_.clone(), kind)); |
263 |
| - } |
264 |
| - } |
265 |
| - } |
266 |
| - |
267 |
| - let ret_types = match decl.output { |
268 |
| - FnRetTy::Return(ref return_type) => { |
269 |
| - let mut ret = get_real_types(generics, &return_type, cx, 0); |
270 |
| - if ret.is_empty() { |
271 |
| - if let Some(kind) = return_type.def_id().map(|did| cx.tcx.def_kind(did).clean(cx)) { |
272 |
| - ret.insert((return_type.clone(), kind)); |
273 |
| - } |
274 |
| - } |
275 |
| - ret.into_iter().collect() |
276 |
| - } |
277 |
| - _ => Vec::new(), |
278 |
| - }; |
279 |
| - (all_types.into_iter().collect(), ret_types) |
280 |
| -} |
281 |
| - |
282 | 162 | crate fn strip_type(ty: Type) -> Type {
|
283 | 163 | match ty {
|
284 | 164 | Type::ResolvedPath { path, param_names, did, is_generic } => {
|
|
0 commit comments