From ff88b59e58a03dc142e80f35f4ce6177e07ad8ba Mon Sep 17 00:00:00 2001 From: zredb Date: Mon, 10 Jan 2022 10:44:18 +0800 Subject: [PATCH] fix #90187 --- src/librustdoc/formats/cache.rs | 2 +- src/librustdoc/html/render/search_index.rs | 23 +++++++++----------- src/librustdoc/passes/collect_trait_impls.rs | 4 ++-- src/librustdoc/passes/stripper.rs | 3 ++- 4 files changed, 15 insertions(+), 17 deletions(-) diff --git a/src/librustdoc/formats/cache.rs b/src/librustdoc/formats/cache.rs index a8fef4a31780..53159709586c 100644 --- a/src/librustdoc/formats/cache.rs +++ b/src/librustdoc/formats/cache.rs @@ -303,7 +303,7 @@ impl<'a, 'tcx> DocFolder for CacheBuilder<'a, 'tcx> { desc, parent, parent_idx: None, - search_type: get_function_type_for_search(&item, self.tcx), + search_type: get_function_type_for_search(&item, self.tcx, self.cache), aliases: item.attrs.get_doc_aliases(), }); } diff --git a/src/librustdoc/html/render/search_index.rs b/src/librustdoc/html/render/search_index.rs index 87138b9571c2..0b6eeb518250 100644 --- a/src/librustdoc/html/render/search_index.rs +++ b/src/librustdoc/html/render/search_index.rs @@ -33,7 +33,7 @@ crate fn build_index<'tcx>(krate: &clean::Crate, cache: &mut Cache, tcx: TyCtxt< desc, parent: Some(did), parent_idx: None, - search_type: get_function_type_for_search(item, tcx), + search_type: get_function_type_for_search(item, tcx, &cache), aliases: item.attrs.get_doc_aliases(), }); } @@ -188,11 +188,12 @@ crate fn build_index<'tcx>(krate: &clean::Crate, cache: &mut Cache, tcx: TyCtxt< crate fn get_function_type_for_search<'tcx>( item: &clean::Item, tcx: TyCtxt<'tcx>, + cache: &Cache, ) -> Option { let (mut inputs, mut output) = match *item.kind { - clean::FunctionItem(ref f) => get_fn_inputs_and_outputs(f, tcx), - clean::MethodItem(ref m, _) => get_fn_inputs_and_outputs(m, tcx), - clean::TyMethodItem(ref m) => get_fn_inputs_and_outputs(m, tcx), + clean::FunctionItem(ref f) => get_fn_inputs_and_outputs(f, tcx, cache), + clean::MethodItem(ref m, _) => get_fn_inputs_and_outputs(m, tcx, cache), + clean::TyMethodItem(ref m) => get_fn_inputs_and_outputs(m, tcx, cache), _ => return None, }; @@ -311,7 +312,7 @@ fn add_generics_and_bounds_as_types<'tcx>( // We remove the name of the full generic because we have no use for it. index_ty.name = Some(String::new()); res.push(TypeWithKind::from((index_ty, ItemType::Generic))); - } else if let Some(kind) = ty.def_id_no_primitives().map(|did| tcx.def_kind(did).into()) { + } else if let Some(kind) = ty.def_id(cache).map(|did| tcx.def_kind(did).into()) { res.push(TypeWithKind::from((index_ty, kind))); } else if ty.is_primitive() { // This is a primitive, let's store it as such. @@ -330,9 +331,7 @@ fn add_generics_and_bounds_as_types<'tcx>( if let Type::Generic(arg_s) = *arg { // First we check if the bounds are in a `where` predicate... if let Some(where_pred) = generics.where_predicates.iter().find(|g| match g { - WherePredicate::BoundPredicate { ty, .. } => { - ty.def_id_no_primitives() == arg.def_id_no_primitives() - } + WherePredicate::BoundPredicate { ty, .. } => ty.def_id(cache) == arg.def_id(cache), _ => false, }) { let mut ty_generics = Vec::new(); @@ -397,6 +396,7 @@ fn add_generics_and_bounds_as_types<'tcx>( fn get_fn_inputs_and_outputs<'tcx>( func: &Function, tcx: TyCtxt<'tcx>, + cache: &Cache, ) -> (Vec, Vec) { let decl = &func.decl; let generics = &func.generics; @@ -411,8 +411,7 @@ fn get_fn_inputs_and_outputs<'tcx>( if !args.is_empty() { all_types.extend(args); } else { - if let Some(kind) = arg.type_.def_id_no_primitives().map(|did| tcx.def_kind(did).into()) - { + if let Some(kind) = arg.type_.def_id(cache).map(|did| tcx.def_kind(did).into()) { all_types.push(TypeWithKind::from((get_index_type(&arg.type_, vec![]), kind))); } } @@ -423,9 +422,7 @@ fn get_fn_inputs_and_outputs<'tcx>( FnRetTy::Return(ref return_type) => { add_generics_and_bounds_as_types(generics, return_type, tcx, 0, &mut ret_types); if ret_types.is_empty() { - if let Some(kind) = - return_type.def_id_no_primitives().map(|did| tcx.def_kind(did).into()) - { + if let Some(kind) = return_type.def_id(cache).map(|did| tcx.def_kind(did).into()) { ret_types.push(TypeWithKind::from((get_index_type(return_type, vec![]), kind))); } } diff --git a/src/librustdoc/passes/collect_trait_impls.rs b/src/librustdoc/passes/collect_trait_impls.rs index 66ac612ea37c..fd52d93cb382 100644 --- a/src/librustdoc/passes/collect_trait_impls.rs +++ b/src/librustdoc/passes/collect_trait_impls.rs @@ -102,7 +102,7 @@ crate fn collect_trait_impls(mut krate: Crate, cx: &mut DocContext<'_>) -> Crate } else if let Some(did) = target.def_id(&cx.cache) { cleaner.items.insert(did.into()); } - if let Some(for_did) = for_.def_id_no_primitives() { + if let Some(for_did) = for_.def_id(&cx.cache) { if type_did_to_deref_target.insert(for_did, target).is_none() { // Since only the `DefId` portion of the `Type` instances is known to be same for both the // `Deref` target type and the impl for type positions, this map of types is keyed by @@ -216,7 +216,7 @@ impl BadImplStripper { true } else if let Some(prim) = ty.primitive_type() { self.prims.contains(&prim) - } else if let Some(did) = ty.def_id_no_primitives() { + } else if let Some(did) = ty.def_id(&cx.cache) { is_deref || self.keep_impl_with_def_id(did.into()) } else { false diff --git a/src/librustdoc/passes/stripper.rs b/src/librustdoc/passes/stripper.rs index 7b07974ae01c..ed0b2c0a5d72 100644 --- a/src/librustdoc/passes/stripper.rs +++ b/src/librustdoc/passes/stripper.rs @@ -118,6 +118,7 @@ impl<'a> DocFolder for Stripper<'a> { /// This stripper discards all impls which reference stripped items crate struct ImplStripper<'a> { crate retained: &'a ItemIdSet, + crate cache: &'a Cache, } impl<'a> DocFolder for ImplStripper<'a> { @@ -127,7 +128,7 @@ impl<'a> DocFolder for ImplStripper<'a> { if imp.trait_.is_none() && imp.items.is_empty() { return None; } - if let Some(did) = imp.for_.def_id_no_primitives() { + if let Some(did) = imp.for_.def_id(self.cache) { if did.is_local() && !imp.for_.is_assoc_ty() && !self.retained.contains(&did.into()) { debug!("ImplStripper: impl item for stripped type; removing");