Auto merge of #90385 - mfrw:mfrw/librustdoc, r=GuillaumeGomez
rustdoc: use Type::def_id() instead of Type::def_id_no_primitives() For: #90187 r? `@jyn514`
This commit is contained in:
commit
b416e3892d
4 changed files with 29 additions and 17 deletions
|
@ -303,7 +303,7 @@ impl<'a, 'tcx> DocFolder for CacheBuilder<'a, 'tcx> {
|
||||||
desc,
|
desc,
|
||||||
parent,
|
parent,
|
||||||
parent_idx: None,
|
parent_idx: None,
|
||||||
search_type: get_index_search_type(&item, self.tcx),
|
search_type: get_index_search_type(&item, self.tcx, self.cache),
|
||||||
aliases: item.attrs.get_doc_aliases(),
|
aliases: item.attrs.get_doc_aliases(),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -42,7 +42,7 @@ crate fn build_index<'tcx>(krate: &clean::Crate, cache: &mut Cache, tcx: TyCtxt<
|
||||||
desc,
|
desc,
|
||||||
parent: Some(did),
|
parent: Some(did),
|
||||||
parent_idx: None,
|
parent_idx: None,
|
||||||
search_type: get_index_search_type(item, tcx),
|
search_type: get_index_search_type(item, tcx, cache),
|
||||||
aliases: item.attrs.get_doc_aliases(),
|
aliases: item.attrs.get_doc_aliases(),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -194,11 +194,12 @@ crate fn build_index<'tcx>(krate: &clean::Crate, cache: &mut Cache, tcx: TyCtxt<
|
||||||
crate fn get_index_search_type<'tcx>(
|
crate fn get_index_search_type<'tcx>(
|
||||||
item: &clean::Item,
|
item: &clean::Item,
|
||||||
tcx: TyCtxt<'tcx>,
|
tcx: TyCtxt<'tcx>,
|
||||||
|
cache: &Cache,
|
||||||
) -> Option<IndexItemFunctionType> {
|
) -> Option<IndexItemFunctionType> {
|
||||||
let (mut inputs, mut output) = match *item.kind {
|
let (mut inputs, mut output) = match *item.kind {
|
||||||
clean::FunctionItem(ref f) => get_all_types(&f.generics, &f.decl, tcx),
|
clean::FunctionItem(ref f) => get_all_types(&f.generics, &f.decl, tcx, cache),
|
||||||
clean::MethodItem(ref m, _) => get_all_types(&m.generics, &m.decl, tcx),
|
clean::MethodItem(ref m, _) => get_all_types(&m.generics, &m.decl, tcx, cache),
|
||||||
clean::TyMethodItem(ref m) => get_all_types(&m.generics, &m.decl, tcx),
|
clean::TyMethodItem(ref m) => get_all_types(&m.generics, &m.decl, tcx, cache),
|
||||||
_ => return None,
|
_ => return None,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -254,12 +255,14 @@ crate fn get_real_types<'tcx>(
|
||||||
tcx: TyCtxt<'tcx>,
|
tcx: TyCtxt<'tcx>,
|
||||||
recurse: usize,
|
recurse: usize,
|
||||||
res: &mut Vec<TypeWithKind>,
|
res: &mut Vec<TypeWithKind>,
|
||||||
|
cache: &Cache,
|
||||||
) {
|
) {
|
||||||
fn insert_ty(
|
fn insert_ty(
|
||||||
res: &mut Vec<TypeWithKind>,
|
res: &mut Vec<TypeWithKind>,
|
||||||
tcx: TyCtxt<'_>,
|
tcx: TyCtxt<'_>,
|
||||||
ty: Type,
|
ty: Type,
|
||||||
mut generics: Vec<TypeWithKind>,
|
mut generics: Vec<TypeWithKind>,
|
||||||
|
_cache: &Cache,
|
||||||
) {
|
) {
|
||||||
let is_full_generic = ty.is_full_generic();
|
let is_full_generic = ty.is_full_generic();
|
||||||
|
|
||||||
|
@ -350,12 +353,19 @@ crate fn get_real_types<'tcx>(
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if let Some(ty) = x.get_type() {
|
if let Some(ty) = x.get_type() {
|
||||||
get_real_types(generics, &ty, tcx, recurse + 1, &mut ty_generics);
|
get_real_types(
|
||||||
|
generics,
|
||||||
|
&ty,
|
||||||
|
tcx,
|
||||||
|
recurse + 1,
|
||||||
|
&mut ty_generics,
|
||||||
|
cache,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
insert_ty(res, tcx, arg.clone(), ty_generics);
|
insert_ty(res, tcx, arg.clone(), ty_generics, cache);
|
||||||
}
|
}
|
||||||
// Otherwise we check if the trait bounds are "inlined" like `T: Option<u32>`...
|
// Otherwise we check if the trait bounds are "inlined" like `T: Option<u32>`...
|
||||||
if let Some(bound) = generics.params.iter().find(|g| g.is_type() && g.name == arg_s) {
|
if let Some(bound) = generics.params.iter().find(|g| g.is_type() && g.name == arg_s) {
|
||||||
|
@ -363,10 +373,10 @@ crate fn get_real_types<'tcx>(
|
||||||
for bound in bound.get_bounds().unwrap_or(&[]) {
|
for bound in bound.get_bounds().unwrap_or(&[]) {
|
||||||
if let Some(path) = bound.get_trait_path() {
|
if let Some(path) = bound.get_trait_path() {
|
||||||
let ty = Type::ResolvedPath { did: path.def_id(), path };
|
let ty = Type::ResolvedPath { did: path.def_id(), path };
|
||||||
get_real_types(generics, &ty, tcx, recurse + 1, &mut ty_generics);
|
get_real_types(generics, &ty, tcx, recurse + 1, &mut ty_generics, cache);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
insert_ty(res, tcx, arg.clone(), ty_generics);
|
insert_ty(res, tcx, arg.clone(), ty_generics, cache);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// This is not a type parameter. So for example if we have `T, U: Option<T>`, and we're
|
// This is not a type parameter. So for example if we have `T, U: Option<T>`, and we're
|
||||||
|
@ -377,10 +387,10 @@ crate fn get_real_types<'tcx>(
|
||||||
let mut ty_generics = Vec::new();
|
let mut ty_generics = Vec::new();
|
||||||
if let Some(arg_generics) = arg.generics() {
|
if let Some(arg_generics) = arg.generics() {
|
||||||
for gen in arg_generics.iter() {
|
for gen in arg_generics.iter() {
|
||||||
get_real_types(generics, gen, tcx, recurse + 1, &mut ty_generics);
|
get_real_types(generics, gen, tcx, recurse + 1, &mut ty_generics, cache);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
insert_ty(res, tcx, arg.clone(), ty_generics);
|
insert_ty(res, tcx, arg.clone(), ty_generics, cache);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -392,6 +402,7 @@ crate fn get_all_types<'tcx>(
|
||||||
generics: &Generics,
|
generics: &Generics,
|
||||||
decl: &FnDecl,
|
decl: &FnDecl,
|
||||||
tcx: TyCtxt<'tcx>,
|
tcx: TyCtxt<'tcx>,
|
||||||
|
cache: &Cache,
|
||||||
) -> (Vec<TypeWithKind>, Vec<TypeWithKind>) {
|
) -> (Vec<TypeWithKind>, Vec<TypeWithKind>) {
|
||||||
let mut all_types = Vec::new();
|
let mut all_types = Vec::new();
|
||||||
for arg in decl.inputs.values.iter() {
|
for arg in decl.inputs.values.iter() {
|
||||||
|
@ -401,7 +412,7 @@ crate fn get_all_types<'tcx>(
|
||||||
// FIXME: performance wise, it'd be much better to move `args` declaration outside of the
|
// FIXME: performance wise, it'd be much better to move `args` declaration outside of the
|
||||||
// loop and replace this line with `args.clear()`.
|
// loop and replace this line with `args.clear()`.
|
||||||
let mut args = Vec::new();
|
let mut args = Vec::new();
|
||||||
get_real_types(generics, &arg.type_, tcx, 0, &mut args);
|
get_real_types(generics, &arg.type_, tcx, 0, &mut args, cache);
|
||||||
if !args.is_empty() {
|
if !args.is_empty() {
|
||||||
// FIXME: once back to performance improvements, replace this line with:
|
// FIXME: once back to performance improvements, replace this line with:
|
||||||
// `all_types.extend(args.drain(..));`.
|
// `all_types.extend(args.drain(..));`.
|
||||||
|
@ -417,7 +428,7 @@ crate fn get_all_types<'tcx>(
|
||||||
let mut ret_types = Vec::new();
|
let mut ret_types = Vec::new();
|
||||||
match decl.output {
|
match decl.output {
|
||||||
FnRetTy::Return(ref return_type) => {
|
FnRetTy::Return(ref return_type) => {
|
||||||
get_real_types(generics, return_type, tcx, 0, &mut ret_types);
|
get_real_types(generics, return_type, tcx, 0, &mut ret_types, cache);
|
||||||
if ret_types.is_empty() {
|
if ret_types.is_empty() {
|
||||||
if let Some(kind) =
|
if let Some(kind) =
|
||||||
return_type.def_id_no_primitives().map(|did| tcx.def_kind(did).into())
|
return_type.def_id_no_primitives().map(|did| tcx.def_kind(did).into())
|
||||||
|
|
|
@ -2166,7 +2166,7 @@ fn sidebar_deref_methods(
|
||||||
}
|
}
|
||||||
|
|
||||||
// Recurse into any further impls that might exist for `target`
|
// Recurse into any further impls that might exist for `target`
|
||||||
if let Some(target_did) = target.def_id_no_primitives() {
|
if let Some(target_did) = target.def_id(c) {
|
||||||
if let Some(target_impls) = c.impls.get(&target_did) {
|
if let Some(target_impls) = c.impls.get(&target_did) {
|
||||||
if let Some(target_deref_impl) = target_impls.iter().find(|i| {
|
if let Some(target_deref_impl) = target_impls.iter().find(|i| {
|
||||||
i.inner_impl()
|
i.inner_impl()
|
||||||
|
|
|
@ -57,6 +57,7 @@ crate fn collect_trait_impls(mut krate: Crate, cx: &mut DocContext<'_>) -> Crate
|
||||||
|
|
||||||
// Follow all `Deref` targets of included items and recursively add them as valid
|
// Follow all `Deref` targets of included items and recursively add them as valid
|
||||||
fn add_deref_target(
|
fn add_deref_target(
|
||||||
|
cx: &DocContext<'_>,
|
||||||
map: &FxHashMap<DefId, &Type>,
|
map: &FxHashMap<DefId, &Type>,
|
||||||
cleaner: &mut BadImplStripper,
|
cleaner: &mut BadImplStripper,
|
||||||
type_did: DefId,
|
type_did: DefId,
|
||||||
|
@ -65,14 +66,14 @@ crate fn collect_trait_impls(mut krate: Crate, cx: &mut DocContext<'_>) -> Crate
|
||||||
debug!("add_deref_target: type {:?}, target {:?}", type_did, target);
|
debug!("add_deref_target: type {:?}, target {:?}", type_did, target);
|
||||||
if let Some(target_prim) = target.primitive_type() {
|
if let Some(target_prim) = target.primitive_type() {
|
||||||
cleaner.prims.insert(target_prim);
|
cleaner.prims.insert(target_prim);
|
||||||
} else if let Some(target_did) = target.def_id_no_primitives() {
|
} else if let Some(target_did) = target.def_id(&cx.cache) {
|
||||||
// `impl Deref<Target = S> for S`
|
// `impl Deref<Target = S> for S`
|
||||||
if target_did == type_did {
|
if target_did == type_did {
|
||||||
// Avoid infinite cycles
|
// Avoid infinite cycles
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
cleaner.items.insert(target_did.into());
|
cleaner.items.insert(target_did.into());
|
||||||
add_deref_target(map, cleaner, target_did);
|
add_deref_target(cx, map, cleaner, target_did);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -102,7 +103,7 @@ crate fn collect_trait_impls(mut krate: Crate, cx: &mut DocContext<'_>) -> Crate
|
||||||
// `Deref` target type and the impl for type positions, this map of types is keyed by
|
// `Deref` target type and the impl for type positions, this map of types is keyed by
|
||||||
// `DefId` and for convenience uses a special cleaner that accepts `DefId`s directly.
|
// `DefId` and for convenience uses a special cleaner that accepts `DefId`s directly.
|
||||||
if cleaner.keep_impl_with_def_id(for_did.into()) {
|
if cleaner.keep_impl_with_def_id(for_did.into()) {
|
||||||
add_deref_target(&type_did_to_deref_target, &mut cleaner, for_did);
|
add_deref_target(cx, &type_did_to_deref_target, &mut cleaner, for_did);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue