Skip to content

Commit d81deb3

Browse files
committed
Stop re-exporting Type::ResolvedPath
I would like to rename it to `Type::Path`, but then it can't be re-exported since the name would conflict with the `Path` struct. Usually enum variants are referred to using their qualified names in Rust (and parts of rustdoc already do that with `clean::Type`), so this is also more consistent with the language.
1 parent 8adb0b6 commit d81deb3

File tree

9 files changed

+39
-36
lines changed

9 files changed

+39
-36
lines changed

src/librustdoc/clean/mod.rs

+3-4
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,8 @@ use crate::visit_ast::Module as DocModule;
4141

4242
use utils::*;
4343

44-
crate use utils::{get_auto_trait_and_blanket_impls, krate, register_res};
45-
4644
crate use self::types::*;
45+
crate use self::utils::{get_auto_trait_and_blanket_impls, krate, register_res};
4746

4847
crate trait Clean<T> {
4948
fn clean(&self, cx: &mut DocContext<'_>) -> T;
@@ -1406,12 +1405,12 @@ impl<'tcx> Clean<Type> for Ty<'tcx> {
14061405
};
14071406
inline::record_extern_fqn(cx, did, kind);
14081407
let path = external_path(cx, did, false, vec![], substs);
1409-
ResolvedPath { path }
1408+
Type::ResolvedPath { path }
14101409
}
14111410
ty::Foreign(did) => {
14121411
inline::record_extern_fqn(cx, did, ItemType::ForeignType);
14131412
let path = external_path(cx, did, false, vec![], InternalSubsts::empty());
1414-
ResolvedPath { path }
1413+
Type::ResolvedPath { path }
14151414
}
14161415
ty::Dynamic(obj, ref reg) => {
14171416
// HACK: pick the first `did` as the `did` of the trait object. Someone

src/librustdoc/clean/types.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ crate use self::ItemKind::*;
4747
crate use self::SelfTy::*;
4848
crate use self::Type::{
4949
Array, BareFunction, BorrowedRef, DynTrait, Generic, ImplTrait, Infer, Primitive, QPath,
50-
RawPointer, ResolvedPath, Slice, Tuple,
50+
RawPointer, Slice, Tuple,
5151
};
5252
crate use self::Visibility::{Inherited, Public};
5353

@@ -1488,7 +1488,7 @@ impl Type {
14881488
/// Checks if this is a `T::Name` path for an associated type.
14891489
crate fn is_assoc_ty(&self) -> bool {
14901490
match self {
1491-
ResolvedPath { path, .. } => path.is_assoc_ty(),
1491+
Type::ResolvedPath { path, .. } => path.is_assoc_ty(),
14921492
_ => false,
14931493
}
14941494
}
@@ -1502,7 +1502,7 @@ impl Type {
15021502

15031503
crate fn generics(&self) -> Option<Vec<&Type>> {
15041504
match self {
1505-
ResolvedPath { path, .. } => path.generics(),
1505+
Type::ResolvedPath { path, .. } => path.generics(),
15061506
_ => None,
15071507
}
15081508
}
@@ -1525,7 +1525,7 @@ impl Type {
15251525

15261526
fn inner_def_id(&self, cache: Option<&Cache>) -> Option<DefId> {
15271527
let t: PrimitiveType = match *self {
1528-
ResolvedPath { ref path } => return Some(path.def_id()),
1528+
Type::ResolvedPath { ref path } => return Some(path.def_id()),
15291529
DynTrait(ref bounds, _) => return Some(bounds[0].trait_.def_id()),
15301530
Primitive(p) => return cache.and_then(|c| c.primitive_locations.get(&p).cloned()),
15311531
BorrowedRef { type_: box Generic(..), .. } => PrimitiveType::Reference,

src/librustdoc/clean/utils.rs

+3-4
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@ use crate::clean::auto_trait::AutoTraitFinder;
22
use crate::clean::blanket_impl::BlanketImplFinder;
33
use crate::clean::{
44
inline, Clean, Crate, ExternalCrate, Generic, GenericArg, GenericArgs, ImportSource, Item,
5-
ItemKind, Lifetime, Path, PathSegment, Primitive, PrimitiveType, ResolvedPath, Type,
6-
TypeBinding, Visibility,
5+
ItemKind, Lifetime, Path, PathSegment, Primitive, PrimitiveType, Type, TypeBinding, Visibility,
76
};
87
use crate::core::DocContext;
98
use crate::formats::item_type::ItemType;
@@ -187,7 +186,7 @@ crate fn build_deref_target_impls(cx: &mut DocContext<'_>, items: &[Item], ret:
187186
for &did in prim.impls(tcx).iter().filter(|did| !did.is_local()) {
188187
inline::build_impl(cx, None, did, None, ret);
189188
}
190-
} else if let ResolvedPath { path } = target {
189+
} else if let Type::ResolvedPath { path } = target {
191190
let did = path.def_id();
192191
if !did.is_local() {
193192
inline::build_impls(cx, None, did, None, ret);
@@ -362,7 +361,7 @@ crate fn resolve_type(cx: &mut DocContext<'_>, path: Path) -> Type {
362361
Res::Def(DefKind::TyParam, _) if path.segments.len() == 1 => Generic(path.segments[0].name),
363362
_ => {
364363
let _ = register_res(cx, path.res);
365-
ResolvedPath { path }
364+
Type::ResolvedPath { path }
366365
}
367366
}
368367
}

src/librustdoc/formats/cache.rs

+5-3
Original file line numberDiff line numberDiff line change
@@ -401,7 +401,7 @@ impl<'a, 'tcx> DocFolder for CacheBuilder<'a, 'tcx> {
401401
clean::ImplItem(ref i) => {
402402
self.cache.parent_is_trait_impl = i.trait_.is_some();
403403
match i.for_ {
404-
clean::ResolvedPath { ref path } => {
404+
clean::Type::ResolvedPath { ref path } => {
405405
self.cache.parent_stack.push(path.def_id());
406406
true
407407
}
@@ -436,8 +436,10 @@ impl<'a, 'tcx> DocFolder for CacheBuilder<'a, 'tcx> {
436436
// Note: matching twice to restrict the lifetime of the `i` borrow.
437437
let mut dids = FxHashSet::default();
438438
match i.for_ {
439-
clean::ResolvedPath { ref path }
440-
| clean::BorrowedRef { type_: box clean::ResolvedPath { ref path }, .. } => {
439+
clean::Type::ResolvedPath { ref path }
440+
| clean::BorrowedRef {
441+
type_: box clean::Type::ResolvedPath { ref path }, ..
442+
} => {
441443
dids.insert(path.def_id());
442444
}
443445
clean::DynTrait(ref bounds, _)

src/librustdoc/html/format.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -762,7 +762,7 @@ fn fmt_type<'cx>(
762762

763763
match *t {
764764
clean::Generic(name) => write!(f, "{}", name),
765-
clean::ResolvedPath { ref path } => {
765+
clean::Type::ResolvedPath { ref path } => {
766766
// Paths like `T::Output` and `Self::Output` should be rendered with all segments.
767767
let did = path.def_id();
768768
resolved_path(f, did, path, path.is_assoc_ty(), use_absolute, cx)

src/librustdoc/html/render/cache.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ fn get_index_type(clean_type: &clean::Type, generics: Vec<TypeWithKind>) -> Rend
218218

219219
fn get_index_type_name(clean_type: &clean::Type, accept_generic: bool) -> Option<Symbol> {
220220
match *clean_type {
221-
clean::ResolvedPath { ref path, .. } => {
221+
clean::Type::ResolvedPath { ref path, .. } => {
222222
let path_segment = path.segments.last().unwrap();
223223
Some(path_segment.name)
224224
}

src/librustdoc/html/render/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1227,7 +1227,7 @@ fn should_render_item(item: &clean::Item, deref_mut_: bool, tcx: TyCtxt<'_>) ->
12271227
| SelfTy::SelfExplicit(clean::BorrowedRef { mutability, .. }) => {
12281228
(mutability == Mutability::Mut, false, false)
12291229
}
1230-
SelfTy::SelfExplicit(clean::ResolvedPath { path }) => {
1230+
SelfTy::SelfExplicit(clean::Type::ResolvedPath { path }) => {
12311231
(false, Some(path.def_id()) == tcx.lang_items().owned_box(), false)
12321232
}
12331233
SelfTy::SelfValue => (false, false, true),

src/librustdoc/html/render/print_item.rs

+12-13
Original file line numberDiff line numberDiff line change
@@ -727,10 +727,10 @@ fn item_trait(w: &mut Buffer, cx: &Context<'_>, it: &clean::Item, t: &clean::Tra
727727
let mut implementor_dups: FxHashMap<Symbol, (DefId, bool)> = FxHashMap::default();
728728
for implementor in implementors {
729729
match implementor.inner_impl().for_ {
730-
clean::ResolvedPath { ref path }
731-
| clean::BorrowedRef { type_: box clean::ResolvedPath { ref path }, .. }
732-
if !path.is_assoc_ty() =>
733-
{
730+
clean::Type::ResolvedPath { ref path }
731+
| clean::BorrowedRef {
732+
type_: box clean::Type::ResolvedPath { ref path }, ..
733+
} if !path.is_assoc_ty() => {
734734
let did = path.def_id();
735735
let &mut (prev_did, ref mut has_duplicates) =
736736
implementor_dups.entry(path.last()).or_insert((did, false));
@@ -1452,15 +1452,14 @@ fn render_implementor(
14521452
) {
14531453
// If there's already another implementor that has the same abridged name, use the
14541454
// full path, for example in `std::iter::ExactSizeIterator`
1455-
let use_absolute = match implementor.inner_impl().for_ {
1456-
clean::ResolvedPath { ref path, .. }
1457-
| clean::BorrowedRef { type_: box clean::ResolvedPath { ref path, .. }, .. }
1458-
if !path.is_assoc_ty() =>
1459-
{
1460-
implementor_dups[&path.last()].1
1461-
}
1462-
_ => false,
1463-
};
1455+
let use_absolute =
1456+
match implementor.inner_impl().for_ {
1457+
clean::Type::ResolvedPath { ref path, .. }
1458+
| clean::BorrowedRef {
1459+
type_: box clean::Type::ResolvedPath { ref path, .. }, ..
1460+
} if !path.is_assoc_ty() => implementor_dups[&path.last()].1,
1461+
_ => false,
1462+
};
14641463
render_impl(
14651464
w,
14661465
cx,

src/librustdoc/json/conversions.rs

+9-5
Original file line numberDiff line numberDiff line change
@@ -365,7 +365,7 @@ impl FromWithTcx<clean::GenericBound> for GenericBound {
365365
match bound {
366366
TraitBound(clean::PolyTrait { trait_, generic_params }, modifier) => {
367367
// FIXME: should `trait_` be a clean::Path equivalent in JSON?
368-
let trait_ = clean::ResolvedPath { path: trait_ }.into_tcx(tcx);
368+
let trait_ = clean::Type::ResolvedPath { path: trait_ }.into_tcx(tcx);
369369
GenericBound::TraitBound {
370370
trait_,
371371
generic_params: generic_params.into_iter().map(|x| x.into_tcx(tcx)).collect(),
@@ -388,9 +388,13 @@ crate fn from_trait_bound_modifier(modifier: rustc_hir::TraitBoundModifier) -> T
388388

389389
impl FromWithTcx<clean::Type> for Type {
390390
fn from_tcx(ty: clean::Type, tcx: TyCtxt<'_>) -> Self {
391-
use clean::Type::*;
391+
use clean::Type::{
392+
Array, BareFunction, BorrowedRef, DynTrait, Generic, ImplTrait, Infer, Primitive,
393+
QPath, RawPointer, Slice, Tuple,
394+
};
395+
392396
match ty {
393-
ResolvedPath { path } => Type::ResolvedPath {
397+
clean::Type::ResolvedPath { path } => Type::ResolvedPath {
394398
name: path.whole_name(),
395399
id: from_item_id(path.def_id().into()),
396400
args: path.segments.last().map(|args| Box::new(args.clone().args.into_tcx(tcx))),
@@ -435,7 +439,7 @@ impl FromWithTcx<clean::Type> for Type {
435439
},
436440
QPath { name, self_type, trait_, .. } => {
437441
// FIXME: should `trait_` be a clean::Path equivalent in JSON?
438-
let trait_ = ResolvedPath { path: trait_ }.into_tcx(tcx);
442+
let trait_ = clean::Type::ResolvedPath { path: trait_ }.into_tcx(tcx);
439443
Type::QualifiedPath {
440444
name: name.to_string(),
441445
self_type: Box::new((*self_type).into_tcx(tcx)),
@@ -501,7 +505,7 @@ impl FromWithTcx<clean::Impl> for Impl {
501505
let provided_trait_methods = impl_.provided_trait_methods(tcx);
502506
let clean::Impl { unsafety, generics, trait_, for_, items, polarity, kind } = impl_;
503507
// FIXME: should `trait_` be a clean::Path equivalent in JSON?
504-
let trait_ = trait_.map(|path| clean::ResolvedPath { path }.into_tcx(tcx));
508+
let trait_ = trait_.map(|path| clean::Type::ResolvedPath { path }.into_tcx(tcx));
505509
// FIXME: use something like ImplKind in JSON?
506510
let (synthetic, blanket_impl) = match kind {
507511
clean::ImplKind::Normal => (false, None),

0 commit comments

Comments
 (0)