Skip to content

Commit fcbbdaf

Browse files
authored
Rollup merge of #91197 - camelid:rename-resolvedpath, r=GuillaumeGomez,jyn514
rustdoc: Rename `Type::ResolvedPath` to `Type::Path` and don't re-export it The new name is shorter, simpler, and consistent with `hir::Ty`. It can't be re-exported since the name would conflict with the `clean::Path` struct. But usually enum variants are referred to using their qualified names in Rust anyway (and parts of rustdoc already do that with `clean::Type`), so this is also more consistent with the language. r? `@GuillaumeGomez` cc `@jyn514`
2 parents 10743f0 + 79c718f commit fcbbdaf

File tree

9 files changed

+43
-43
lines changed

9 files changed

+43
-43
lines changed

src/librustdoc/clean/mod.rs

+3-9
Original file line numberDiff line numberDiff line change
@@ -41,14 +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-
46-
crate use self::types::FnRetTy::*;
47-
crate use self::types::ItemKind::*;
48-
crate use self::types::SelfTy::*;
49-
crate use self::types::Type::*;
50-
crate use self::types::Visibility::{Inherited, Public};
5144
crate use self::types::*;
45+
crate use self::utils::{get_auto_trait_and_blanket_impls, krate, register_res};
5246

5347
crate trait Clean<T> {
5448
fn clean(&self, cx: &mut DocContext<'_>) -> T;
@@ -1411,12 +1405,12 @@ impl<'tcx> Clean<Type> for Ty<'tcx> {
14111405
};
14121406
inline::record_extern_fqn(cx, did, kind);
14131407
let path = external_path(cx, did, false, vec![], substs);
1414-
ResolvedPath { path }
1408+
Type::Path { path }
14151409
}
14161410
ty::Foreign(did) => {
14171411
inline::record_extern_fqn(cx, did, ItemType::ForeignType);
14181412
let path = external_path(cx, did, false, vec![], InternalSubsts::empty());
1419-
ResolvedPath { path }
1413+
Type::Path { path }
14201414
}
14211415
ty::Dynamic(obj, ref reg) => {
14221416
// HACK: pick the first `did` as the `did` of the trait object. Someone

src/librustdoc/clean/types.rs

+14-10
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ use rustc_target::spec::abi::Abi;
3434
use crate::clean::cfg::Cfg;
3535
use crate::clean::external_path;
3636
use crate::clean::inline::{self, print_inlined_const};
37-
use crate::clean::types::Type::{QPath, ResolvedPath};
3837
use crate::clean::utils::{is_literal_expr, print_const_expr, print_evaluated_const};
3938
use crate::clean::Clean;
4039
use crate::core::DocContext;
@@ -43,10 +42,14 @@ use crate::formats::item_type::ItemType;
4342
use crate::html::render::cache::ExternalLocation;
4443
use crate::html::render::Context;
4544

46-
use self::FnRetTy::*;
47-
use self::ItemKind::*;
48-
use self::SelfTy::*;
49-
use self::Type::*;
45+
crate use self::FnRetTy::*;
46+
crate use self::ItemKind::*;
47+
crate use self::SelfTy::*;
48+
crate use self::Type::{
49+
Array, BareFunction, BorrowedRef, DynTrait, Generic, ImplTrait, Infer, Primitive, QPath,
50+
RawPointer, Slice, Tuple,
51+
};
52+
crate use self::Visibility::{Inherited, Public};
5053

5154
crate type ItemIdSet = FxHashSet<ItemId>;
5255

@@ -1418,8 +1421,9 @@ crate struct PolyTrait {
14181421
crate enum Type {
14191422
/// A named type, which could be a trait.
14201423
///
1421-
/// This is mostly Rustdoc's version of [`hir::Path`]. It has to be different because Rustdoc's [`PathSegment`] can contain cleaned generics.
1422-
ResolvedPath { path: Path },
1424+
/// This is mostly Rustdoc's version of [`hir::Path`].
1425+
/// It has to be different because Rustdoc's [`PathSegment`] can contain cleaned generics.
1426+
Path { path: Path },
14231427
/// A `dyn Trait` object: `dyn for<'a> Trait<'a> + Send + 'static`
14241428
DynTrait(Vec<PolyTrait>, Option<Lifetime>),
14251429
/// A type parameter.
@@ -1485,7 +1489,7 @@ impl Type {
14851489
/// Checks if this is a `T::Name` path for an associated type.
14861490
crate fn is_assoc_ty(&self) -> bool {
14871491
match self {
1488-
ResolvedPath { path, .. } => path.is_assoc_ty(),
1492+
Type::Path { path, .. } => path.is_assoc_ty(),
14891493
_ => false,
14901494
}
14911495
}
@@ -1499,7 +1503,7 @@ impl Type {
14991503

15001504
crate fn generics(&self) -> Option<Vec<&Type>> {
15011505
match self {
1502-
ResolvedPath { path, .. } => path.generics(),
1506+
Type::Path { path, .. } => path.generics(),
15031507
_ => None,
15041508
}
15051509
}
@@ -1522,7 +1526,7 @@ impl Type {
15221526

15231527
fn inner_def_id(&self, cache: Option<&Cache>) -> Option<DefId> {
15241528
let t: PrimitiveType = match *self {
1525-
ResolvedPath { ref path } => return Some(path.def_id()),
1529+
Type::Path { ref path } => return Some(path.def_id()),
15261530
DynTrait(ref bounds, _) => return Some(bounds[0].trait_.def_id()),
15271531
Primitive(p) => return cache.and_then(|c| c.primitive_locations.get(&p).cloned()),
15281532
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::Path { 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::Path { path }
366365
}
367366
}
368367
}

src/librustdoc/formats/cache.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ use crate::html::render::IndexItem;
2727
#[derive(Default)]
2828
crate struct Cache {
2929
/// Maps a type ID to all known implementations for that type. This is only
30-
/// recognized for intra-crate `ResolvedPath` types, and is used to print
30+
/// recognized for intra-crate [`clean::Type::Path`]s, and is used to print
3131
/// out extra documentation on the page of an enum/struct.
3232
///
3333
/// The values of the map are a list of implementations and documentation
@@ -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::Path { ref path } => {
405405
self.cache.parent_stack.push(path.def_id());
406406
true
407407
}
@@ -436,8 +436,8 @@ 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::Path { ref path }
440+
| clean::BorrowedRef { type_: box clean::Type::Path { ref path }, .. } => {
441441
dids.insert(path.def_id());
442442
}
443443
clean::DynTrait(ref bounds, _)

src/librustdoc/html/format.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -607,8 +607,7 @@ crate fn href_relative_parts<'a>(fqp: &'a [String], relative_to_fqp: &'a [String
607607
}
608608
}
609609

610-
/// Used when rendering a `ResolvedPath` structure. This invokes the `path`
611-
/// rendering function with the necessary arguments for linking to a local path.
610+
/// Used to render a [`clean::Path`].
612611
fn resolved_path<'cx>(
613612
w: &mut fmt::Formatter<'_>,
614613
did: DefId,
@@ -762,7 +761,7 @@ fn fmt_type<'cx>(
762761

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

src/librustdoc/html/render/cache.rs

+2-2
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::Path { ref path, .. } => {
222222
let path_segment = path.segments.last().unwrap();
223223
Some(path_segment.name)
224224
}
@@ -371,7 +371,7 @@ crate fn get_real_types<'tcx>(
371371
let mut ty_generics = Vec::new();
372372
for bound in bound.get_bounds().unwrap_or(&[]) {
373373
if let Some(path) = bound.get_trait_path() {
374-
let ty = Type::ResolvedPath { path };
374+
let ty = Type::Path { path };
375375
get_real_types(generics, &ty, tcx, recurse + 1, &mut ty_generics, cache);
376376
}
377377
}

src/librustdoc/html/render/mod.rs

+2-2
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::Path { path }) => {
12311231
(false, Some(path.def_id()) == tcx.lang_items().owned_box(), false)
12321232
}
12331233
SelfTy::SelfValue => (false, false, true),
@@ -2520,7 +2520,7 @@ fn collect_paths_for_type(first_ty: clean::Type, cache: &Cache) -> Vec<String> {
25202520
}
25212521

25222522
match ty {
2523-
clean::Type::ResolvedPath { path } => process_path(path.def_id()),
2523+
clean::Type::Path { path } => process_path(path.def_id()),
25242524
clean::Type::Tuple(tys) => {
25252525
work.extend(tys.into_iter());
25262526
}

src/librustdoc/html/render/print_item.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -727,8 +727,8 @@ 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 }, .. }
730+
clean::Type::Path { ref path }
731+
| clean::BorrowedRef { type_: box clean::Type::Path { ref path }, .. }
732732
if !path.is_assoc_ty() =>
733733
{
734734
let did = path.def_id();
@@ -1453,8 +1453,8 @@ fn render_implementor(
14531453
// If there's already another implementor that has the same abridged name, use the
14541454
// full path, for example in `std::iter::ExactSizeIterator`
14551455
let use_absolute = match implementor.inner_impl().for_ {
1456-
clean::ResolvedPath { ref path, .. }
1457-
| clean::BorrowedRef { type_: box clean::ResolvedPath { ref path, .. }, .. }
1456+
clean::Type::Path { ref path, .. }
1457+
| clean::BorrowedRef { type_: box clean::Type::Path { ref path, .. }, .. }
14581458
if !path.is_assoc_ty() =>
14591459
{
14601460
implementor_dups[&path.last()].1

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::Path { 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::Path { 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::Path { 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::Path { 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)