Skip to content

Commit

Permalink
Make fields of RustdocVisitor private
Browse files Browse the repository at this point in the history
  • Loading branch information
Mark-Simulacrum committed Aug 10, 2019
1 parent d19a359 commit 3710002
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 15 deletions.
6 changes: 3 additions & 3 deletions src/librustdoc/clean/mod.rs
Expand Up @@ -138,7 +138,7 @@ pub struct Crate {
pub masked_crates: FxHashSet<CrateNum>,
}

impl<'a, 'tcx> Clean<Crate> for visit_ast::RustdocVisitor<'a, 'tcx> {
impl<'a, 'tcx> Clean<Crate> for (visit_ast::RustdocVisitor<'a, 'tcx>, doctree::Module<'tcx>) {
fn clean(&self, cx: &DocContext<'_>) -> Crate {
use crate::visit_lib::LibEmbargoVisitor;

Expand All @@ -159,7 +159,7 @@ impl<'a, 'tcx> Clean<Crate> for visit_ast::RustdocVisitor<'a, 'tcx> {

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

match module.inner {
Expand All @@ -169,7 +169,7 @@ impl<'a, 'tcx> Clean<Crate> for visit_ast::RustdocVisitor<'a, 'tcx> {
// `#[doc(masked)]` to the injected `extern crate` because it's unstable.
if it.is_extern_crate()
&& (it.attrs.has_doc_flag(sym::masked)
|| self.cx.tcx.is_compiler_builtins(it.def_id.krate))
|| cx.tcx.is_compiler_builtins(it.def_id.krate))
{
masked_crates.insert(it.def_id.krate);
}
Expand Down
4 changes: 2 additions & 2 deletions src/librustdoc/core.rs
Expand Up @@ -395,8 +395,8 @@ pub fn run_core(options: RustdocOptions) -> (clean::Crate, RenderInfo, RenderOpt

let mut krate = {
let mut v = RustdocVisitor::new(&ctxt);
v.visit(tcx.hir().krate());
v.clean(&ctxt)
let module = v.visit(tcx.hir().krate());
(v, module).clean(&ctxt)
};

fn report_deprecated_attr(name: &str, diag: &errors::Handler) {
Expand Down
14 changes: 4 additions & 10 deletions src/librustdoc/visit_ast.rs
Expand Up @@ -20,17 +20,11 @@ use crate::clean::{self, AttributesExt, NestedAttributesExt, def_id_to_path};
use crate::doctree::*;


// Looks to me like the first two of these are actually
// output parameters, maybe only mutated once; perhaps
// better simply to have the visit method return a tuple
// containing them?

// Also, is there some reason that this doesn't use the 'visit'
// framework from syntax?.

pub struct RustdocVisitor<'a, 'tcx> {
pub module: Option<Module<'tcx>>,
pub cx: &'a core::DocContext<'tcx>,
cx: &'a core::DocContext<'tcx>,
view_item_stack: FxHashSet<hir::HirId>,
inlining: bool,
/// Are the current module and all of its parents public?
Expand All @@ -46,7 +40,6 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> {
let mut stack = FxHashSet::default();
stack.insert(hir::CRATE_HIR_ID);
RustdocVisitor {
module: None,
cx,
view_item_stack: stack,
inlining: false,
Expand Down Expand Up @@ -75,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) {
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,
Expand All @@ -88,9 +81,10 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> {
krate.exported_macros.iter().map(|def| self.visit_local_macro(def, None)),
);
module.is_crate = true;
self.module = Some(module);

self.cx.renderinfo.borrow_mut().exact_paths = self.exact_paths.take().unwrap();

module
}

pub fn visit_variant_data(&mut self, item: &'tcx hir::Item,
Expand Down

0 comments on commit 3710002

Please sign in to comment.