Implement Clean<Crate> on hir::Crate directly

This commit is contained in:
Mark Rousskov 2019-08-10 07:30:39 -04:00
parent 78d9088e77
commit 32f144a527
2 changed files with 8 additions and 11 deletions

View File

@ -137,13 +137,15 @@ pub struct Crate {
pub masked_crates: FxHashSet<CrateNum>,
}
// The `()` here is rather ugly and would be great to remove. Unfortunately, we
// already have a different Clean impl for `doctree::Module` which makes this
// the only way to easily disambiguate.
impl<'tcx> Clean<Crate> for ((), doctree::Module<'tcx>) {
impl Clean<Crate> for hir::Crate {
// note that self here is ignored in favor of `cx.tcx.hir().krate()` since
// that gets around tying self's lifetime to the '_ in cx.
fn clean(&self, cx: &DocContext<'_>) -> Crate {
use crate::visit_lib::LibEmbargoVisitor;
let v = crate::visit_ast::RustdocVisitor::new(&cx);
let module = v.visit(cx.tcx.hir().krate());
{
let mut r = cx.renderinfo.borrow_mut();
r.deref_trait_did = cx.tcx.lang_items().deref_trait();
@ -161,7 +163,7 @@ impl<'tcx> Clean<Crate> for ((), doctree::Module<'tcx>) {
// Clean the crate, translating the entire libsyntax AST to one that is
// understood by rustdoc.
let mut module = self.1.clean(cx);
let mut module = module.clean(cx);
let mut masked_crates = FxHashSet::default();
match module.inner {

View File

@ -30,7 +30,6 @@ use rustc_data_structures::sync::{self, Lrc};
use std::sync::Arc;
use std::rc::Rc;
use crate::visit_ast::RustdocVisitor;
use crate::config::{Options as RustdocOptions, RenderOptions};
use crate::clean;
use crate::clean::{Clean, MAX_DEF_ID, AttributesExt};
@ -392,11 +391,7 @@ pub fn run_core(options: RustdocOptions) -> (clean::Crate, RenderInfo, RenderOpt
};
debug!("crate: {:?}", tcx.hir().krate());
let mut krate = {
let v = RustdocVisitor::new(&ctxt);
let module = v.visit(tcx.hir().krate());
((), module).clean(&ctxt)
};
let mut krate = tcx.hir().krate().clean(&ctxt);
fn report_deprecated_attr(name: &str, diag: &errors::Handler) {
let mut msg = diag.struct_warn(&format!("the `#![doc({})]` attribute is \