Rename Type::ResolvedPath
to Type::Path
At last! The new name is shorter, simpler, and consistent with `hir::Ty`.
This commit is contained in:
parent
d81deb33fa
commit
79c718f1d5
9 changed files with 37 additions and 38 deletions
|
@ -1405,12 +1405,12 @@ impl<'tcx> Clean<Type> for Ty<'tcx> {
|
||||||
};
|
};
|
||||||
inline::record_extern_fqn(cx, did, kind);
|
inline::record_extern_fqn(cx, did, kind);
|
||||||
let path = external_path(cx, did, false, vec![], substs);
|
let path = external_path(cx, did, false, vec![], substs);
|
||||||
Type::ResolvedPath { path }
|
Type::Path { path }
|
||||||
}
|
}
|
||||||
ty::Foreign(did) => {
|
ty::Foreign(did) => {
|
||||||
inline::record_extern_fqn(cx, did, ItemType::ForeignType);
|
inline::record_extern_fqn(cx, did, ItemType::ForeignType);
|
||||||
let path = external_path(cx, did, false, vec![], InternalSubsts::empty());
|
let path = external_path(cx, did, false, vec![], InternalSubsts::empty());
|
||||||
Type::ResolvedPath { path }
|
Type::Path { path }
|
||||||
}
|
}
|
||||||
ty::Dynamic(obj, ref reg) => {
|
ty::Dynamic(obj, ref reg) => {
|
||||||
// HACK: pick the first `did` as the `did` of the trait object. Someone
|
// HACK: pick the first `did` as the `did` of the trait object. Someone
|
||||||
|
|
|
@ -1421,8 +1421,9 @@ crate struct PolyTrait {
|
||||||
crate enum Type {
|
crate enum Type {
|
||||||
/// A named type, which could be a trait.
|
/// A named type, which could be a trait.
|
||||||
///
|
///
|
||||||
/// This is mostly Rustdoc's version of [`hir::Path`]. It has to be different because Rustdoc's [`PathSegment`] can contain cleaned generics.
|
/// This is mostly Rustdoc's version of [`hir::Path`].
|
||||||
ResolvedPath { path: Path },
|
/// It has to be different because Rustdoc's [`PathSegment`] can contain cleaned generics.
|
||||||
|
Path { path: Path },
|
||||||
/// A `dyn Trait` object: `dyn for<'a> Trait<'a> + Send + 'static`
|
/// A `dyn Trait` object: `dyn for<'a> Trait<'a> + Send + 'static`
|
||||||
DynTrait(Vec<PolyTrait>, Option<Lifetime>),
|
DynTrait(Vec<PolyTrait>, Option<Lifetime>),
|
||||||
/// A type parameter.
|
/// A type parameter.
|
||||||
|
@ -1488,7 +1489,7 @@ impl Type {
|
||||||
/// Checks if this is a `T::Name` path for an associated type.
|
/// Checks if this is a `T::Name` path for an associated type.
|
||||||
crate fn is_assoc_ty(&self) -> bool {
|
crate fn is_assoc_ty(&self) -> bool {
|
||||||
match self {
|
match self {
|
||||||
Type::ResolvedPath { path, .. } => path.is_assoc_ty(),
|
Type::Path { path, .. } => path.is_assoc_ty(),
|
||||||
_ => false,
|
_ => false,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1502,7 +1503,7 @@ impl Type {
|
||||||
|
|
||||||
crate fn generics(&self) -> Option<Vec<&Type>> {
|
crate fn generics(&self) -> Option<Vec<&Type>> {
|
||||||
match self {
|
match self {
|
||||||
Type::ResolvedPath { path, .. } => path.generics(),
|
Type::Path { path, .. } => path.generics(),
|
||||||
_ => None,
|
_ => None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1525,7 +1526,7 @@ impl Type {
|
||||||
|
|
||||||
fn inner_def_id(&self, cache: Option<&Cache>) -> Option<DefId> {
|
fn inner_def_id(&self, cache: Option<&Cache>) -> Option<DefId> {
|
||||||
let t: PrimitiveType = match *self {
|
let t: PrimitiveType = match *self {
|
||||||
Type::ResolvedPath { ref path } => return Some(path.def_id()),
|
Type::Path { ref path } => return Some(path.def_id()),
|
||||||
DynTrait(ref bounds, _) => return Some(bounds[0].trait_.def_id()),
|
DynTrait(ref bounds, _) => return Some(bounds[0].trait_.def_id()),
|
||||||
Primitive(p) => return cache.and_then(|c| c.primitive_locations.get(&p).cloned()),
|
Primitive(p) => return cache.and_then(|c| c.primitive_locations.get(&p).cloned()),
|
||||||
BorrowedRef { type_: box Generic(..), .. } => PrimitiveType::Reference,
|
BorrowedRef { type_: box Generic(..), .. } => PrimitiveType::Reference,
|
||||||
|
|
|
@ -186,7 +186,7 @@ crate fn build_deref_target_impls(cx: &mut DocContext<'_>, items: &[Item], ret:
|
||||||
for &did in prim.impls(tcx).iter().filter(|did| !did.is_local()) {
|
for &did in prim.impls(tcx).iter().filter(|did| !did.is_local()) {
|
||||||
inline::build_impl(cx, None, did, None, ret);
|
inline::build_impl(cx, None, did, None, ret);
|
||||||
}
|
}
|
||||||
} else if let Type::ResolvedPath { path } = target {
|
} else if let Type::Path { path } = target {
|
||||||
let did = path.def_id();
|
let did = path.def_id();
|
||||||
if !did.is_local() {
|
if !did.is_local() {
|
||||||
inline::build_impls(cx, None, did, None, ret);
|
inline::build_impls(cx, None, did, None, ret);
|
||||||
|
@ -361,7 +361,7 @@ crate fn resolve_type(cx: &mut DocContext<'_>, path: Path) -> Type {
|
||||||
Res::Def(DefKind::TyParam, _) if path.segments.len() == 1 => Generic(path.segments[0].name),
|
Res::Def(DefKind::TyParam, _) if path.segments.len() == 1 => Generic(path.segments[0].name),
|
||||||
_ => {
|
_ => {
|
||||||
let _ = register_res(cx, path.res);
|
let _ = register_res(cx, path.res);
|
||||||
Type::ResolvedPath { path }
|
Type::Path { path }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,7 +27,7 @@ use crate::html::render::IndexItem;
|
||||||
#[derive(Default)]
|
#[derive(Default)]
|
||||||
crate struct Cache {
|
crate struct Cache {
|
||||||
/// Maps a type ID to all known implementations for that type. This is only
|
/// Maps a type ID to all known implementations for that type. This is only
|
||||||
/// recognized for intra-crate `ResolvedPath` types, and is used to print
|
/// recognized for intra-crate [`clean::Type::Path`]s, and is used to print
|
||||||
/// out extra documentation on the page of an enum/struct.
|
/// out extra documentation on the page of an enum/struct.
|
||||||
///
|
///
|
||||||
/// The values of the map are a list of implementations and documentation
|
/// The values of the map are a list of implementations and documentation
|
||||||
|
@ -401,7 +401,7 @@ impl<'a, 'tcx> DocFolder for CacheBuilder<'a, 'tcx> {
|
||||||
clean::ImplItem(ref i) => {
|
clean::ImplItem(ref i) => {
|
||||||
self.cache.parent_is_trait_impl = i.trait_.is_some();
|
self.cache.parent_is_trait_impl = i.trait_.is_some();
|
||||||
match i.for_ {
|
match i.for_ {
|
||||||
clean::Type::ResolvedPath { ref path } => {
|
clean::Type::Path { ref path } => {
|
||||||
self.cache.parent_stack.push(path.def_id());
|
self.cache.parent_stack.push(path.def_id());
|
||||||
true
|
true
|
||||||
}
|
}
|
||||||
|
@ -436,10 +436,8 @@ impl<'a, 'tcx> DocFolder for CacheBuilder<'a, 'tcx> {
|
||||||
// Note: matching twice to restrict the lifetime of the `i` borrow.
|
// Note: matching twice to restrict the lifetime of the `i` borrow.
|
||||||
let mut dids = FxHashSet::default();
|
let mut dids = FxHashSet::default();
|
||||||
match i.for_ {
|
match i.for_ {
|
||||||
clean::Type::ResolvedPath { ref path }
|
clean::Type::Path { ref path }
|
||||||
| clean::BorrowedRef {
|
| clean::BorrowedRef { type_: box clean::Type::Path { ref path }, .. } => {
|
||||||
type_: box clean::Type::ResolvedPath { ref path }, ..
|
|
||||||
} => {
|
|
||||||
dids.insert(path.def_id());
|
dids.insert(path.def_id());
|
||||||
}
|
}
|
||||||
clean::DynTrait(ref bounds, _)
|
clean::DynTrait(ref bounds, _)
|
||||||
|
|
|
@ -607,8 +607,7 @@ crate fn href_relative_parts<'a>(fqp: &'a [String], relative_to_fqp: &'a [String
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Used when rendering a `ResolvedPath` structure. This invokes the `path`
|
/// Used to render a [`clean::Path`].
|
||||||
/// rendering function with the necessary arguments for linking to a local path.
|
|
||||||
fn resolved_path<'cx>(
|
fn resolved_path<'cx>(
|
||||||
w: &mut fmt::Formatter<'_>,
|
w: &mut fmt::Formatter<'_>,
|
||||||
did: DefId,
|
did: DefId,
|
||||||
|
@ -762,7 +761,7 @@ fn fmt_type<'cx>(
|
||||||
|
|
||||||
match *t {
|
match *t {
|
||||||
clean::Generic(name) => write!(f, "{}", name),
|
clean::Generic(name) => write!(f, "{}", name),
|
||||||
clean::Type::ResolvedPath { ref path } => {
|
clean::Type::Path { ref path } => {
|
||||||
// Paths like `T::Output` and `Self::Output` should be rendered with all segments.
|
// Paths like `T::Output` and `Self::Output` should be rendered with all segments.
|
||||||
let did = path.def_id();
|
let did = path.def_id();
|
||||||
resolved_path(f, did, path, path.is_assoc_ty(), use_absolute, cx)
|
resolved_path(f, did, path, path.is_assoc_ty(), use_absolute, cx)
|
||||||
|
|
|
@ -218,7 +218,7 @@ fn get_index_type(clean_type: &clean::Type, generics: Vec<TypeWithKind>) -> Rend
|
||||||
|
|
||||||
fn get_index_type_name(clean_type: &clean::Type, accept_generic: bool) -> Option<Symbol> {
|
fn get_index_type_name(clean_type: &clean::Type, accept_generic: bool) -> Option<Symbol> {
|
||||||
match *clean_type {
|
match *clean_type {
|
||||||
clean::Type::ResolvedPath { ref path, .. } => {
|
clean::Type::Path { ref path, .. } => {
|
||||||
let path_segment = path.segments.last().unwrap();
|
let path_segment = path.segments.last().unwrap();
|
||||||
Some(path_segment.name)
|
Some(path_segment.name)
|
||||||
}
|
}
|
||||||
|
@ -371,7 +371,7 @@ crate fn get_real_types<'tcx>(
|
||||||
let mut ty_generics = Vec::new();
|
let mut ty_generics = Vec::new();
|
||||||
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 { path };
|
let ty = Type::Path { path };
|
||||||
get_real_types(generics, &ty, tcx, recurse + 1, &mut ty_generics, cache);
|
get_real_types(generics, &ty, tcx, recurse + 1, &mut ty_generics, cache);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1227,7 +1227,7 @@ fn should_render_item(item: &clean::Item, deref_mut_: bool, tcx: TyCtxt<'_>) ->
|
||||||
| SelfTy::SelfExplicit(clean::BorrowedRef { mutability, .. }) => {
|
| SelfTy::SelfExplicit(clean::BorrowedRef { mutability, .. }) => {
|
||||||
(mutability == Mutability::Mut, false, false)
|
(mutability == Mutability::Mut, false, false)
|
||||||
}
|
}
|
||||||
SelfTy::SelfExplicit(clean::Type::ResolvedPath { path }) => {
|
SelfTy::SelfExplicit(clean::Type::Path { path }) => {
|
||||||
(false, Some(path.def_id()) == tcx.lang_items().owned_box(), false)
|
(false, Some(path.def_id()) == tcx.lang_items().owned_box(), false)
|
||||||
}
|
}
|
||||||
SelfTy::SelfValue => (false, false, true),
|
SelfTy::SelfValue => (false, false, true),
|
||||||
|
@ -2520,7 +2520,7 @@ fn collect_paths_for_type(first_ty: clean::Type, cache: &Cache) -> Vec<String> {
|
||||||
}
|
}
|
||||||
|
|
||||||
match ty {
|
match ty {
|
||||||
clean::Type::ResolvedPath { path } => process_path(path.def_id()),
|
clean::Type::Path { path } => process_path(path.def_id()),
|
||||||
clean::Type::Tuple(tys) => {
|
clean::Type::Tuple(tys) => {
|
||||||
work.extend(tys.into_iter());
|
work.extend(tys.into_iter());
|
||||||
}
|
}
|
||||||
|
|
|
@ -727,10 +727,10 @@ fn item_trait(w: &mut Buffer, cx: &Context<'_>, it: &clean::Item, t: &clean::Tra
|
||||||
let mut implementor_dups: FxHashMap<Symbol, (DefId, bool)> = FxHashMap::default();
|
let mut implementor_dups: FxHashMap<Symbol, (DefId, bool)> = FxHashMap::default();
|
||||||
for implementor in implementors {
|
for implementor in implementors {
|
||||||
match implementor.inner_impl().for_ {
|
match implementor.inner_impl().for_ {
|
||||||
clean::Type::ResolvedPath { ref path }
|
clean::Type::Path { ref path }
|
||||||
| clean::BorrowedRef {
|
| clean::BorrowedRef { type_: box clean::Type::Path { ref path }, .. }
|
||||||
type_: box clean::Type::ResolvedPath { ref path }, ..
|
if !path.is_assoc_ty() =>
|
||||||
} if !path.is_assoc_ty() => {
|
{
|
||||||
let did = path.def_id();
|
let did = path.def_id();
|
||||||
let &mut (prev_did, ref mut has_duplicates) =
|
let &mut (prev_did, ref mut has_duplicates) =
|
||||||
implementor_dups.entry(path.last()).or_insert((did, false));
|
implementor_dups.entry(path.last()).or_insert((did, false));
|
||||||
|
@ -1452,14 +1452,15 @@ fn render_implementor(
|
||||||
) {
|
) {
|
||||||
// If there's already another implementor that has the same abridged name, use the
|
// If there's already another implementor that has the same abridged name, use the
|
||||||
// full path, for example in `std::iter::ExactSizeIterator`
|
// full path, for example in `std::iter::ExactSizeIterator`
|
||||||
let use_absolute =
|
let use_absolute = match implementor.inner_impl().for_ {
|
||||||
match implementor.inner_impl().for_ {
|
clean::Type::Path { ref path, .. }
|
||||||
clean::Type::ResolvedPath { ref path, .. }
|
| clean::BorrowedRef { type_: box clean::Type::Path { ref path, .. }, .. }
|
||||||
| clean::BorrowedRef {
|
if !path.is_assoc_ty() =>
|
||||||
type_: box clean::Type::ResolvedPath { ref path, .. }, ..
|
{
|
||||||
} if !path.is_assoc_ty() => implementor_dups[&path.last()].1,
|
implementor_dups[&path.last()].1
|
||||||
_ => false,
|
}
|
||||||
};
|
_ => false,
|
||||||
|
};
|
||||||
render_impl(
|
render_impl(
|
||||||
w,
|
w,
|
||||||
cx,
|
cx,
|
||||||
|
|
|
@ -365,7 +365,7 @@ impl FromWithTcx<clean::GenericBound> for GenericBound {
|
||||||
match bound {
|
match bound {
|
||||||
TraitBound(clean::PolyTrait { trait_, generic_params }, modifier) => {
|
TraitBound(clean::PolyTrait { trait_, generic_params }, modifier) => {
|
||||||
// FIXME: should `trait_` be a clean::Path equivalent in JSON?
|
// FIXME: should `trait_` be a clean::Path equivalent in JSON?
|
||||||
let trait_ = clean::Type::ResolvedPath { path: trait_ }.into_tcx(tcx);
|
let trait_ = clean::Type::Path { path: trait_ }.into_tcx(tcx);
|
||||||
GenericBound::TraitBound {
|
GenericBound::TraitBound {
|
||||||
trait_,
|
trait_,
|
||||||
generic_params: generic_params.into_iter().map(|x| x.into_tcx(tcx)).collect(),
|
generic_params: generic_params.into_iter().map(|x| x.into_tcx(tcx)).collect(),
|
||||||
|
@ -394,7 +394,7 @@ impl FromWithTcx<clean::Type> for Type {
|
||||||
};
|
};
|
||||||
|
|
||||||
match ty {
|
match ty {
|
||||||
clean::Type::ResolvedPath { path } => Type::ResolvedPath {
|
clean::Type::Path { path } => Type::ResolvedPath {
|
||||||
name: path.whole_name(),
|
name: path.whole_name(),
|
||||||
id: from_item_id(path.def_id().into()),
|
id: from_item_id(path.def_id().into()),
|
||||||
args: path.segments.last().map(|args| Box::new(args.clone().args.into_tcx(tcx))),
|
args: path.segments.last().map(|args| Box::new(args.clone().args.into_tcx(tcx))),
|
||||||
|
@ -439,7 +439,7 @@ impl FromWithTcx<clean::Type> for Type {
|
||||||
},
|
},
|
||||||
QPath { name, self_type, trait_, .. } => {
|
QPath { name, self_type, trait_, .. } => {
|
||||||
// FIXME: should `trait_` be a clean::Path equivalent in JSON?
|
// FIXME: should `trait_` be a clean::Path equivalent in JSON?
|
||||||
let trait_ = clean::Type::ResolvedPath { path: trait_ }.into_tcx(tcx);
|
let trait_ = clean::Type::Path { path: trait_ }.into_tcx(tcx);
|
||||||
Type::QualifiedPath {
|
Type::QualifiedPath {
|
||||||
name: name.to_string(),
|
name: name.to_string(),
|
||||||
self_type: Box::new((*self_type).into_tcx(tcx)),
|
self_type: Box::new((*self_type).into_tcx(tcx)),
|
||||||
|
@ -505,7 +505,7 @@ impl FromWithTcx<clean::Impl> for Impl {
|
||||||
let provided_trait_methods = impl_.provided_trait_methods(tcx);
|
let provided_trait_methods = impl_.provided_trait_methods(tcx);
|
||||||
let clean::Impl { unsafety, generics, trait_, for_, items, polarity, kind } = impl_;
|
let clean::Impl { unsafety, generics, trait_, for_, items, polarity, kind } = impl_;
|
||||||
// FIXME: should `trait_` be a clean::Path equivalent in JSON?
|
// FIXME: should `trait_` be a clean::Path equivalent in JSON?
|
||||||
let trait_ = trait_.map(|path| clean::Type::ResolvedPath { path }.into_tcx(tcx));
|
let trait_ = trait_.map(|path| clean::Type::Path { path }.into_tcx(tcx));
|
||||||
// FIXME: use something like ImplKind in JSON?
|
// FIXME: use something like ImplKind in JSON?
|
||||||
let (synthetic, blanket_impl) = match kind {
|
let (synthetic, blanket_impl) = match kind {
|
||||||
clean::ImplKind::Normal => (false, None),
|
clean::ImplKind::Normal => (false, None),
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue