Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rustdoc: general cleanups #62955

Merged
merged 9 commits into from
Aug 10, 2019
18 changes: 9 additions & 9 deletions src/librustc_interface/passes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -204,15 +203,16 @@ impl ExpansionResult {

impl BoxedResolver {
pub fn to_expansion_result(
mut resolver: Rc<Option<RefCell<BoxedResolver>>>,
resolver: Rc<RefCell<BoxedResolver>>,
) -> 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)
})
}
}
}
}
Expand Down
14 changes: 7 additions & 7 deletions src/librustc_interface/queries.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ pub(crate) struct Queries {
parse: Query<ast::Crate>,
crate_name: Query<String>,
register_plugins: Query<(ast::Crate, PluginInfo)>,
expansion: Query<(ast::Crate, Rc<Option<RefCell<BoxedResolver>>>)>,
expansion: Query<(ast::Crate, Steal<Rc<RefCell<BoxedResolver>>>)>,
dep_graph: Query<DepGraph>,
lower_to_hir: Query<(Steal<hir::map::Forest>, ExpansionResult)>,
prepare_outputs: Query<OutputFilenames>,
Expand Down Expand Up @@ -142,7 +142,7 @@ impl Compiler {

pub fn expansion(
&self
) -> Result<&Query<(ast::Crate, Rc<Option<RefCell<BoxedResolver>>>)>> {
) -> Result<&Query<(ast::Crate, Steal<Rc<RefCell<BoxedResolver>>>)>> {
self.queries.expansion.compute(|| {
let crate_name = self.crate_name()?.peek().clone();
let (krate, plugin_info) = self.register_plugins()?.take();
Expand All @@ -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)))))
})
}

Expand All @@ -176,9 +176,10 @@ impl Compiler {
pub fn lower_to_hir(&self) -> Result<&Query<(Steal<hir::map::Forest>, 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(),
Expand All @@ -187,7 +188,6 @@ impl Compiler {
&krate
)
})?);
expansion_result.give((krate, Rc::new(None)));
Ok((hir, BoxedResolver::to_expansion_result(resolver)))
})
}
Expand Down
4 changes: 1 addition & 3 deletions src/librustdoc/clean/blanket_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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> {
Expand All @@ -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))
Expand Down
6 changes: 3 additions & 3 deletions src/librustdoc/clean/inline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -326,7 +326,7 @@ pub fn build_impl(cx: &DocContext<'_>, did: DefId, attrs: Option<Attrs<'_>>,
// 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
}
}
Expand All @@ -347,7 +347,7 @@ pub fn build_impl(cx: &DocContext<'_>, did: DefId, attrs: Option<Attrs<'_>>,
// 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
}
}
Expand Down
78 changes: 41 additions & 37 deletions src/librustdoc/clean/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -138,10 +137,15 @@ pub struct Crate {
pub masked_crates: FxHashSet<CrateNum>,
}

impl<'a, 'tcx> Clean<Crate> for visit_ast::RustdocVisitor<'a, '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 @@ -159,7 +163,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 = module.clean(cx);
let mut masked_crates = FxHashSet::default();

match module.inner {
Expand All @@ -169,7 +173,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 Expand Up @@ -652,9 +656,9 @@ impl Clean<Item> 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,
Expand Down Expand Up @@ -1938,8 +1942,8 @@ impl Clean<Item> 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,
Expand Down Expand Up @@ -2138,8 +2142,8 @@ impl Clean<Item> 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,
Expand Down Expand Up @@ -2168,8 +2172,8 @@ impl Clean<Item> 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),
Expand Down Expand Up @@ -3242,8 +3246,8 @@ impl Clean<Item> 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),
Expand All @@ -3262,8 +3266,8 @@ impl Clean<Item> 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),
Expand Down Expand Up @@ -3309,8 +3313,8 @@ impl Clean<Item> 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),
Expand All @@ -3332,8 +3336,8 @@ impl Clean<Item> 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),
Expand Down Expand Up @@ -3637,8 +3641,8 @@ impl Clean<Item> 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),
Expand All @@ -3661,8 +3665,8 @@ impl Clean<Item> 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),
Expand Down Expand Up @@ -3712,8 +3716,8 @@ impl Clean<Item> 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),
Expand All @@ -3737,8 +3741,8 @@ impl Clean<Item> 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),
Expand Down Expand Up @@ -3824,8 +3828,8 @@ impl Clean<Vec<Item>> 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),
Expand Down Expand Up @@ -4063,8 +4067,8 @@ impl Clean<Item> 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,
}
}
Expand Down Expand Up @@ -4246,8 +4250,8 @@ impl Clean<Item> 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{}}}",
Expand All @@ -4274,8 +4278,8 @@ impl Clean<Item> 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,
Expand Down
Loading