diff options
Diffstat (limited to 'src/librustdoc/clean/utils.rs')
| -rw-r--r-- | src/librustdoc/clean/utils.rs | 126 |
1 files changed, 3 insertions, 123 deletions
diff --git a/src/librustdoc/clean/utils.rs b/src/librustdoc/clean/utils.rs index e380d4672d0..2c829c49953 100644 --- a/src/librustdoc/clean/utils.rs +++ b/src/librustdoc/clean/utils.rs @@ -1,10 +1,9 @@ use crate::clean::auto_trait::AutoTraitFinder; use crate::clean::blanket_impl::BlanketImplFinder; use crate::clean::{ - inline, Clean, Crate, ExternalCrate, FnDecl, FnRetTy, Generic, GenericArg, GenericArgs, - GenericBound, Generics, GetDefId, ImportSource, Item, ItemKind, Lifetime, MacroKind, Path, - PathSegment, Primitive, PrimitiveType, ResolvedPath, Type, TypeBinding, TypeKind, - WherePredicate, + inline, Clean, Crate, ExternalCrate, Generic, GenericArg, GenericArgs, ImportSource, Item, + ItemKind, Lifetime, MacroKind, Path, PathSegment, Primitive, PrimitiveType, ResolvedPath, Type, + TypeBinding, TypeKind, }; use crate::core::DocContext; @@ -160,125 +159,6 @@ pub(super) fn external_path( } } -/// The point of this function is to replace bounds with types. -/// -/// i.e. `[T, U]` when you have the following bounds: `T: Display, U: Option<T>` will return -/// `[Display, Option]` (we just returns the list of the types, we don't care about the -/// wrapped types in here). -crate fn get_real_types( - generics: &Generics, - arg: &Type, - cx: &DocContext<'_>, - recurse: i32, -) -> FxHashSet<(Type, TypeKind)> { - fn insert(res: &mut FxHashSet<(Type, TypeKind)>, cx: &DocContext<'_>, ty: Type) { - if let Some(kind) = ty.def_id().map(|did| cx.tcx.def_kind(did).clean(cx)) { - res.insert((ty, kind)); - } else if ty.is_primitive() { - // This is a primitive, let's store it as such. - res.insert((ty, TypeKind::Primitive)); - } - } - let mut res = FxHashSet::default(); - if recurse >= 10 { - // FIXME: remove this whole recurse thing when the recursion bug is fixed - return res; - } - - if arg.is_full_generic() { - let arg_s = Symbol::intern(&arg.print(&cx.cache).to_string()); - if let Some(where_pred) = generics.where_predicates.iter().find(|g| match g { - WherePredicate::BoundPredicate { ty, .. } => ty.def_id() == arg.def_id(), - _ => false, - }) { - let bounds = where_pred.get_bounds().unwrap_or_else(|| &[]); - for bound in bounds.iter() { - if let GenericBound::TraitBound(poly_trait, _) = bound { - for x in poly_trait.generic_params.iter() { - if !x.is_type() { - continue; - } - if let Some(ty) = x.get_type() { - let adds = get_real_types(generics, &ty, cx, recurse + 1); - if !adds.is_empty() { - res.extend(adds); - } else if !ty.is_full_generic() { - insert(&mut res, cx, ty); - } - } - } - } - } - } - if let Some(bound) = generics.params.iter().find(|g| g.is_type() && g.name == arg_s) { - for bound in bound.get_bounds().unwrap_or_else(|| &[]) { - if let Some(ty) = bound.get_trait_type() { - let adds = get_real_types(generics, &ty, cx, recurse + 1); - if !adds.is_empty() { - res.extend(adds); - } else if !ty.is_full_generic() { - insert(&mut res, cx, ty); - } - } - } - } - } else { - insert(&mut res, cx, arg.clone()); - if let Some(gens) = arg.generics() { - for gen in gens.iter() { - if gen.is_full_generic() { - let adds = get_real_types(generics, gen, cx, recurse + 1); - if !adds.is_empty() { - res.extend(adds); - } - } else { - insert(&mut res, cx, gen.clone()); - } - } - } - } - res -} - -/// Return the full list of types when bounds have been resolved. -/// -/// i.e. `fn foo<A: Display, B: Option<A>>(x: u32, y: B)` will return -/// `[u32, Display, Option]`. -crate fn get_all_types( - generics: &Generics, - decl: &FnDecl, - cx: &DocContext<'_>, -) -> (Vec<(Type, TypeKind)>, Vec<(Type, TypeKind)>) { - let mut all_types = FxHashSet::default(); - for arg in decl.inputs.values.iter() { - if arg.type_.is_self_type() { - continue; - } - let args = get_real_types(generics, &arg.type_, cx, 0); - if !args.is_empty() { - all_types.extend(args); - } else { - if let Some(kind) = arg.type_.def_id().map(|did| cx.tcx.def_kind(did).clean(cx)) { - all_types.insert((arg.type_.clone(), kind)); - } - } - } - - let ret_types = match decl.output { - FnRetTy::Return(ref return_type) => { - let mut ret = get_real_types(generics, &return_type, cx, 0); - if ret.is_empty() { - if let Some(kind) = return_type.def_id().map(|did| cx.tcx.def_kind(did).clean(cx)) { - ret.insert((return_type.clone(), kind)); - } - } - ret.into_iter().collect() - } - _ => Vec::new(), - }; - (all_types.into_iter().collect(), ret_types) -} - crate fn strip_type(ty: Type) -> Type { match ty { Type::ResolvedPath { path, param_names, did, is_generic } => { |
