diff --git a/src/librustc_interface/passes.rs b/src/librustc_interface/passes.rs index c9d68943b088..8b0b5a5b7a2b 100644 --- a/src/librustc_interface/passes.rs +++ b/src/librustc_interface/passes.rs @@ -58,7 +58,6 @@ use std::path::PathBuf; use std::sync::mpsc; use std::cell::RefCell; use std::rc::Rc; -use std::mem; pub fn parse<'a>(sess: &'a Session, input: &Input) -> PResult<'a, ast::Crate> { sess.diagnostic() @@ -204,15 +203,16 @@ impl ExpansionResult { impl BoxedResolver { pub fn to_expansion_result( - mut resolver: Rc>>, + resolver: Rc>, ) -> ExpansionResult { - if let Some(resolver) = Rc::get_mut(&mut resolver) { - mem::replace(resolver, None).unwrap().into_inner().complete() - } else { - let resolver = &*resolver; - resolver.as_ref().unwrap().borrow_mut().access(|resolver| { - ExpansionResult::from_resolver_ref(resolver) - }) + match Rc::try_unwrap(resolver) { + Ok(resolver) => resolver.into_inner().complete(), + Err(resolver) => { + let resolver = &*resolver; + resolver.borrow_mut().access(|resolver| { + ExpansionResult::from_resolver_ref(resolver) + }) + } } } } diff --git a/src/librustc_interface/queries.rs b/src/librustc_interface/queries.rs index 2e7952cd0044..ed50dadb6009 100644 --- a/src/librustc_interface/queries.rs +++ b/src/librustc_interface/queries.rs @@ -76,7 +76,7 @@ pub(crate) struct Queries { parse: Query, crate_name: Query, register_plugins: Query<(ast::Crate, PluginInfo)>, - expansion: Query<(ast::Crate, Rc>>)>, + expansion: Query<(ast::Crate, Steal>>)>, dep_graph: Query, lower_to_hir: Query<(Steal, ExpansionResult)>, prepare_outputs: Query, @@ -142,7 +142,7 @@ impl Compiler { pub fn expansion( &self - ) -> Result<&Query<(ast::Crate, Rc>>)>> { + ) -> Result<&Query<(ast::Crate, Steal>>)>> { self.queries.expansion.compute(|| { let crate_name = self.crate_name()?.peek().clone(); let (krate, plugin_info) = self.register_plugins()?.take(); @@ -152,7 +152,7 @@ impl Compiler { krate, &crate_name, plugin_info, - ).map(|(krate, resolver)| (krate, Rc::new(Some(RefCell::new(resolver))))) + ).map(|(krate, resolver)| (krate, Steal::new(Rc::new(RefCell::new(resolver))))) }) } @@ -176,9 +176,10 @@ impl Compiler { pub fn lower_to_hir(&self) -> Result<&Query<(Steal, ExpansionResult)>> { self.queries.lower_to_hir.compute(|| { let expansion_result = self.expansion()?; - let (krate, resolver) = expansion_result.take(); - let resolver_ref = &*resolver; - let hir = Steal::new(resolver_ref.as_ref().unwrap().borrow_mut().access(|resolver| { + let peeked = expansion_result.peek(); + let krate = &peeked.0; + let resolver = peeked.1.steal(); + let hir = Steal::new(resolver.borrow_mut().access(|resolver| { passes::lower_to_hir( self.session(), self.cstore(), @@ -187,7 +188,6 @@ impl Compiler { &krate ) })?); - expansion_result.give((krate, Rc::new(None))); Ok((hir, BoxedResolver::to_expansion_result(resolver))) }) } diff --git a/src/librustdoc/clean/blanket_impl.rs b/src/librustdoc/clean/blanket_impl.rs index 5c42d705bd57..64cffaec2eaf 100644 --- a/src/librustdoc/clean/blanket_impl.rs +++ b/src/librustdoc/clean/blanket_impl.rs @@ -5,8 +5,6 @@ use rustc::ty::subst::Subst; use rustc::infer::InferOk; use syntax_pos::DUMMY_SP; -use crate::core::DocAccessLevels; - use super::*; pub struct BlanketImplFinder<'a, 'tcx> { @@ -30,7 +28,7 @@ impl<'a, 'tcx> BlanketImplFinder<'a, 'tcx> { debug!("get_blanket_impls({:?})", ty); let mut impls = Vec::new(); for &trait_def_id in self.cx.all_traits.iter() { - if !self.cx.renderinfo.borrow().access_levels.is_doc_reachable(trait_def_id) || + if !self.cx.renderinfo.borrow().access_levels.is_public(trait_def_id) || self.cx.generated_synthetics .borrow_mut() .get(&(ty, trait_def_id)) diff --git a/src/librustdoc/clean/inline.rs b/src/librustdoc/clean/inline.rs index 8463fbfbd200..d2a6dcf19bcc 100644 --- a/src/librustdoc/clean/inline.rs +++ b/src/librustdoc/clean/inline.rs @@ -14,7 +14,7 @@ use rustc_metadata::cstore::LoadedMacro; use rustc::ty; use rustc::util::nodemap::FxHashSet; -use crate::core::{DocContext, DocAccessLevels}; +use crate::core::DocContext; use crate::doctree; use crate::clean::{ self, @@ -326,7 +326,7 @@ pub fn build_impl(cx: &DocContext<'_>, did: DefId, attrs: Option>, // reachable in rustdoc generated documentation if !did.is_local() { if let Some(traitref) = associated_trait { - if !cx.renderinfo.borrow().access_levels.is_doc_reachable(traitref.def_id) { + if !cx.renderinfo.borrow().access_levels.is_public(traitref.def_id) { return } } @@ -347,7 +347,7 @@ pub fn build_impl(cx: &DocContext<'_>, did: DefId, attrs: Option>, // reachable in rustdoc generated documentation if !did.is_local() { if let Some(did) = for_.def_id() { - if !cx.renderinfo.borrow().access_levels.is_doc_reachable(did) { + if !cx.renderinfo.borrow().access_levels.is_public(did) { return } } diff --git a/src/librustdoc/clean/mod.rs b/src/librustdoc/clean/mod.rs index d3accff5c2ce..6f33bdd7f4d2 100644 --- a/src/librustdoc/clean/mod.rs +++ b/src/librustdoc/clean/mod.rs @@ -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,10 +137,15 @@ pub struct Crate { pub masked_crates: FxHashSet, } -impl<'a, 'tcx> Clean for visit_ast::RustdocVisitor<'a, 'tcx> { +impl Clean 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(); @@ -159,7 +163,7 @@ impl<'a, 'tcx> Clean 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 = module.clean(cx); let mut masked_crates = FxHashSet::default(); match module.inner { @@ -169,7 +173,7 @@ impl<'a, 'tcx> Clean 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); } @@ -652,9 +656,9 @@ impl Clean for doctree::Module<'_> { attrs, source: whence.clean(cx), visibility: self.vis.clean(cx), - stability: self.stab.clean(cx), - deprecation: self.depr.clean(cx), - def_id: cx.tcx.hir().local_def_id_from_node_id(self.id), + stability: cx.stability(self.id).clean(cx), + deprecation: cx.deprecation(self.id).clean(cx), + def_id: cx.tcx.hir().local_def_id(self.id), inner: ModuleItem(Module { is_crate: self.is_crate, items, @@ -1938,8 +1942,8 @@ impl Clean for doctree::Function<'_> { attrs: self.attrs.clean(cx), source: self.whence.clean(cx), visibility: self.vis.clean(cx), - stability: self.stab.clean(cx), - deprecation: self.depr.clean(cx), + stability: cx.stability(self.id).clean(cx), + deprecation: cx.deprecation(self.id).clean(cx), def_id: did, inner: FunctionItem(Function { decl, @@ -2138,8 +2142,8 @@ impl Clean for doctree::Trait<'_> { source: self.whence.clean(cx), def_id: cx.tcx.hir().local_def_id(self.id), visibility: self.vis.clean(cx), - stability: self.stab.clean(cx), - deprecation: self.depr.clean(cx), + stability: cx.stability(self.id).clean(cx), + deprecation: cx.deprecation(self.id).clean(cx), inner: TraitItem(Trait { auto: self.is_auto.clean(cx), unsafety: self.unsafety, @@ -2168,8 +2172,8 @@ impl Clean for doctree::TraitAlias<'_> { source: self.whence.clean(cx), def_id: cx.tcx.hir().local_def_id(self.id), visibility: self.vis.clean(cx), - stability: self.stab.clean(cx), - deprecation: self.depr.clean(cx), + stability: cx.stability(self.id).clean(cx), + deprecation: cx.deprecation(self.id).clean(cx), inner: TraitAliasItem(TraitAlias { generics: self.generics.clean(cx), bounds: self.bounds.clean(cx), @@ -3242,8 +3246,8 @@ impl Clean for doctree::Struct<'_> { source: self.whence.clean(cx), def_id: cx.tcx.hir().local_def_id(self.id), visibility: self.vis.clean(cx), - stability: self.stab.clean(cx), - deprecation: self.depr.clean(cx), + stability: cx.stability(self.id).clean(cx), + deprecation: cx.deprecation(self.id).clean(cx), inner: StructItem(Struct { struct_type: self.struct_type, generics: self.generics.clean(cx), @@ -3262,8 +3266,8 @@ impl Clean for doctree::Union<'_> { source: self.whence.clean(cx), def_id: cx.tcx.hir().local_def_id(self.id), visibility: self.vis.clean(cx), - stability: self.stab.clean(cx), - deprecation: self.depr.clean(cx), + stability: cx.stability(self.id).clean(cx), + deprecation: cx.deprecation(self.id).clean(cx), inner: UnionItem(Union { struct_type: self.struct_type, generics: self.generics.clean(cx), @@ -3309,8 +3313,8 @@ impl Clean for doctree::Enum<'_> { source: self.whence.clean(cx), def_id: cx.tcx.hir().local_def_id(self.id), visibility: self.vis.clean(cx), - stability: self.stab.clean(cx), - deprecation: self.depr.clean(cx), + stability: cx.stability(self.id).clean(cx), + deprecation: cx.deprecation(self.id).clean(cx), inner: EnumItem(Enum { variants: self.variants.iter().map(|v| v.clean(cx)).collect(), generics: self.generics.clean(cx), @@ -3332,8 +3336,8 @@ impl Clean for doctree::Variant<'_> { attrs: self.attrs.clean(cx), source: self.whence.clean(cx), visibility: None, - stability: self.stab.clean(cx), - deprecation: self.depr.clean(cx), + stability: cx.stability(self.id).clean(cx), + deprecation: cx.deprecation(self.id).clean(cx), def_id: cx.tcx.hir().local_def_id(self.id), inner: VariantItem(Variant { kind: self.def.clean(cx), @@ -3637,8 +3641,8 @@ impl Clean for doctree::Typedef<'_> { source: self.whence.clean(cx), def_id: cx.tcx.hir().local_def_id(self.id), visibility: self.vis.clean(cx), - stability: self.stab.clean(cx), - deprecation: self.depr.clean(cx), + stability: cx.stability(self.id).clean(cx), + deprecation: cx.deprecation(self.id).clean(cx), inner: TypedefItem(Typedef { type_: self.ty.clean(cx), generics: self.gen.clean(cx), @@ -3661,8 +3665,8 @@ impl Clean for doctree::OpaqueTy<'_> { source: self.whence.clean(cx), def_id: cx.tcx.hir().local_def_id(self.id), visibility: self.vis.clean(cx), - stability: self.stab.clean(cx), - deprecation: self.depr.clean(cx), + stability: cx.stability(self.id).clean(cx), + deprecation: cx.deprecation(self.id).clean(cx), inner: OpaqueTyItem(OpaqueTy { bounds: self.opaque_ty.bounds.clean(cx), generics: self.opaque_ty.generics.clean(cx), @@ -3712,8 +3716,8 @@ impl Clean for doctree::Static<'_> { source: self.whence.clean(cx), def_id: cx.tcx.hir().local_def_id(self.id), visibility: self.vis.clean(cx), - stability: self.stab.clean(cx), - deprecation: self.depr.clean(cx), + stability: cx.stability(self.id).clean(cx), + deprecation: cx.deprecation(self.id).clean(cx), inner: StaticItem(Static { type_: self.type_.clean(cx), mutability: self.mutability.clean(cx), @@ -3737,8 +3741,8 @@ impl Clean for doctree::Constant<'_> { source: self.whence.clean(cx), def_id: cx.tcx.hir().local_def_id(self.id), visibility: self.vis.clean(cx), - stability: self.stab.clean(cx), - deprecation: self.depr.clean(cx), + stability: cx.stability(self.id).clean(cx), + deprecation: cx.deprecation(self.id).clean(cx), inner: ConstantItem(Constant { type_: self.type_.clean(cx), expr: print_const_expr(cx, self.expr), @@ -3824,8 +3828,8 @@ impl Clean> for doctree::Impl<'_> { source: self.whence.clean(cx), def_id: cx.tcx.hir().local_def_id(self.id), visibility: self.vis.clean(cx), - stability: self.stab.clean(cx), - deprecation: self.depr.clean(cx), + stability: cx.stability(self.id).clean(cx), + deprecation: cx.deprecation(self.id).clean(cx), inner: ImplItem(Impl { unsafety: self.unsafety, generics: self.generics.clean(cx), @@ -4063,8 +4067,8 @@ impl Clean for doctree::ForeignItem<'_> { source: self.whence.clean(cx), def_id: cx.tcx.hir().local_def_id(self.id), visibility: self.vis.clean(cx), - stability: self.stab.clean(cx), - deprecation: self.depr.clean(cx), + stability: cx.stability(self.id).clean(cx), + deprecation: cx.deprecation(self.id).clean(cx), inner, } } @@ -4246,8 +4250,8 @@ impl Clean for doctree::Macro<'_> { attrs: self.attrs.clean(cx), source: self.whence.clean(cx), visibility: Some(Public), - stability: self.stab.clean(cx), - deprecation: self.depr.clean(cx), + stability: cx.stability(self.hid).clean(cx), + deprecation: cx.deprecation(self.hid).clean(cx), def_id: self.def_id, inner: MacroItem(Macro { source: format!("macro_rules! {} {{\n{}}}", @@ -4274,8 +4278,8 @@ impl Clean for doctree::ProcMacro<'_> { attrs: self.attrs.clean(cx), source: self.whence.clean(cx), visibility: Some(Public), - stability: self.stab.clean(cx), - deprecation: self.depr.clean(cx), + stability: cx.stability(self.id).clean(cx), + deprecation: cx.deprecation(self.id).clean(cx), def_id: cx.tcx.hir().local_def_id(self.id), inner: ProcMacroItem(ProcMacro { kind: self.kind, diff --git a/src/librustdoc/core.rs b/src/librustdoc/core.rs index cc79f4ab09a5..5138e4a23a47 100644 --- a/src/librustdoc/core.rs +++ b/src/librustdoc/core.rs @@ -16,6 +16,7 @@ use rustc_metadata::cstore::CStore; use rustc_target::spec::TargetTriple; use syntax::source_map; +use syntax::attr; use syntax::feature_gate::UnstableFeatures; use syntax::json::JsonEmitter; use syntax::symbol::sym; @@ -29,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}; @@ -45,7 +45,7 @@ pub type ExternalPaths = FxHashMap, clean::TypeKind)>; pub struct DocContext<'tcx> { pub tcx: TyCtxt<'tcx>, - pub resolver: Rc>>, + pub resolver: Rc>, /// The stack of module NodeIds up till this point pub crate_name: Option, pub cstore: Lrc, @@ -83,9 +83,7 @@ impl<'tcx> DocContext<'tcx> { pub fn enter_resolver(&self, f: F) -> R where F: FnOnce(&mut resolve::Resolver<'_>) -> R { - let resolver = &*self.resolver; - let resolver = resolver.as_ref().unwrap(); - resolver.borrow_mut().access(f) + self.resolver.borrow_mut().access(f) } /// Call the closure with the given parameters set as @@ -167,15 +165,15 @@ impl<'tcx> DocContext<'tcx> { self.tcx.hir().as_local_hir_id(def_id) } } -} -pub trait DocAccessLevels { - fn is_doc_reachable(&self, did: DefId) -> bool; -} + pub fn stability(&self, id: HirId) -> Option { + self.tcx.hir().opt_local_def_id(id) + .and_then(|def_id| self.tcx.lookup_stability(def_id)).cloned() + } -impl DocAccessLevels for AccessLevels { - fn is_doc_reachable(&self, did: DefId) -> bool { - self.is_public(did) + pub fn deprecation(&self, id: HirId) -> Option { + self.tcx.hir().opt_local_def_id(id) + .and_then(|def_id| self.tcx.lookup_deprecation(def_id)) } } @@ -344,7 +342,7 @@ pub fn run_core(options: RustdocOptions) -> (clean::Crate, RenderInfo, RenderOpt // We need to hold on to the complete resolver, so we cause everything to be // cloned for the analysis passes to use. Suboptimal, but necessary in the // current architecture. - let resolver = abort_on_err(compiler.expansion(), sess).peek().1.clone(); + let resolver = abort_on_err(compiler.expansion(), sess).peek().1.borrow().clone(); if sess.has_errors() { sess.fatal("Compilation failed, aborting rustdoc"); @@ -393,11 +391,7 @@ pub fn run_core(options: RustdocOptions) -> (clean::Crate, RenderInfo, RenderOpt }; debug!("crate: {:?}", tcx.hir().krate()); - let mut krate = { - let mut v = RustdocVisitor::new(&ctxt); - v.visit(tcx.hir().krate()); - v.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 \ diff --git a/src/librustdoc/doctree.rs b/src/librustdoc/doctree.rs index ec60241a92d4..90dcf1be76c0 100644 --- a/src/librustdoc/doctree.rs +++ b/src/librustdoc/doctree.rs @@ -3,8 +3,7 @@ pub use self::StructType::*; use syntax::ast; -use syntax::ast::{Name, NodeId}; -use syntax::attr; +use syntax::ast::Name; use syntax::ext::base::MacroKind; use syntax_pos::{self, Span}; @@ -24,15 +23,13 @@ pub struct Module<'hir> { pub enums: Vec>, pub fns: Vec>, pub mods: Vec>, - pub id: NodeId, + pub id: hir::HirId, pub typedefs: Vec>, pub opaque_tys: Vec>, pub statics: Vec>, pub constants: Vec>, pub traits: Vec>, pub vis: &'hir hir::Visibility, - pub stab: Option, - pub depr: Option, pub impls: Vec>, pub foreigns: Vec>, pub macros: Vec>, @@ -49,10 +46,8 @@ impl Module<'hir> { ) -> Module<'hir> { Module { name : name, - id: ast::CRATE_NODE_ID, + id: hir::CRATE_HIR_ID, vis, - stab: None, - depr: None, where_outer: syntax_pos::DUMMY_SP, where_inner: syntax_pos::DUMMY_SP, attrs, @@ -90,8 +85,6 @@ pub enum StructType { pub struct Struct<'hir> { pub vis: &'hir hir::Visibility, - pub stab: Option, - pub depr: Option, pub id: hir::HirId, pub struct_type: StructType, pub name: Name, @@ -103,8 +96,6 @@ pub struct Struct<'hir> { pub struct Union<'hir> { pub vis: &'hir hir::Visibility, - pub stab: Option, - pub depr: Option, pub id: hir::HirId, pub struct_type: StructType, pub name: Name, @@ -116,8 +107,6 @@ pub struct Union<'hir> { pub struct Enum<'hir> { pub vis: &'hir hir::Visibility, - pub stab: Option, - pub depr: Option, pub variants: Vec>, pub generics: &'hir hir::Generics, pub attrs: &'hir hir::HirVec, @@ -131,8 +120,6 @@ pub struct Variant<'hir> { pub id: hir::HirId, pub attrs: &'hir hir::HirVec, pub def: &'hir hir::VariantData, - pub stab: Option, - pub depr: Option, pub whence: Span, } @@ -142,8 +129,6 @@ pub struct Function<'hir> { pub id: hir::HirId, pub name: Name, pub vis: &'hir hir::Visibility, - pub stab: Option, - pub depr: Option, pub header: hir::FnHeader, pub whence: Span, pub generics: &'hir hir::Generics, @@ -158,8 +143,6 @@ pub struct Typedef<'hir> { pub attrs: &'hir hir::HirVec, pub whence: Span, pub vis: &'hir hir::Visibility, - pub stab: Option, - pub depr: Option, } pub struct OpaqueTy<'hir> { @@ -169,8 +152,6 @@ pub struct OpaqueTy<'hir> { pub attrs: &'hir hir::HirVec, pub whence: Span, pub vis: &'hir hir::Visibility, - pub stab: Option, - pub depr: Option, } #[derive(Debug)] @@ -181,8 +162,6 @@ pub struct Static<'hir> { pub name: Name, pub attrs: &'hir hir::HirVec, pub vis: &'hir hir::Visibility, - pub stab: Option, - pub depr: Option, pub id: hir::HirId, pub whence: Span, } @@ -193,8 +172,6 @@ pub struct Constant<'hir> { pub name: Name, pub attrs: &'hir hir::HirVec, pub vis: &'hir hir::Visibility, - pub stab: Option, - pub depr: Option, pub id: hir::HirId, pub whence: Span, } @@ -210,8 +187,6 @@ pub struct Trait<'hir> { pub id: hir::HirId, pub whence: Span, pub vis: &'hir hir::Visibility, - pub stab: Option, - pub depr: Option, } pub struct TraitAlias<'hir> { @@ -222,8 +197,6 @@ pub struct TraitAlias<'hir> { pub id: hir::HirId, pub whence: Span, pub vis: &'hir hir::Visibility, - pub stab: Option, - pub depr: Option, } #[derive(Debug)] @@ -238,15 +211,11 @@ pub struct Impl<'hir> { pub attrs: &'hir hir::HirVec, pub whence: Span, pub vis: &'hir hir::Visibility, - pub stab: Option, - pub depr: Option, pub id: hir::HirId, } pub struct ForeignItem<'hir> { pub vis: &'hir hir::Visibility, - pub stab: Option, - pub depr: Option, pub id: hir::HirId, pub name: Name, pub kind: &'hir hir::ForeignItemKind, @@ -258,12 +227,11 @@ pub struct ForeignItem<'hir> { // these imported macro_rules (which only have a DUMMY_NODE_ID). pub struct Macro<'hir> { pub name: Name, + pub hid: hir::HirId, pub def_id: hir::def_id::DefId, pub attrs: &'hir hir::HirVec, pub whence: Span, pub matchers: hir::HirVec, - pub stab: Option, - pub depr: Option, pub imported_from: Option, } @@ -293,8 +261,6 @@ pub struct ProcMacro<'hir> { pub helpers: Vec, pub attrs: &'hir hir::HirVec, pub whence: Span, - pub stab: Option, - pub depr: Option, } pub fn struct_type_from_def(vdata: &hir::VariantData) -> StructType { diff --git a/src/librustdoc/html/format.rs b/src/librustdoc/html/format.rs index 9e5cc03b8312..9c22837bdae8 100644 --- a/src/librustdoc/html/format.rs +++ b/src/librustdoc/html/format.rs @@ -14,7 +14,6 @@ use rustc_target::spec::abi::Abi; use rustc::hir; use crate::clean::{self, PrimitiveType}; -use crate::core::DocAccessLevels; use crate::html::item_type::ItemType; use crate::html::render::{self, cache, CURRENT_LOCATION_KEY}; @@ -404,7 +403,7 @@ impl fmt::Display for clean::Path { pub fn href(did: DefId) -> Option<(String, ItemType, Vec)> { let cache = cache(); - if !did.is_local() && !cache.access_levels.is_doc_reachable(did) { + if !did.is_local() && !cache.access_levels.is_public(did) { return None } diff --git a/src/librustdoc/passes/mod.rs b/src/librustdoc/passes/mod.rs index ca40d6d02f86..4e10b46bc8a6 100644 --- a/src/librustdoc/passes/mod.rs +++ b/src/librustdoc/passes/mod.rs @@ -10,7 +10,7 @@ use syntax_pos::{DUMMY_SP, InnerSpan, Span}; use std::ops::Range; use crate::clean::{self, GetDefId, Item}; -use crate::core::{DocContext, DocAccessLevels}; +use crate::core::DocContext; use crate::fold::{DocFolder, StripItem}; use crate::html::markdown::{find_testable_code, ErrorCodes, LangString}; @@ -347,7 +347,7 @@ pub fn look_for_tests<'tcx>( diag.emit(); } else if check_missing_code == false && tests.found_tests > 0 && - !cx.renderinfo.borrow().access_levels.is_doc_reachable(item.def_id) { + !cx.renderinfo.borrow().access_levels.is_public(item.def_id) { let mut diag = cx.tcx.struct_span_lint_hir( lint::builtin::PRIVATE_DOC_TESTS, hir_id, diff --git a/src/librustdoc/visit_ast.rs b/src/librustdoc/visit_ast.rs index 1ba2c0333d6b..f01b9eeb30f2 100644 --- a/src/librustdoc/visit_ast.rs +++ b/src/librustdoc/visit_ast.rs @@ -7,7 +7,6 @@ use rustc::hir::def_id::{DefId, LOCAL_CRATE}; use rustc::middle::privacy::AccessLevel; use rustc::util::nodemap::{FxHashSet, FxHashMap}; use syntax::ast; -use syntax::attr; use syntax::ext::base::MacroKind; use syntax::source_map::Spanned; use syntax::symbol::sym; @@ -20,22 +19,16 @@ 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>, - pub cx: &'a core::DocContext<'tcx>, + cx: &'a core::DocContext<'tcx>, view_item_stack: FxHashSet, inlining: bool, /// Are the current module and all of its parents public? inside_public_path: bool, - exact_paths: Option>>, + exact_paths: FxHashMap>, } impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> { @@ -46,36 +39,24 @@ 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, inside_public_path: true, - exact_paths: Some(FxHashMap::default()), + exact_paths: FxHashMap::default(), } } fn store_path(&mut self, did: DefId) { // We can't use the entry API, as that keeps the mutable borrow of `self` active // when we try to use `cx`. - let exact_paths = self.exact_paths.as_mut().unwrap(); - if exact_paths.get(&did).is_none() { + if self.exact_paths.get(&did).is_none() { let path = def_id_to_path(self.cx, did, self.cx.crate_name.clone()); - exact_paths.insert(did, path); + self.exact_paths.insert(did, path); } } - fn stability(&self, id: hir::HirId) -> Option { - self.cx.tcx.hir().opt_local_def_id(id) - .and_then(|def_id| self.cx.tcx.lookup_stability(def_id)).cloned() - } - - fn deprecation(&self, id: hir::HirId) -> Option { - self.cx.tcx.hir().opt_local_def_id(id) - .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, @@ -88,12 +69,13 @@ 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(); + self.cx.renderinfo.borrow_mut().exact_paths = self.exact_paths; + + module } - pub fn visit_variant_data(&mut self, item: &'tcx hir::Item, + fn visit_variant_data(&mut self, item: &'tcx hir::Item, name: ast::Name, sd: &'tcx hir::VariantData, generics: &'tcx hir::Generics) -> Struct<'tcx> { debug!("visiting struct"); @@ -103,8 +85,6 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> { struct_type, name, vis: &item.vis, - stab: self.stability(item.hir_id), - depr: self.deprecation(item.hir_id), attrs: &item.attrs, generics, fields: sd.fields(), @@ -112,7 +92,7 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> { } } - pub fn visit_union_data(&mut self, item: &'tcx hir::Item, + fn visit_union_data(&mut self, item: &'tcx hir::Item, name: ast::Name, sd: &'tcx hir::VariantData, generics: &'tcx hir::Generics) -> Union<'tcx> { debug!("visiting union"); @@ -122,8 +102,6 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> { struct_type, name, vis: &item.vis, - stab: self.stability(item.hir_id), - depr: self.deprecation(item.hir_id), attrs: &item.attrs, generics, fields: sd.fields(), @@ -131,7 +109,7 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> { } } - pub fn visit_enum_def(&mut self, it: &'tcx hir::Item, + fn visit_enum_def(&mut self, it: &'tcx hir::Item, name: ast::Name, def: &'tcx hir::EnumDef, generics: &'tcx hir::Generics) -> Enum<'tcx> { debug!("visiting enum"); @@ -141,14 +119,10 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> { name: v.node.ident.name, id: v.node.id, attrs: &v.node.attrs, - stab: self.stability(v.node.id), - depr: self.deprecation(v.node.id), def: &v.node.data, whence: v.span, }).collect(), vis: &it.vis, - stab: self.stability(it.hir_id), - depr: self.deprecation(it.hir_id), generics, attrs: &it.attrs, id: it.hir_id, @@ -156,7 +130,7 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> { } } - pub fn visit_fn(&mut self, om: &mut Module<'tcx>, item: &'tcx hir::Item, + fn visit_fn(&mut self, om: &mut Module<'tcx>, item: &'tcx hir::Item, name: ast::Name, decl: &'tcx hir::FnDecl, header: hir::FnHeader, generics: &'tcx hir::Generics, @@ -207,16 +181,12 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> { helpers, attrs: &item.attrs, whence: item.span, - stab: self.stability(item.hir_id), - depr: self.deprecation(item.hir_id), }); } None => { om.fns.push(Function { id: item.hir_id, vis: &item.vis, - stab: self.stability(item.hir_id), - depr: self.deprecation(item.hir_id), attrs: &item.attrs, decl, name, @@ -229,16 +199,14 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> { } } - pub fn visit_mod_contents(&mut self, span: Span, attrs: &'tcx hir::HirVec, + fn visit_mod_contents(&mut self, span: Span, attrs: &'tcx hir::HirVec, vis: &'tcx hir::Visibility, id: hir::HirId, m: &'tcx hir::Mod, name: Option) -> Module<'tcx> { let mut om = Module::new(name, attrs, vis); om.where_outer = span; om.where_inner = m.inner; - om.stab = self.stability(id); - om.depr = self.deprecation(id); - om.id = self.cx.tcx.hir().hir_to_node_id(id); + om.id = id; // Keep track of if there were any private modules in the path. let orig_inside_public_path = self.inside_public_path; self.inside_public_path &= vis.node.is_pub(); @@ -369,7 +337,7 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> { ret } - pub fn visit_item(&mut self, item: &'tcx hir::Item, + fn visit_item(&mut self, item: &'tcx hir::Item, renamed: Option, om: &mut Module<'tcx>) { debug!("visiting item {:?}", item); let ident = renamed.unwrap_or(item.ident); @@ -467,8 +435,6 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> { attrs: &item.attrs, whence: item.span, vis: &item.vis, - stab: self.stability(item.hir_id), - depr: self.deprecation(item.hir_id), }; om.typedefs.push(t); }, @@ -480,8 +446,6 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> { attrs: &item.attrs, whence: item.span, vis: &item.vis, - stab: self.stability(item.hir_id), - depr: self.deprecation(item.hir_id), }; om.opaque_tys.push(t); }, @@ -495,8 +459,6 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> { attrs: &item.attrs, whence: item.span, vis: &item.vis, - stab: self.stability(item.hir_id), - depr: self.deprecation(item.hir_id), }; om.statics.push(s); }, @@ -509,8 +471,6 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> { attrs: &item.attrs, whence: item.span, vis: &item.vis, - stab: self.stability(item.hir_id), - depr: self.deprecation(item.hir_id), }; om.constants.push(s); }, @@ -529,8 +489,6 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> { attrs: &item.attrs, whence: item.span, vis: &item.vis, - stab: self.stability(item.hir_id), - depr: self.deprecation(item.hir_id), }; om.traits.push(t); }, @@ -543,8 +501,6 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> { attrs: &item.attrs, whence: item.span, vis: &item.vis, - stab: self.stability(item.hir_id), - depr: self.deprecation(item.hir_id), }; om.trait_aliases.push(t); }, @@ -574,8 +530,6 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> { id: item.hir_id, whence: item.span, vis: &item.vis, - stab: self.stability(item.hir_id), - depr: self.deprecation(item.hir_id), }; om.impls.push(i); } @@ -595,8 +549,6 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> { name: renamed.unwrap_or(item.ident).name, kind: &item.node, vis: &item.vis, - stab: self.stability(item.hir_id), - depr: self.deprecation(item.hir_id), attrs: &item.attrs, whence: item.span }); @@ -614,14 +566,12 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> { let matchers = tts.chunks(4).map(|arm| arm[0].span()).collect(); Macro { - + hid: def.hir_id, def_id: self.cx.tcx.hir().local_def_id(def.hir_id), attrs: &def.attrs, name: renamed.unwrap_or(def.name), whence: def.span, matchers, - stab: self.stability(def.hir_id), - depr: self.deprecation(def.hir_id), imported_from: None, } }