Skip to content

Commit 32f144a

Browse files
Implement Clean<Crate> on hir::Crate directly
1 parent 78d9088 commit 32f144a

File tree

2 files changed

+8
-11
lines changed

2 files changed

+8
-11
lines changed

src/librustdoc/clean/mod.rs

+7-5
Original file line numberDiff line numberDiff line change
@@ -137,13 +137,15 @@ pub struct Crate {
137137
pub masked_crates: FxHashSet<CrateNum>,
138138
}
139139

140-
// The `()` here is rather ugly and would be great to remove. Unfortunately, we
141-
// already have a different Clean impl for `doctree::Module` which makes this
142-
// the only way to easily disambiguate.
143-
impl<'tcx> Clean<Crate> for ((), doctree::Module<'tcx>) {
140+
impl Clean<Crate> for hir::Crate {
141+
// note that self here is ignored in favor of `cx.tcx.hir().krate()` since
142+
// that gets around tying self's lifetime to the '_ in cx.
144143
fn clean(&self, cx: &DocContext<'_>) -> Crate {
145144
use crate::visit_lib::LibEmbargoVisitor;
146145

146+
let v = crate::visit_ast::RustdocVisitor::new(&cx);
147+
let module = v.visit(cx.tcx.hir().krate());
148+
147149
{
148150
let mut r = cx.renderinfo.borrow_mut();
149151
r.deref_trait_did = cx.tcx.lang_items().deref_trait();
@@ -161,7 +163,7 @@ impl<'tcx> Clean<Crate> for ((), doctree::Module<'tcx>) {
161163

162164
// Clean the crate, translating the entire libsyntax AST to one that is
163165
// understood by rustdoc.
164-
let mut module = self.1.clean(cx);
166+
let mut module = module.clean(cx);
165167
let mut masked_crates = FxHashSet::default();
166168

167169
match module.inner {

src/librustdoc/core.rs

+1-6
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ use rustc_data_structures::sync::{self, Lrc};
3030
use std::sync::Arc;
3131
use std::rc::Rc;
3232

33-
use crate::visit_ast::RustdocVisitor;
3433
use crate::config::{Options as RustdocOptions, RenderOptions};
3534
use crate::clean;
3635
use crate::clean::{Clean, MAX_DEF_ID, AttributesExt};
@@ -392,11 +391,7 @@ pub fn run_core(options: RustdocOptions) -> (clean::Crate, RenderInfo, RenderOpt
392391
};
393392
debug!("crate: {:?}", tcx.hir().krate());
394393

395-
let mut krate = {
396-
let v = RustdocVisitor::new(&ctxt);
397-
let module = v.visit(tcx.hir().krate());
398-
((), module).clean(&ctxt)
399-
};
394+
let mut krate = tcx.hir().krate().clean(&ctxt);
400395

401396
fn report_deprecated_attr(name: &str, diag: &errors::Handler) {
402397
let mut msg = diag.struct_warn(&format!("the `#![doc({})]` attribute is \

0 commit comments

Comments
 (0)