Use Path
instead of Type
in PolyTrait
The change to `impl Clean<Path> for hir::TraitRef<'_>` was necessary to fix a test failure for `src/test/rustdoc/trait-alias-mention.rs`. Here's why: The old code path was through `impl Clean<Type> for hir::TraitRef<'_>`, which called `resolve_type`, which in turn called `register_res`. Now, because `PolyTrait` uses a `Path` instead of a `Type`, the impl of `Clean<Path>` was being run, which did not call `register_res`, causing the trait alias to not be recorded in the `external_paths` cache.
This commit is contained in:
parent
4c6385ff93
commit
91d3b7201e
11 changed files with 209 additions and 307 deletions
|
@ -2,7 +2,7 @@ use crate::clean::auto_trait::AutoTraitFinder;
|
|||
use crate::clean::blanket_impl::BlanketImplFinder;
|
||||
use crate::clean::{
|
||||
inline, Clean, Crate, ExternalCrate, Generic, GenericArg, GenericArgs, ImportSource, Item,
|
||||
ItemKind, Lifetime, Path, PathSegment, PolyTrait, Primitive, PrimitiveType, ResolvedPath, Type,
|
||||
ItemKind, Lifetime, Path, PathSegment, Primitive, PrimitiveType, ResolvedPath, Type,
|
||||
TypeBinding, Visibility,
|
||||
};
|
||||
use crate::core::DocContext;
|
||||
|
@ -156,39 +156,7 @@ pub(super) fn external_path(
|
|||
}
|
||||
}
|
||||
|
||||
crate fn strip_type(ty: Type) -> Type {
|
||||
match ty {
|
||||
Type::ResolvedPath { path, did } => Type::ResolvedPath { path: strip_path(&path), did },
|
||||
Type::DynTrait(mut bounds, lt) => {
|
||||
let first = bounds.remove(0);
|
||||
let stripped_trait = strip_type(first.trait_);
|
||||
|
||||
bounds.insert(
|
||||
0,
|
||||
PolyTrait { trait_: stripped_trait, generic_params: first.generic_params },
|
||||
);
|
||||
Type::DynTrait(bounds, lt)
|
||||
}
|
||||
Type::Tuple(inner_tys) => {
|
||||
Type::Tuple(inner_tys.iter().map(|t| strip_type(t.clone())).collect())
|
||||
}
|
||||
Type::Slice(inner_ty) => Type::Slice(Box::new(strip_type(*inner_ty))),
|
||||
Type::Array(inner_ty, s) => Type::Array(Box::new(strip_type(*inner_ty)), s),
|
||||
Type::RawPointer(m, inner_ty) => Type::RawPointer(m, Box::new(strip_type(*inner_ty))),
|
||||
Type::BorrowedRef { lifetime, mutability, type_ } => {
|
||||
Type::BorrowedRef { lifetime, mutability, type_: Box::new(strip_type(*type_)) }
|
||||
}
|
||||
Type::QPath { name, self_type, trait_, self_def_id } => Type::QPath {
|
||||
name,
|
||||
self_def_id,
|
||||
self_type: Box::new(strip_type(*self_type)),
|
||||
trait_: Box::new(strip_type(*trait_)),
|
||||
},
|
||||
_ => ty,
|
||||
}
|
||||
}
|
||||
|
||||
crate fn strip_path(path: &Path) -> Path {
|
||||
crate fn strip_path(path: Path) -> Path {
|
||||
let segments = path
|
||||
.segments
|
||||
.iter()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue