Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Get rid of rustdoc::doctree #78082

Closed
wants to merge 27 commits into from
Closed
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
776 changes: 381 additions & 395 deletions src/librustdoc/clean/mod.rs

Large diffs are not rendered by default.

10 changes: 5 additions & 5 deletions src/librustdoc/clean/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ crate fn krate(mut cx: &mut DocContext<'_>) -> Crate {
use crate::visit_lib::LibEmbargoVisitor;

let krate = cx.tcx.hir().krate();
let module = crate::visit_ast::RustdocVisitor::new(&mut cx).visit(krate);
//let module = crate::visit_ast::RustdocVisitor::new(&mut cx).visit(krate);

let mut r = cx.renderinfo.get_mut();
r.deref_trait_did = cx.tcx.lang_items().deref_trait();
Expand All @@ -41,10 +41,10 @@ crate fn krate(mut cx: &mut DocContext<'_>) -> Crate {

// Clean the crate, translating the entire librustc_ast AST to one that is
// understood by rustdoc.
let mut module = module.clean(cx);
let mut krate = krate.clean(cx);
let mut masked_crates = FxHashSet::default();

match module.kind {
match krate.kind {
ItemKind::ModuleItem(ref module) => {
for it in &module.items {
// `compiler_builtins` should be masked too, but we can't apply
Expand All @@ -62,7 +62,7 @@ crate fn krate(mut cx: &mut DocContext<'_>) -> Crate {

let ExternalCrate { name, src, primitives, keywords, .. } = LOCAL_CRATE.clean(cx);
{
let m = match module.kind {
let m = match krate.kind {
ItemKind::ModuleItem(ref mut m) => m,
_ => unreachable!(),
};
Expand Down Expand Up @@ -92,7 +92,7 @@ crate fn krate(mut cx: &mut DocContext<'_>) -> Crate {
name,
version: None,
src,
module: Some(module),
module: Some(krate),
externs,
primitives,
external_traits: cx.external_traits.clone(),
Expand Down
175 changes: 0 additions & 175 deletions src/librustdoc/doctree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,64 +7,6 @@ use rustc_span::hygiene::MacroKind;
use rustc_span::{self, Span, Symbol};

use rustc_hir as hir;
use rustc_hir::def_id::CrateNum;
use rustc_hir::HirId;

crate struct Module<'hir> {
crate name: Option<Symbol>,
crate attrs: &'hir [ast::Attribute],
crate where_outer: Span,
crate where_inner: Span,
crate extern_crates: Vec<ExternCrate<'hir>>,
crate imports: Vec<Import<'hir>>,
crate structs: Vec<Struct<'hir>>,
crate unions: Vec<Union<'hir>>,
crate enums: Vec<Enum<'hir>>,
crate fns: Vec<Function<'hir>>,
crate mods: Vec<Module<'hir>>,
crate id: hir::HirId,
crate typedefs: Vec<Typedef<'hir>>,
crate opaque_tys: Vec<OpaqueTy<'hir>>,
crate statics: Vec<Static<'hir>>,
crate constants: Vec<Constant<'hir>>,
crate traits: Vec<Trait<'hir>>,
crate impls: Vec<Impl<'hir>>,
crate foreigns: Vec<ForeignItem<'hir>>,
crate macros: Vec<Macro>,
crate proc_macros: Vec<ProcMacro>,
crate trait_aliases: Vec<TraitAlias<'hir>>,
crate is_crate: bool,
}

impl Module<'hir> {
crate fn new(name: Option<Symbol>, attrs: &'hir [ast::Attribute]) -> Module<'hir> {
Module {
name,
id: hir::CRATE_HIR_ID,
where_outer: rustc_span::DUMMY_SP,
where_inner: rustc_span::DUMMY_SP,
attrs,
extern_crates: Vec::new(),
imports: Vec::new(),
structs: Vec::new(),
unions: Vec::new(),
enums: Vec::new(),
fns: Vec::new(),
mods: Vec::new(),
typedefs: Vec::new(),
opaque_tys: Vec::new(),
statics: Vec::new(),
constants: Vec::new(),
traits: Vec::new(),
impls: Vec::new(),
foreigns: Vec::new(),
macros: Vec::new(),
proc_macros: Vec::new(),
trait_aliases: Vec::new(),
is_crate: false,
}
}
}

#[derive(Debug, Clone, Copy)]
crate enum StructType {
Expand All @@ -76,57 +18,6 @@ crate enum StructType {
Unit,
}

crate struct Struct<'hir> {
crate id: hir::HirId,
crate struct_type: StructType,
crate name: Symbol,
crate generics: &'hir hir::Generics<'hir>,
crate fields: &'hir [hir::StructField<'hir>],
}

crate struct Union<'hir> {
crate id: hir::HirId,
crate struct_type: StructType,
crate name: Symbol,
crate generics: &'hir hir::Generics<'hir>,
crate fields: &'hir [hir::StructField<'hir>],
}

crate struct Enum<'hir> {
crate variants: Vec<Variant<'hir>>,
crate generics: &'hir hir::Generics<'hir>,
crate id: hir::HirId,
crate name: Symbol,
}

crate struct Variant<'hir> {
crate name: Symbol,
crate id: hir::HirId,
crate def: &'hir hir::VariantData<'hir>,
}

crate struct Function<'hir> {
crate decl: &'hir hir::FnDecl<'hir>,
crate id: hir::HirId,
crate name: Symbol,
crate header: hir::FnHeader,
crate generics: &'hir hir::Generics<'hir>,
crate body: hir::BodyId,
}

crate struct Typedef<'hir> {
crate ty: &'hir hir::Ty<'hir>,
crate gen: &'hir hir::Generics<'hir>,
crate name: Symbol,
crate id: hir::HirId,
}

crate struct OpaqueTy<'hir> {
crate opaque_ty: &'hir hir::OpaqueTy<'hir>,
crate name: Symbol,
crate id: hir::HirId,
}

#[derive(Debug)]
crate struct Static<'hir> {
crate type_: &'hir hir::Ty<'hir>,
Expand All @@ -139,72 +30,6 @@ crate struct Static<'hir> {
crate span: Span,
}

crate struct Constant<'hir> {
crate type_: &'hir hir::Ty<'hir>,
crate expr: hir::BodyId,
crate name: Symbol,
crate id: hir::HirId,
}

crate struct Trait<'hir> {
crate is_auto: hir::IsAuto,
crate unsafety: hir::Unsafety,
crate name: Symbol,
crate items: Vec<&'hir hir::TraitItem<'hir>>,
crate generics: &'hir hir::Generics<'hir>,
crate bounds: &'hir [hir::GenericBound<'hir>],
crate attrs: &'hir [ast::Attribute],
crate id: hir::HirId,
}

crate struct TraitAlias<'hir> {
crate name: Symbol,
crate generics: &'hir hir::Generics<'hir>,
crate bounds: &'hir [hir::GenericBound<'hir>],
crate id: hir::HirId,
}

#[derive(Debug)]
crate struct Impl<'hir> {
crate unsafety: hir::Unsafety,
crate polarity: hir::ImplPolarity,
crate defaultness: hir::Defaultness,
crate constness: hir::Constness,
crate generics: &'hir hir::Generics<'hir>,
crate trait_: &'hir Option<hir::TraitRef<'hir>>,
crate for_: &'hir hir::Ty<'hir>,
crate items: Vec<&'hir hir::ImplItem<'hir>>,
crate attrs: &'hir [ast::Attribute],
crate span: Span,
crate vis: &'hir hir::Visibility<'hir>,
crate id: hir::HirId,
}

crate struct ForeignItem<'hir> {
crate id: hir::HirId,
crate name: Symbol,
crate kind: &'hir hir::ForeignItemKind<'hir>,
}

// For Macro we store the DefId instead of the NodeId, since we also create
// these imported macro_rules (which only have a DUMMY_NODE_ID).
crate struct Macro {
crate name: Symbol,
crate def_id: hir::def_id::DefId,
crate matchers: Vec<Span>,
crate imported_from: Option<Symbol>,
}

crate struct ExternCrate<'hir> {
crate name: Symbol,
crate hir_id: HirId,
crate cnum: CrateNum,
crate path: Option<String>,
crate vis: &'hir hir::Visibility<'hir>,
crate attrs: &'hir [ast::Attribute],
crate span: Span,
}

#[derive(Debug)]
crate struct Import<'hir> {
crate name: Symbol,
Expand Down
5 changes: 3 additions & 2 deletions src/librustdoc/formats/cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,8 @@ impl DocFolder for Cache {
| clean::StructFieldItem(..)
| clean::VariantItem(..) => (
(
Some(*self.parent_stack.last().expect("parent_stack is empty")),
Some(*self.parent_stack.last()
.unwrap_or_else(|| panic!("parent_stack is empty (while indexing {:?})", item.kind))),
Some(&self.stack[..self.stack.len() - 1]),
),
false,
Expand Down Expand Up @@ -303,7 +304,7 @@ impl DocFolder for Cache {

match parent {
(parent, Some(path)) if is_inherent_impl_item || !self.stripped_mod => {
debug_assert!(!item.is_stripped());
debug_assert!(!item.is_stripped(), "name={:?}, kind={:?}", item.name, item.kind);

// A crate has a module at its root, containing all items,
// which should not be indexed. The crate-item itself is
Expand Down
7 changes: 5 additions & 2 deletions src/librustdoc/formats/renderer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ crate fn run_format<T: FormatRenderer>(
// recurse into the items of the module as well.
let name = item.name.as_ref().unwrap().to_string();
if name.is_empty() {
panic!("Unexpected module with empty name");
panic!("Unexpected module with empty name: {:?}", item);
}

cx.mod_item_in(&item, &name, &cache)?;
Expand All @@ -97,7 +97,10 @@ crate fn run_format<T: FormatRenderer>(

cx.mod_item_out(&name)?;
} else if item.name.is_some() {
cx.item(item, &cache)?;
match item.kind {
clean::ItemKind::ImportItem(..) => {}
_ => cx.item(item, &cache)?,
}
}
}

Expand Down
16 changes: 10 additions & 6 deletions src/librustdoc/html/render/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1725,7 +1725,10 @@ fn print_item(cx: &Context, item: &clean::Item, buf: &mut Buffer, cache: &Cache)
"Module "
}
}
clean::FunctionItem(..) | clean::ForeignFunctionItem(..) => "Function ",
clean::FunctionItem(..)
| clean::ForeignFunctionItem(..)
| clean::TyMethodItem(..)
| clean::MethodItem(..) => "Function ",
clean::TraitItem(..) => "Trait ",
clean::StructItem(..) => "Struct ",
clean::UnionItem(..) => "Union ",
Expand All @@ -1746,7 +1749,7 @@ fn print_item(cx: &Context, item: &clean::Item, buf: &mut Buffer, cache: &Cache)
clean::TraitAliasItem(..) => "Trait Alias ",
_ => {
// We don't generate pages for any other type.
unreachable!();
unreachable!("unknown kind {:?}", item.kind);
}
};
buf.write_str(name);
Expand All @@ -1768,9 +1771,10 @@ fn print_item(cx: &Context, item: &clean::Item, buf: &mut Buffer, cache: &Cache)

match item.kind {
clean::ModuleItem(ref m) => item_module(buf, cx, item, &m.items),
clean::FunctionItem(ref f) | clean::ForeignFunctionItem(ref f) => {
item_function(buf, cx, item, f)
}
clean::FunctionItem(ref f)
| clean::ForeignFunctionItem(ref f)
| clean::TyMethodItem(ref f)
| clean::MethodItem(ref f, _) => item_function(buf, cx, item, f),
clean::TraitItem(ref t) => item_trait(buf, cx, item, t, cache),
clean::StructItem(ref s) => item_struct(buf, cx, item, s, cache),
clean::UnionItem(ref s) => item_union(buf, cx, item, s, cache),
Expand All @@ -1787,7 +1791,7 @@ fn print_item(cx: &Context, item: &clean::Item, buf: &mut Buffer, cache: &Cache)
clean::TraitAliasItem(ref ta) => item_trait_alias(buf, cx, item, ta, cache),
_ => {
// We don't generate pages for any other type.
unreachable!();
unreachable!("unknown kind {:?}", item.kind);
}
}
}
Expand Down
1 change: 0 additions & 1 deletion src/librustdoc/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,6 @@ mod json;
mod markdown;
mod passes;
mod theme;
mod visit_ast;
mod visit_lib;

pub fn main() {
Expand Down
Loading