Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 8 additions & 11 deletions src/librustdoc/calculate_doc_coverage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,15 @@ use rustc_span::{FileName, RemapPathScopeComponents};
use serde::Serialize;
use tracing::debug;

use crate::clean::{self, ItemKind};
use crate::config::{OutputFormat, RenderOptions};
use crate::core::DocContext;
use crate::docfs::PathError;
use crate::error::Error;
use crate::html::markdown::{ErrorCodes, find_testable_code};
use crate::passes::check_doc_test_visibility::{Tests, should_have_doc_example};
use crate::try_err;
use crate::visit::DocVisitor;
use crate::{clean, try_err};

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

match i.kind {
clean::StrippedItem(..) => {
// don't count items in stripped modules
return;
}
clean::PlaceholderImplItem => {
// The "real" impl items are handled below.
return;
}
// Don't count items in stripped modules.
ItemKind::Stripped(..) => return,
// The "real" impl items are handled below.
ItemKind::PlaceholderImpl => return,
// docs on `use` and `extern crate` statements are not displayed, so they're not
// worth counting
clean::ImportItem(..) | clean::ExternCrateItem { .. } => {}
ItemKind::Import(..) | ItemKind::ExternCrate { .. } => {}
// Don't count trait impls, the missing-docs lint doesn't so we shouldn't either.
// Inherent impls *can* be documented, and those docs show up, but in most cases it
// doesn't make sense, as all methods on a type are in one single impl block
clean::ImplItem(_) => {}
ItemKind::Impl(_) => {}
_ => {
let has_docs = !i.attrs.doc_strings.is_empty();
let mut tests = Tests { found_tests: 0 };
Expand Down
2 changes: 1 addition & 1 deletion src/librustdoc/clean/auto_trait.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ fn synthesize_auto_trait_impl<'tcx>(
name: None,
attrs: Default::default(),
stability: None,
kind: clean::ImplItem(Box::new(clean::Impl {
kind: clean::ItemKind::Impl(Box::new(clean::Impl {
safety: hir::Safety::Safe,
generics,
trait_: Some(clean_trait_ref_with_constraints(cx, trait_ref, ThinVec::new())),
Expand Down
2 changes: 1 addition & 1 deletion src/librustdoc/clean/blanket_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ pub(crate) fn synthesize_blanket_impls(
item_id: clean::ItemId::Blanket { impl_id: impl_def_id, for_: item_def_id },
attrs: Default::default(),
stability: None,
kind: clean::ImplItem(Box::new(clean::Impl {
kind: clean::ItemKind::Impl(Box::new(clean::Impl {
safety: hir::Safety::Safe,
generics: clean_ty_generics(cx, impl_def_id),
// FIXME(eddyb) compute both `trait_` and `for_` from
Expand Down
54 changes: 24 additions & 30 deletions src/librustdoc/clean/inline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ use tracing::{debug, instrument, trace};

use super::{Item, extract_cfg_from_attrs};
use crate::clean::{
self, Attributes, CfgInfo, ImplKind, ItemId, Type, clean_bound_vars, clean_generics,
self, Attributes, CfgInfo, ImplKind, ItemId, ItemKind, Type, clean_bound_vars, clean_generics,
clean_impl_item, clean_middle_assoc_item, clean_middle_field, clean_middle_ty,
clean_poly_fn_sig, clean_trait_ref_with_constraints, clean_ty, clean_ty_alias_inner_type,
clean_ty_generics, clean_variant_def, utils,
Expand Down Expand Up @@ -47,7 +47,7 @@ pub(crate) fn try_inline(
) -> Option<Vec<clean::Item>> {
fn try_inline_inner(
cx: &mut DocContext<'_>,
kind: clean::ItemKind,
kind: ItemKind,
did: DefId,
name: Symbol,
import_def_id: Option<LocalDefId>,
Expand Down Expand Up @@ -87,52 +87,52 @@ pub(crate) fn try_inline(
record_extern_fqn(cx, did, ItemType::Trait);
cx.with_param_env(did, |cx| {
build_impls(cx, did, attrs_without_docs, &mut ret);
clean::TraitItem(Box::new(build_trait(cx, did)))
ItemKind::Trait(Box::new(build_trait(cx, did)))
})
}
Res::Def(DefKind::TraitAlias, did) => {
record_extern_fqn(cx, did, ItemType::TraitAlias);
cx.with_param_env(did, |cx| clean::TraitAliasItem(build_trait_alias(cx, did)))
cx.with_param_env(did, |cx| ItemKind::TraitAlias(build_trait_alias(cx, did)))
}
Res::Def(DefKind::Fn, did) => {
record_extern_fqn(cx, did, ItemType::Function);
cx.with_param_env(did, |cx| {
clean::enter_impl_trait(cx, |cx| clean::FunctionItem(build_function(cx, did)))
clean::enter_impl_trait(cx, |cx| ItemKind::Fn(build_function(cx, did)))
})
}
Res::Def(DefKind::Struct, did) => {
record_extern_fqn(cx, did, ItemType::Struct);
cx.with_param_env(did, |cx| {
build_impls(cx, did, attrs_without_docs, &mut ret);
clean::StructItem(build_struct(cx, did))
ItemKind::Struct(build_struct(cx, did))
})
}
Res::Def(DefKind::Union, did) => {
record_extern_fqn(cx, did, ItemType::Union);
cx.with_param_env(did, |cx| {
build_impls(cx, did, attrs_without_docs, &mut ret);
clean::UnionItem(build_union(cx, did))
ItemKind::Union(build_union(cx, did))
})
}
Res::Def(DefKind::TyAlias, did) => {
record_extern_fqn(cx, did, ItemType::TypeAlias);
cx.with_param_env(did, |cx| {
build_impls(cx, did, attrs_without_docs, &mut ret);
clean::TypeAliasItem(build_type_alias(cx, did, &mut ret))
ItemKind::TyAlias(build_type_alias(cx, did, &mut ret))
})
}
Res::Def(DefKind::Enum, did) => {
record_extern_fqn(cx, did, ItemType::Enum);
cx.with_param_env(did, |cx| {
build_impls(cx, did, attrs_without_docs, &mut ret);
clean::EnumItem(build_enum(cx, did))
ItemKind::Enum(build_enum(cx, did))
})
}
Res::Def(DefKind::ForeignTy, did) => {
record_extern_fqn(cx, did, ItemType::ForeignType);
cx.with_param_env(did, |cx| {
build_impls(cx, did, attrs_without_docs, &mut ret);
clean::ForeignTypeItem
ItemKind::ForeignTy
})
}
// Never inline enum variants but leave them shown as re-exports.
Expand All @@ -142,19 +142,19 @@ pub(crate) fn try_inline(
Res::Def(DefKind::Ctor(..), _) | Res::SelfCtor(..) => return Some(Vec::new()),
Res::Def(DefKind::Mod, did) => {
record_extern_fqn(cx, did, ItemType::Module);
clean::ModuleItem(build_module(cx, did, name, visited))
ItemKind::Module(build_module(cx, did, name, visited))
}
Res::Def(DefKind::Static { .. }, did) => {
record_extern_fqn(cx, did, ItemType::Static);
cx.with_param_env(did, |cx| {
clean::StaticItem(build_static(cx, did, cx.tcx.is_mutable_static(did)))
ItemKind::Static(build_static(cx, did, cx.tcx.is_mutable_static(did)))
})
}
Res::Def(DefKind::Const, did) => {
record_extern_fqn(cx, did, ItemType::Constant);
cx.with_param_env(did, |cx| {
let ct = build_const_item(cx, did);
clean::ConstantItem(Box::new(ct))
ItemKind::Const(Box::new(ct))
})
}
Res::Def(DefKind::Macro(kinds), did) => {
Expand Down Expand Up @@ -650,7 +650,7 @@ pub(crate) fn build_impl(
ret.push(clean::Item::from_def_id_and_attrs_and_parts(
did,
None,
clean::ImplItem(Box::new(clean::Impl {
ItemKind::Impl(Box::new(clean::Impl {
safety: hir::Safety::Safe,
generics,
trait_,
Expand Down Expand Up @@ -756,7 +756,7 @@ fn build_module_items(
item_id: ItemId::DefId(module_def_id),
attrs: Default::default(),
stability: None,
kind: clean::ImportItem(clean::Import::new_simple(
kind: ItemKind::Import(clean::Import::new_simple(
item.ident.name,
clean::ImportSource {
path: clean::Path {
Expand Down Expand Up @@ -795,7 +795,7 @@ fn build_module_items(
let item = Item::from_def_id_and_parts(
module_def_id,
None,
clean::ImportItem(clean::Import::new_simple(
ItemKind::Import(clean::Import::new_simple(
item.ident.name,
clean::ImportSource {
path: clean::Path {
Expand Down Expand Up @@ -850,7 +850,7 @@ fn build_const_item(cx: &mut DocContext<'_>, def_id: DefId) -> clean::Constant {
None,
None,
);
clean::Constant { generics, type_: ty, kind: clean::ConstantKind::Extern { def_id } }
clean::Constant { generics, ty, rhs: clean::ConstantKind::Extern { def_id } }
}

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

fn build_macro(
tcx: TyCtxt<'_>,
def_id: DefId,
name: Symbol,
macro_kinds: MacroKinds,
) -> clean::ItemKind {
fn build_macro(tcx: TyCtxt<'_>, def_id: DefId, name: Symbol, macro_kinds: MacroKinds) -> ItemKind {
match CStore::from_tcx(tcx).load_macro_untracked(tcx, def_id) {
LoadedMacro::MacroDef { def, .. } => match macro_kinds {
MacroKinds::DERIVE => clean::ProcMacroItem(clean::ProcMacro {
MacroKinds::DERIVE => ItemKind::ProcMacro(clean::ProcMacro {
kind: MacroKind::Derive,
helpers: Vec::new(),
}),
MacroKinds::ATTR => clean::ProcMacroItem(clean::ProcMacro {
kind: MacroKind::Attr,
helpers: Vec::new(),
}),
_ => clean::MacroItem(
MacroKinds::ATTR => {
ItemKind::ProcMacro(clean::ProcMacro { kind: MacroKind::Attr, helpers: Vec::new() })
}
_ => ItemKind::DeclMacro(
clean::Macro {
source: utils::display_macro_source(tcx, name, &def),
macro_rules: def.macro_rules,
Expand All @@ -898,7 +892,7 @@ fn build_macro(
MacroKinds::DERIVE => MacroKind::Derive,
_ => unreachable!(),
};
clean::ProcMacroItem(clean::ProcMacro { kind, helpers: ext.helper_attrs })
ItemKind::ProcMacro(clean::ProcMacro { kind, helpers: ext.helper_attrs })
}
}
}
Expand Down
Loading
Loading