Skip to content

Commit

Permalink
Implement Clean<Crate> on hir::Crate directly
Browse files Browse the repository at this point in the history
  • Loading branch information
Mark-Simulacrum committed Aug 10, 2019
1 parent 78d9088 commit 32f144a
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 11 deletions.
12 changes: 7 additions & 5 deletions src/librustdoc/clean/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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 {
Expand Down
7 changes: 1 addition & 6 deletions src/librustdoc/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -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 \
Expand Down

0 comments on commit 32f144a

Please sign in to comment.