Skip to content

Commit cd705f8

Browse files
committed
Auto merge of #162916 - fmease:rustdoc-better-item-kinds, r=<try>
[WIP] rustdoc: Improve `ItemKind`
2 parents 52d0fd8 + 628da35 commit cd705f8

34 files changed

Lines changed: 913 additions & 1194 deletions

‎src/librustdoc/calculate_doc_coverage.rs‎

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,15 @@ use rustc_span::{FileName, RemapPathScopeComponents};
1515
use serde::Serialize;
1616
use tracing::debug;
1717

18+
use crate::clean::{self, ItemKind};
1819
use crate::config::{OutputFormat, RenderOptions};
1920
use crate::core::DocContext;
2021
use crate::docfs::PathError;
2122
use crate::error::Error;
2223
use crate::html::markdown::{ErrorCodes, find_testable_code};
2324
use crate::passes::check_doc_test_visibility::{Tests, should_have_doc_example};
25+
use crate::try_err;
2426
use crate::visit::DocVisitor;
25-
use crate::{clean, try_err};
2627

2728
pub(crate) fn run(
2829
krate: &clean::Crate,
@@ -219,21 +220,17 @@ impl DocVisitor<'_> for CoverageCalculator<'_, '_> {
219220
}
220221

221222
match i.kind {
222-
clean::StrippedItem(..) => {
223-
// don't count items in stripped modules
224-
return;
225-
}
226-
clean::PlaceholderImplItem => {
227-
// The "real" impl items are handled below.
228-
return;
229-
}
223+
// Don't count items in stripped modules.
224+
ItemKind::Stripped(..) => return,
225+
// The "real" impl items are handled below.
226+
ItemKind::PlaceholderImpl => return,
230227
// docs on `use` and `extern crate` statements are not displayed, so they're not
231228
// worth counting
232-
clean::ImportItem(..) | clean::ExternCrateItem { .. } => {}
229+
ItemKind::Import(..) | ItemKind::ExternCrate { .. } => {}
233230
// Don't count trait impls, the missing-docs lint doesn't so we shouldn't either.
234231
// Inherent impls *can* be documented, and those docs show up, but in most cases it
235232
// doesn't make sense, as all methods on a type are in one single impl block
236-
clean::ImplItem(_) => {}
233+
ItemKind::Impl(_) => {}
237234
_ => {
238235
let has_docs = !i.attrs.doc_strings.is_empty();
239236
let mut tests = Tests { found_tests: 0 };

‎src/librustdoc/clean/auto_trait.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ fn synthesize_auto_trait_impl<'tcx>(
121121
name: None,
122122
attrs: Default::default(),
123123
stability: None,
124-
kind: clean::ImplItem(Box::new(clean::Impl {
124+
kind: clean::ItemKind::Impl(Box::new(clean::Impl {
125125
safety: hir::Safety::Safe,
126126
generics,
127127
trait_: Some(clean_trait_ref_with_constraints(cx, trait_ref, ThinVec::new())),

‎src/librustdoc/clean/blanket_impl.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ pub(crate) fn synthesize_blanket_impls(
8989
item_id: clean::ItemId::Blanket { impl_id: impl_def_id, for_: item_def_id },
9090
attrs: Default::default(),
9191
stability: None,
92-
kind: clean::ImplItem(Box::new(clean::Impl {
92+
kind: clean::ItemKind::Impl(Box::new(clean::Impl {
9393
safety: hir::Safety::Safe,
9494
generics: clean_ty_generics(cx, impl_def_id),
9595
// FIXME(eddyb) compute both `trait_` and `for_` from

‎src/librustdoc/clean/inline.rs‎

Lines changed: 25 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ use tracing::{debug, instrument, trace};
1818

1919
use super::{Item, extract_cfg_from_attrs};
2020
use crate::clean::{
21-
self, Attributes, CfgInfo, ImplKind, ItemId, Type, clean_bound_vars, clean_generics,
21+
self, Attributes, CfgInfo, ImplKind, ItemId, ItemKind, Type, clean_bound_vars, clean_generics,
2222
clean_impl_item, clean_middle_assoc_item, clean_middle_field, clean_middle_ty,
2323
clean_poly_fn_sig, clean_trait_ref_with_constraints, clean_ty, clean_ty_alias_inner_type,
2424
clean_ty_generics, clean_variant_def, utils,
@@ -47,7 +47,7 @@ pub(crate) fn try_inline(
4747
) -> Option<Vec<clean::Item>> {
4848
fn try_inline_inner(
4949
cx: &mut DocContext<'_>,
50-
kind: clean::ItemKind,
50+
kind: ItemKind,
5151
did: DefId,
5252
name: Symbol,
5353
import_def_id: Option<LocalDefId>,
@@ -87,52 +87,52 @@ pub(crate) fn try_inline(
8787
record_extern_fqn(cx, did, ItemType::Trait);
8888
cx.with_param_env(did, |cx| {
8989
build_impls(cx, did, attrs_without_docs, &mut ret);
90-
clean::TraitItem(Box::new(build_trait(cx, did)))
90+
ItemKind::Trait(Box::new(build_trait(cx, did)))
9191
})
9292
}
9393
Res::Def(DefKind::TraitAlias, did) => {
9494
record_extern_fqn(cx, did, ItemType::TraitAlias);
95-
cx.with_param_env(did, |cx| clean::TraitAliasItem(build_trait_alias(cx, did)))
95+
cx.with_param_env(did, |cx| ItemKind::TraitAlias(build_trait_alias(cx, did)))
9696
}
9797
Res::Def(DefKind::Fn, did) => {
9898
record_extern_fqn(cx, did, ItemType::Function);
9999
cx.with_param_env(did, |cx| {
100-
clean::enter_impl_trait(cx, |cx| clean::FunctionItem(build_function(cx, did)))
100+
clean::enter_impl_trait(cx, |cx| ItemKind::Fn(build_function(cx, did)))
101101
})
102102
}
103103
Res::Def(DefKind::Struct, did) => {
104104
record_extern_fqn(cx, did, ItemType::Struct);
105105
cx.with_param_env(did, |cx| {
106106
build_impls(cx, did, attrs_without_docs, &mut ret);
107-
clean::StructItem(build_struct(cx, did))
107+
ItemKind::Struct(build_struct(cx, did))
108108
})
109109
}
110110
Res::Def(DefKind::Union, did) => {
111111
record_extern_fqn(cx, did, ItemType::Union);
112112
cx.with_param_env(did, |cx| {
113113
build_impls(cx, did, attrs_without_docs, &mut ret);
114-
clean::UnionItem(build_union(cx, did))
114+
ItemKind::Union(build_union(cx, did))
115115
})
116116
}
117117
Res::Def(DefKind::TyAlias, did) => {
118118
record_extern_fqn(cx, did, ItemType::TypeAlias);
119119
cx.with_param_env(did, |cx| {
120120
build_impls(cx, did, attrs_without_docs, &mut ret);
121-
clean::TypeAliasItem(build_type_alias(cx, did, &mut ret))
121+
ItemKind::TyAlias(build_type_alias(cx, did, &mut ret))
122122
})
123123
}
124124
Res::Def(DefKind::Enum, did) => {
125125
record_extern_fqn(cx, did, ItemType::Enum);
126126
cx.with_param_env(did, |cx| {
127127
build_impls(cx, did, attrs_without_docs, &mut ret);
128-
clean::EnumItem(build_enum(cx, did))
128+
ItemKind::Enum(build_enum(cx, did))
129129
})
130130
}
131131
Res::Def(DefKind::ForeignTy, did) => {
132132
record_extern_fqn(cx, did, ItemType::ForeignType);
133133
cx.with_param_env(did, |cx| {
134134
build_impls(cx, did, attrs_without_docs, &mut ret);
135-
clean::ForeignTypeItem
135+
ItemKind::ForeignTy
136136
})
137137
}
138138
// Never inline enum variants but leave them shown as re-exports.
@@ -142,19 +142,19 @@ pub(crate) fn try_inline(
142142
Res::Def(DefKind::Ctor(..), _) | Res::SelfCtor(..) => return Some(Vec::new()),
143143
Res::Def(DefKind::Mod, did) => {
144144
record_extern_fqn(cx, did, ItemType::Module);
145-
clean::ModuleItem(build_module(cx, did, name, visited))
145+
ItemKind::Module(build_module(cx, did, name, visited))
146146
}
147147
Res::Def(DefKind::Static { .. }, did) => {
148148
record_extern_fqn(cx, did, ItemType::Static);
149149
cx.with_param_env(did, |cx| {
150-
clean::StaticItem(build_static(cx, did, cx.tcx.is_mutable_static(did)))
150+
ItemKind::Static(build_static(cx, did, cx.tcx.is_mutable_static(did)))
151151
})
152152
}
153153
Res::Def(DefKind::Const, did) => {
154154
record_extern_fqn(cx, did, ItemType::Constant);
155155
cx.with_param_env(did, |cx| {
156156
let ct = build_const_item(cx, did);
157-
clean::ConstantItem(Box::new(ct))
157+
ItemKind::Const(Box::new(ct))
158158
})
159159
}
160160
Res::Def(DefKind::Macro(kinds), did) => {
@@ -388,12 +388,7 @@ fn build_type_alias(
388388
let type_ = clean_middle_ty(ty::Binder::dummy(ty), cx, Some(did), None);
389389
let inner_type = clean_ty_alias_inner_type(ty, cx, ret);
390390

391-
Box::new(clean::TypeAlias {
392-
type_,
393-
generics: clean_ty_generics(cx, did),
394-
inner_type,
395-
item_type: None,
396-
})
391+
Box::new(clean::TypeAlias { type_, generics: clean_ty_generics(cx, did), inner_type })
397392
}
398393

399394
/// Builds all inherent implementations of an ADT (struct/union/enum) or Trait item/path/reexport.
@@ -650,7 +645,7 @@ pub(crate) fn build_impl(
650645
ret.push(clean::Item::from_def_id_and_attrs_and_parts(
651646
did,
652647
None,
653-
clean::ImplItem(Box::new(clean::Impl {
648+
ItemKind::Impl(Box::new(clean::Impl {
654649
safety: hir::Safety::Safe,
655650
generics,
656651
trait_,
@@ -756,7 +751,7 @@ fn build_module_items(
756751
item_id: ItemId::DefId(module_def_id),
757752
attrs: Default::default(),
758753
stability: None,
759-
kind: clean::ImportItem(clean::Import::new_simple(
754+
kind: ItemKind::Import(clean::Import::new_simple(
760755
item.ident.name,
761756
clean::ImportSource {
762757
path: clean::Path {
@@ -795,7 +790,7 @@ fn build_module_items(
795790
let item = Item::from_def_id_and_parts(
796791
module_def_id,
797792
None,
798-
clean::ImportItem(clean::Import::new_simple(
793+
ItemKind::Import(clean::Import::new_simple(
799794
item.ident.name,
800795
clean::ImportSource {
801796
path: clean::Path {
@@ -850,7 +845,7 @@ fn build_const_item(cx: &mut DocContext<'_>, def_id: DefId) -> clean::Constant {
850845
None,
851846
None,
852847
);
853-
clean::Constant { generics, type_: ty, kind: clean::ConstantKind::Extern { def_id } }
848+
clean::Constant { generics, ty, rhs: clean::ConstantKind::Extern { def_id } }
854849
}
855850

856851
fn build_static(cx: &mut DocContext<'_>, did: DefId, mutable: bool) -> clean::Static {
@@ -866,23 +861,17 @@ fn build_static(cx: &mut DocContext<'_>, did: DefId, mutable: bool) -> clean::St
866861
}
867862
}
868863

869-
fn build_macro(
870-
tcx: TyCtxt<'_>,
871-
def_id: DefId,
872-
name: Symbol,
873-
macro_kinds: MacroKinds,
874-
) -> clean::ItemKind {
864+
fn build_macro(tcx: TyCtxt<'_>, def_id: DefId, name: Symbol, macro_kinds: MacroKinds) -> ItemKind {
875865
match CStore::from_tcx(tcx).load_macro_untracked(tcx, def_id) {
876866
LoadedMacro::MacroDef { def, .. } => match macro_kinds {
877-
MacroKinds::DERIVE => clean::ProcMacroItem(clean::ProcMacro {
867+
MacroKinds::DERIVE => ItemKind::ProcMacro(clean::ProcMacro {
878868
kind: MacroKind::Derive,
879869
helpers: Vec::new(),
880870
}),
881-
MacroKinds::ATTR => clean::ProcMacroItem(clean::ProcMacro {
882-
kind: MacroKind::Attr,
883-
helpers: Vec::new(),
884-
}),
885-
_ => clean::MacroItem(
871+
MacroKinds::ATTR => {
872+
ItemKind::ProcMacro(clean::ProcMacro { kind: MacroKind::Attr, helpers: Vec::new() })
873+
}
874+
_ => ItemKind::DeclMacro(
886875
clean::Macro {
887876
source: utils::display_macro_source(tcx, name, &def),
888877
macro_rules: def.macro_rules,
@@ -898,7 +887,7 @@ fn build_macro(
898887
MacroKinds::DERIVE => MacroKind::Derive,
899888
_ => unreachable!(),
900889
};
901-
clean::ProcMacroItem(clean::ProcMacro { kind, helpers: ext.helper_attrs })
890+
ItemKind::ProcMacro(clean::ProcMacro { kind, helpers: ext.helper_attrs })
902891
}
903892
}
904893
}

0 commit comments

Comments
 (0)