Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions compiler/rustc_interface/src/passes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -963,6 +963,11 @@ pub fn create_and_enter_global_ctxt<T, F: for<'tcx> FnOnce(TyCtxt<'tcx>) -> T>(

let incremental = dep_graph.is_fully_enabled();

// is_doc_hidden hook is reset to query call for incremental build (fallback for optimization)
if incremental {
providers.hooks.is_doc_hidden = |tcx, def_id| tcx.is_doc_hidden_q(def_id);
}

let gcx_cell = OnceLock::new();
let arena = WorkerLocal::new(|_| Arena::default());
let hir_arena = WorkerLocal::new(|_| rustc_hir::Arena::default());
Expand Down
31 changes: 28 additions & 3 deletions compiler/rustc_metadata/src/rmeta/decoder/cstore_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use std::sync::Arc;

use rustc_hir::attrs::Deprecation;
use rustc_hir::def::{CtorKind, DefKind};
use rustc_hir::def_id::{CrateNum, DefId, DefIdMap, LOCAL_CRATE};
use rustc_hir::def_id::{CrateNum, DefId, DefIdMap, LOCAL_CRATE, LocalDefId};
use rustc_hir::definitions::{DefKey, DefPath, DefPathHash};
use rustc_middle::arena::ArenaAllocatable;
use rustc_middle::bug;
Expand All @@ -18,7 +18,7 @@ use rustc_middle::util::Providers;
use rustc_session::cstore::{CrateStore, ExternCrate};
use rustc_session::{Session, StableCrateId};
use rustc_span::hygiene::ExpnId;
use rustc_span::{Span, Symbol, kw};
use rustc_span::{Span, Symbol, kw, sym};

use super::{Decodable, DecodeContext, DecodeIterator};
use crate::creader::{CStore, LoadedMacro};
Expand Down Expand Up @@ -396,7 +396,7 @@ provide! { tcx, def_id, other, cdata,
crate_extern_paths => { cdata.source().paths().cloned().collect() }
expn_that_defined => { cdata.get_expn_that_defined(def_id.index, tcx.sess) }
default_field => { cdata.get_default_field(def_id.index) }
is_doc_hidden => { cdata.get_attr_flags(def_id.index).contains(AttrFlags::IS_DOC_HIDDEN) }
is_doc_hidden_q => { cdata.get_attr_flags(def_id.index).contains(AttrFlags::IS_DOC_HIDDEN) }
doc_link_resolutions => { tcx.arena.alloc(cdata.get_doc_link_resolutions(def_id.index)) }
doc_link_traits_in_scope => {
tcx.arena.alloc_from_iter(cdata.get_doc_link_traits_in_scope(def_id.index))
Expand Down Expand Up @@ -679,6 +679,29 @@ impl CrateStore for CStore {
}
}

/// Determines whether an item is directly annotated with `doc(hidden)`.
fn is_doc_hidden_local(tcx: TyCtxt<'_>, def_id: LocalDefId) -> bool {
tcx.get_attrs(def_id, sym::doc)
.filter_map(|attr| attr.meta_item_list())
.any(|items| items.iter().any(|item| item.has_name(sym::hidden)))
}

// Optimization of is_doc_hidden query in case of non-incremental build.
// is_doc_hidden query itself renamed into is_doc_hidden_q.
#[inline]
fn is_doc_hidden(tcx: TyCtxt<'_>, def_id: DefId) -> bool {
if let Some(local) = def_id.as_local() {
is_doc_hidden_local(tcx, local)
} else {
let cdata = rustc_data_structures::sync::FreezeReadGuard::map(CStore::from_tcx(tcx), |c| {
c.get_crate_data(def_id.krate).cdata
});
let cdata =
crate::creader::CrateMetadataRef { cdata: &cdata, cstore: &CStore::from_tcx(tcx) };
cdata.get_attr_flags(def_id.index).contains(AttrFlags::IS_DOC_HIDDEN)
}
}

fn provide_cstore_hooks(providers: &mut Providers) {
providers.hooks.def_path_hash_to_def_id_extern = |tcx, hash, stable_crate_id| {
// If this is a DefPathHash from an upstream crate, let the CrateStore map
Expand Down Expand Up @@ -706,4 +729,6 @@ fn provide_cstore_hooks(providers: &mut Providers) {
cdata.imported_source_file(file_index as u32, tcx.sess);
}
};
providers.hooks.is_doc_hidden = is_doc_hidden;
providers.is_doc_hidden_q = is_doc_hidden_local;
}
3 changes: 3 additions & 0 deletions compiler/rustc_middle/src/hooks/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,9 @@ declare_hooks! {
/// Ensure the given scalar is valid for the given type.
/// This checks non-recursive runtime validity.
hook validate_scalar_in_layout(scalar: crate::ty::ScalarInt, ty: Ty<'tcx>) -> bool;

/// Determines whether an item is annotated with `#[doc(hidden)]`.
hook is_doc_hidden(def_id: DefId) -> bool;
}

#[cold]
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_middle/src/query/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1511,7 +1511,7 @@ rustc_queries! {
}

/// Determines whether an item is annotated with `#[doc(hidden)]`.
query is_doc_hidden(def_id: DefId) -> bool {
query is_doc_hidden_q(def_id: DefId) -> bool {
desc { |tcx| "checking whether `{}` is `doc(hidden)`", tcx.def_path_str(def_id) }
separate_provide_extern
}
Expand Down
8 changes: 0 additions & 8 deletions compiler/rustc_middle/src/ty/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1662,13 +1662,6 @@ pub fn reveal_opaque_types_in_bounds<'tcx>(
val.fold_with(&mut visitor)
}

/// Determines whether an item is directly annotated with `doc(hidden)`.
fn is_doc_hidden(tcx: TyCtxt<'_>, def_id: LocalDefId) -> bool {
tcx.get_attrs(def_id, sym::doc)
.filter_map(|attr| attr.meta_item_list())
.any(|items| items.iter().any(|item| item.has_name(sym::hidden)))
}

/// Determines whether an item is annotated with `doc(notable_trait)`.
pub fn is_doc_notable_trait(tcx: TyCtxt<'_>, def_id: DefId) -> bool {
tcx.get_attrs(def_id, sym::doc)
Expand Down Expand Up @@ -1702,7 +1695,6 @@ pub fn intrinsic_raw(tcx: TyCtxt<'_>, def_id: LocalDefId) -> Option<ty::Intrinsi
pub fn provide(providers: &mut Providers) {
*providers = Providers {
reveal_opaque_types_in_bounds,
is_doc_hidden,
is_doc_notable_trait,
intrinsic_raw,
..*providers
Expand Down
2 changes: 1 addition & 1 deletion src/librustdoc/clean/inline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ pub(crate) fn try_inline_glob(
.iter()
.filter(|child| !child.reexport_chain.is_empty())
.filter_map(|child| child.res.opt_def_id())
.filter(|def_id| !cx.tcx.is_doc_hidden(def_id))
.filter(|def_id| !cx.tcx.is_doc_hidden(*def_id))
.collect();
let attrs = cx.tcx.hir_attrs(import.hir_id());
let mut items = build_module_items(
Expand Down
2 changes: 1 addition & 1 deletion src/librustdoc/visit_ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,7 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> {
.unwrap_or(target_def_id);
item_def_id != import_def_id
&& self.cx.cache.effective_visibilities.is_directly_public(tcx, item_def_id.to_def_id())
&& !tcx.is_doc_hidden(item_def_id)
&& !tcx.is_doc_hidden(item_def_id.to_def_id())
&& !inherits_doc_hidden(tcx, item_def_id, None)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ struct BodyVisitor<'a, 'tcx> {
fn is_public_macro(cx: &LateContext<'_>, def_id: LocalDefId) -> bool {
(cx.effective_visibilities.is_exported(def_id)
|| find_attr!(cx.tcx.get_all_attrs(def_id), AttributeKind::MacroExport { .. }))
&& !cx.tcx.is_doc_hidden(def_id)
&& !cx.tcx.is_doc_hidden(def_id.to_def_id())
}

impl<'tcx> Visitor<'tcx> for BodyVisitor<'_, 'tcx> {
Expand Down
2 changes: 1 addition & 1 deletion src/tools/clippy/clippy_lints/src/new_without_default.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ impl<'tcx> LateLintPass<'tcx> for NewWithoutDefault {
// can't be implemented for unsafe new
&& !sig.header.is_unsafe()
// shouldn't be implemented when it is hidden in docs
&& !cx.tcx.is_doc_hidden(impl_item.owner_id.def_id)
&& !cx.tcx.is_doc_hidden(impl_item.owner_id.def_id.to_def_id())
// when the result of `new()` depends on a parameter we should not require
// an impl of `Default`
&& impl_item.generics.params.is_empty()
Expand Down
Loading