Skip to content

Commit

Permalink
rustdoc: normalise type/field names in clean/rustdoc-json-types/jsond…
Browse files Browse the repository at this point in the history
…oclint
  • Loading branch information
its-the-shrimp committed Aug 7, 2024
1 parent 8b38707 commit 036baf2
Show file tree
Hide file tree
Showing 81 changed files with 433 additions and 419 deletions.
6 changes: 3 additions & 3 deletions src/librustdoc/clean/inline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,10 +104,10 @@ pub(crate) fn try_inline(
})
}
Res::Def(DefKind::ForeignTy, did) => {
record_extern_fqn(cx, did, ItemType::ForeignType);
record_extern_fqn(cx, did, ItemType::ExternType);
cx.with_param_env(did, |cx| {
build_impls(cx, did, attrs_without_docs, &mut ret);
clean::ForeignTypeItem
clean::ExternTypeItem
})
}
// Never inline enum variants but leave them shown as re-exports.
Expand Down Expand Up @@ -679,7 +679,7 @@ fn build_module_items(
// We can use the item's `DefId` directly since the only information ever used
// from it is `DefId.krate`.
item_id: ItemId::DefId(did),
kind: Box::new(clean::ImportItem(clean::Import::new_simple(
kind: Box::new(clean::UseItem(clean::Use::new_simple(
item.ident.name,
clean::ImportSource {
path: clean::Path {
Expand Down
34 changes: 17 additions & 17 deletions src/librustdoc/clean/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -540,7 +540,7 @@ fn clean_generic_param_def<'tcx>(
GenericParamDefKind::Type {
bounds: ThinVec::new(), // These are filled in from the where-clauses.
default: default.map(Box::new),
synthetic,
is_synthetic: synthetic,
},
)
}
Expand All @@ -567,7 +567,7 @@ fn clean_generic_param_def<'tcx>(
} else {
None
},
synthetic,
is_synthetic: synthetic,
},
),
};
Expand Down Expand Up @@ -619,7 +619,7 @@ fn clean_generic_param<'tcx>(
GenericParamDefKind::Type {
bounds,
default: default.map(|t| clean_ty(t, cx)).map(Box::new),
synthetic,
is_synthetic: synthetic,
},
)
}
Expand All @@ -630,7 +630,7 @@ fn clean_generic_param<'tcx>(
default: default.map(|ct| {
Box::new(ty::Const::from_const_arg(cx.tcx, ct, ty::FeedConstTy::No).to_string())
}),
synthetic,
is_synthetic: synthetic,
},
),
};
Expand Down Expand Up @@ -743,7 +743,7 @@ pub(crate) fn clean_generics<'tcx>(
}
}
}
GenericParamDefKind::Type { bounds, synthetic: false, .. } => {
GenericParamDefKind::Type { bounds, is_synthetic: false, .. } => {
if let Some(bound_pred) = bound_predicates.get_mut(&Type::Generic(p.name)) {
// We merge bounds in the `where` clause.
for bound in bounds.drain(..) {
Expand Down Expand Up @@ -1143,7 +1143,7 @@ fn clean_fn_decl_with_args<'tcx>(
decl: &hir::FnDecl<'tcx>,
header: Option<&hir::FnHeader>,
args: Arguments,
) -> FnDecl {
) -> FunctionSignature {
let mut output = match decl.output {
hir::FnRetTy::Return(typ) => clean_ty(typ, cx),
hir::FnRetTy::DefaultReturn(..) => Type::Tuple(Vec::new()),
Expand All @@ -1153,14 +1153,14 @@ fn clean_fn_decl_with_args<'tcx>(
{
output = output.sugared_async_return_type();
}
FnDecl { inputs: args, output, c_variadic: decl.c_variadic }
FunctionSignature { inputs: args, output, is_c_variadic: decl.c_variadic }
}

fn clean_poly_fn_sig<'tcx>(
cx: &mut DocContext<'tcx>,
did: Option<DefId>,
sig: ty::PolyFnSig<'tcx>,
) -> FnDecl {
) -> FunctionSignature {
let mut names = did.map_or(&[] as &[_], |did| cx.tcx.fn_arg_names(did)).iter();

// We assume all empty tuples are default return type. This theoretically can discard `-> ()`,
Expand All @@ -1177,9 +1177,9 @@ fn clean_poly_fn_sig<'tcx>(
output = output.sugared_async_return_type();
}

FnDecl {
FunctionSignature {
output,
c_variadic: sig.skip_binder().c_variadic,
is_c_variadic: sig.skip_binder().c_variadic,
inputs: Arguments {
values: sig
.inputs()
Expand Down Expand Up @@ -2094,7 +2094,7 @@ pub(crate) fn clean_middle_ty<'tcx>(
Type::Path { path }
}
ty::Foreign(did) => {
inline::record_extern_fqn(cx, did, ItemType::ForeignType);
inline::record_extern_fqn(cx, did, ItemType::ExternType);
let path = clean_middle_path(
cx,
did,
Expand Down Expand Up @@ -3052,7 +3052,7 @@ fn clean_use_statement_inner<'tcx>(
return items;
}
}
Import::new_glob(resolve_use_source(cx, path), true)
Use::new_glob(resolve_use_source(cx, path), true)
} else {
if inline_attr.is_none()
&& let Res::Def(DefKind::Mod, did) = path.res
Expand All @@ -3075,15 +3075,15 @@ fn clean_use_statement_inner<'tcx>(
items.push(Item::from_def_id_and_parts(
import_def_id,
None,
ImportItem(Import::new_simple(name, resolve_use_source(cx, path), false)),
UseItem(Use::new_simple(name, resolve_use_source(cx, path), false)),
cx,
));
return items;
}
Import::new_simple(name, resolve_use_source(cx, path), true)
Use::new_simple(name, resolve_use_source(cx, path), true)
};

vec![Item::from_def_id_and_parts(import_def_id, None, ImportItem(inner), cx)]
vec![Item::from_def_id_and_parts(import_def_id, None, UseItem(inner), cx)]
}

fn clean_maybe_renamed_foreign_item<'tcx>(
Expand All @@ -3108,7 +3108,7 @@ fn clean_maybe_renamed_foreign_item<'tcx>(
Static { type_: Box::new(clean_ty(ty, cx)), mutability, expr: None },
safety,
),
hir::ForeignItemKind::Type => ForeignTypeItem,
hir::ForeignItemKind::Type => ExternTypeItem,
};

Item::from_def_id_and_parts(
Expand Down Expand Up @@ -3158,7 +3158,7 @@ fn clean_bound_vars<'tcx>(
kind: GenericParamDefKind::Type {
bounds: ThinVec::new(),
default: None,
synthetic: false,
is_synthetic: false,
},
})
}
Expand Down
44 changes: 22 additions & 22 deletions src/librustdoc/clean/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -546,7 +546,7 @@ impl Item {
self.type_() == ItemType::Union
}
pub(crate) fn is_import(&self) -> bool {
self.type_() == ItemType::Import
self.type_() == ItemType::Use
}
pub(crate) fn is_extern_crate(&self) -> bool {
self.type_() == ItemType::ExternCrate
Expand All @@ -557,7 +557,7 @@ impl Item {
pub(crate) fn is_stripped(&self) -> bool {
match *self.kind {
StrippedItem(..) => true,
ImportItem(ref i) => !i.should_be_displayed,
UseItem(ref i) => !i.should_be_displayed,
_ => false,
}
}
Expand Down Expand Up @@ -816,7 +816,7 @@ pub(crate) enum ItemKind {
/// The crate's name, *not* the name it's imported as.
src: Option<Symbol>,
},
ImportItem(Import),
UseItem(Use),
StructItem(Struct),
UnionItem(Union),
EnumItem(Enum),
Expand All @@ -840,7 +840,7 @@ pub(crate) enum ItemKind {
/// `static`s from an extern block
ForeignStaticItem(Static, hir::Safety),
/// `type`s from an extern block
ForeignTypeItem,
ExternTypeItem,
MacroItem(Macro),
ProcMacroItem(ProcMacro),
PrimitiveItem(PrimitiveType),
Expand Down Expand Up @@ -877,7 +877,7 @@ impl ItemKind {
ImplItem(i) => i.items.iter(),
ModuleItem(m) => m.items.iter(),
ExternCrateItem { .. }
| ImportItem(_)
| UseItem(_)
| FunctionItem(_)
| TypeAliasItem(_)
| StaticItem(_)
Expand All @@ -888,7 +888,7 @@ impl ItemKind {
| StructFieldItem(_)
| ForeignFunctionItem(_, _)
| ForeignStaticItem(_, _)
| ForeignTypeItem
| ExternTypeItem
| MacroItem(_)
| ProcMacroItem(_)
| PrimitiveItem(_)
Expand Down Expand Up @@ -918,7 +918,7 @@ impl ItemKind {
| TraitAliasItem(_)
| ForeignFunctionItem(_, _)
| ForeignStaticItem(_, _)
| ForeignTypeItem
| ExternTypeItem
| MacroItem(_)
| ProcMacroItem(_)
| PrimitiveItem(_)
Expand Down Expand Up @@ -1313,9 +1313,9 @@ impl WherePredicate {
#[derive(Clone, PartialEq, Eq, Debug, Hash)]
pub(crate) enum GenericParamDefKind {
Lifetime { outlives: ThinVec<Lifetime> },
Type { bounds: ThinVec<GenericBound>, default: Option<Box<Type>>, synthetic: bool },
Type { bounds: ThinVec<GenericBound>, default: Option<Box<Type>>, is_synthetic: bool },
// Option<Box<String>> makes this type smaller than `Option<String>` would.
Const { ty: Box<Type>, default: Option<Box<String>>, synthetic: bool },
Const { ty: Box<Type>, default: Option<Box<String>>, is_synthetic: bool },
}

impl GenericParamDefKind {
Expand All @@ -1339,8 +1339,8 @@ impl GenericParamDef {
pub(crate) fn is_synthetic_param(&self) -> bool {
match self.kind {
GenericParamDefKind::Lifetime { .. } => false,
GenericParamDefKind::Const { synthetic: is_host_effect, .. } => is_host_effect,
GenericParamDefKind::Type { synthetic, .. } => synthetic,
GenericParamDefKind::Const { is_synthetic: is_host_effect, .. } => is_host_effect,
GenericParamDefKind::Type { is_synthetic, .. } => is_synthetic,
}
}

Expand Down Expand Up @@ -1371,18 +1371,18 @@ impl Generics {

#[derive(Clone, Debug)]
pub(crate) struct Function {
pub(crate) decl: FnDecl,
pub(crate) decl: FunctionSignature,
pub(crate) generics: Generics,
}

#[derive(Clone, PartialEq, Eq, Debug, Hash)]
pub(crate) struct FnDecl {
pub(crate) struct FunctionSignature {
pub(crate) inputs: Arguments,
pub(crate) output: Type,
pub(crate) c_variadic: bool,
pub(crate) is_c_variadic: bool,
}

impl FnDecl {
impl FunctionSignature {
pub(crate) fn receiver_type(&self) -> Option<&Type> {
self.inputs.values.get(0).and_then(|v| v.to_receiver())
}
Expand Down Expand Up @@ -2321,7 +2321,7 @@ pub(crate) struct TypeAlias {
pub(crate) struct BareFunctionDecl {
pub(crate) safety: hir::Safety,
pub(crate) generic_params: Vec<GenericParamDef>,
pub(crate) decl: FnDecl,
pub(crate) decl: FunctionSignature,
pub(crate) abi: Abi,
}

Expand Down Expand Up @@ -2478,24 +2478,24 @@ impl ImplKind {
}

#[derive(Clone, Debug)]
pub(crate) struct Import {
pub(crate) kind: ImportKind,
pub(crate) struct Use {
pub(crate) kind: UseKind,
/// The item being re-exported.
pub(crate) source: ImportSource,
pub(crate) should_be_displayed: bool,
}

impl Import {
impl Use {
pub(crate) fn new_simple(
name: Symbol,
source: ImportSource,
should_be_displayed: bool,
) -> Self {
Self { kind: ImportKind::Simple(name), source, should_be_displayed }
Self { kind: UseKind::Simple(name), source, should_be_displayed }
}

pub(crate) fn new_glob(source: ImportSource, should_be_displayed: bool) -> Self {
Self { kind: ImportKind::Glob, source, should_be_displayed }
Self { kind: UseKind::Glob, source, should_be_displayed }
}

pub(crate) fn imported_item_is_doc_hidden(&self, tcx: TyCtxt<'_>) -> bool {
Expand All @@ -2504,7 +2504,7 @@ impl Import {
}

#[derive(Clone, Debug)]
pub(crate) enum ImportKind {
pub(crate) enum UseKind {
// use source as str;
Simple(Symbol),
// use source::*;
Expand Down
4 changes: 2 additions & 2 deletions src/librustdoc/fold.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ pub(crate) trait DocFolder: Sized {
TypeAliasItem(typealias)
}
ExternCrateItem { src: _ }
| ImportItem(_)
| UseItem(_)
| FunctionItem(_)
| StaticItem(_)
| ConstantItem(..)
Expand All @@ -85,7 +85,7 @@ pub(crate) trait DocFolder: Sized {
| StructFieldItem(_)
| ForeignFunctionItem(..)
| ForeignStaticItem(..)
| ForeignTypeItem
| ExternTypeItem
| MacroItem(_)
| ProcMacroItem(_)
| PrimitiveItem(_)
Expand Down
12 changes: 6 additions & 6 deletions src/librustdoc/formats/cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -262,8 +262,8 @@ impl<'a, 'tcx> DocFolder for CacheBuilder<'a, 'tcx> {
// Index this method for searching later on.
let search_name = if !item.is_stripped() {
item.name.or_else(|| {
if let clean::ImportItem(ref i) = *item.kind
&& let clean::ImportKind::Simple(s) = i.kind
if let clean::UseItem(ref i) = *item.kind
&& let clean::UseKind::Simple(s) = i.kind
{
Some(s)
} else {
Expand Down Expand Up @@ -299,7 +299,7 @@ impl<'a, 'tcx> DocFolder for CacheBuilder<'a, 'tcx> {
| clean::ConstantItem(..)
| clean::StaticItem(..)
| clean::UnionItem(..)
| clean::ForeignTypeItem
| clean::ExternTypeItem
| clean::MacroItem(..)
| clean::ProcMacroItem(..)
| clean::VariantItem(..) => {
Expand Down Expand Up @@ -330,7 +330,7 @@ impl<'a, 'tcx> DocFolder for CacheBuilder<'a, 'tcx> {
}

clean::ExternCrateItem { .. }
| clean::ImportItem(..)
| clean::UseItem(..)
| clean::ImplItem(..)
| clean::TyMethodItem(..)
| clean::MethodItem(..)
Expand All @@ -352,7 +352,7 @@ impl<'a, 'tcx> DocFolder for CacheBuilder<'a, 'tcx> {
let (item, parent_pushed) = match *item.kind {
clean::TraitItem(..)
| clean::EnumItem(..)
| clean::ForeignTypeItem
| clean::ExternTypeItem
| clean::StructItem(..)
| clean::UnionItem(..)
| clean::VariantItem(..)
Expand Down Expand Up @@ -528,7 +528,7 @@ fn add_item_to_search_index(tcx: TyCtxt<'_>, cache: &mut Cache, item: &clean::It
// - It's got the same name
// - Both of them have the same exact path
let defid = match &*item.kind {
clean::ItemKind::ImportItem(import) => import.source.did.unwrap_or(item_def_id),
clean::ItemKind::UseItem(import) => import.source.did.unwrap_or(item_def_id),
_ => item_def_id,
};
let path = join_with_double_colon(parent_path);
Expand Down
Loading

0 comments on commit 036baf2

Please sign in to comment.