Represent ownership transfer in RustdocVisitor::visit

Previously visit could be called multiple times, but this is inaccurate,
as it deconstructs Visitor state.
This commit is contained in:
Mark Rousskov 2019-07-24 15:24:25 -04:00
parent 2d18504c27
commit 2fadc4524d
3 changed files with 7 additions and 5 deletions

View File

@ -49,7 +49,6 @@ use parking_lot::ReentrantMutex;
use crate::core::{self, DocContext};
use crate::doctree;
use crate::visit_ast;
use crate::html::render::{cache, ExternalLocation};
use crate::html::item_type::ItemType;
@ -138,7 +137,10 @@ pub struct Crate {
pub masked_crates: FxHashSet<CrateNum>,
}
impl<'a, 'tcx> Clean<Crate> for (visit_ast::RustdocVisitor<'a, 'tcx>, doctree::Module<'tcx>) {
// 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>) {
fn clean(&self, cx: &DocContext<'_>) -> Crate {
use crate::visit_lib::LibEmbargoVisitor;

View File

@ -392,9 +392,9 @@ pub fn run_core(options: RustdocOptions) -> (clean::Crate, RenderInfo, RenderOpt
debug!("crate: {:?}", tcx.hir().krate());
let mut krate = {
let mut v = RustdocVisitor::new(&ctxt);
let v = RustdocVisitor::new(&ctxt);
let module = v.visit(tcx.hir().krate());
(v, module).clean(&ctxt)
((), module).clean(&ctxt)
};
fn report_deprecated_attr(name: &str, diag: &errors::Handler) {

View File

@ -68,7 +68,7 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> {
.and_then(|def_id| self.cx.tcx.lookup_deprecation(def_id))
}
pub fn visit(&mut self, krate: &'tcx hir::Crate) -> Module<'tcx> {
pub fn visit(mut self, krate: &'tcx hir::Crate) -> Module<'tcx> {
let mut module = self.visit_mod_contents(krate.span,
&krate.attrs,
&Spanned { span: syntax_pos::DUMMY_SP,