Skip to content
Open
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
2 changes: 1 addition & 1 deletion src/librustdoc/clean/types/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ fn should_not_trim() {
fn is_same_generic() {
use crate::clean::types::{PrimitiveType, Type};
use crate::formats::cache::Cache;
let cache = Cache::new(false, false);
let cache = Cache::new(false, false, false, false);
let generic = Type::Generic(rustc_span::symbol::sym::Any);
let unit = Type::Primitive(PrimitiveType::Unit);
assert!(!generic.is_doc_subtype_of(&unit, &cache));
Expand Down
8 changes: 8 additions & 0 deletions src/librustdoc/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,10 @@ pub(crate) struct RenderOptions {
pub(crate) document_private: bool,
/// Document items that have `doc(hidden)`.
pub(crate) document_hidden: bool,
/// Hide items marked deprecated from listings, but pages and links still generated.
pub(crate) hide_deprecated: bool,
/// Hide items marked unstable from listings, but pages and links still generated.
pub(crate) hide_unstable: bool,
/// If `true`, generate a JSON file in the crate folder instead of HTML redirection files.
pub(crate) generate_redirect_map: bool,
/// Show the memory layout of types in the docs.
Expand Down Expand Up @@ -788,6 +792,8 @@ impl Options {
let test_runtool_args = matches.opt_strs("test-runtool-arg");
let document_private = matches.opt_present("document-private-items");
let document_hidden = matches.opt_present("document-hidden-items");
let hide_deprecated = matches.opt_present("hide-deprecated-items");
let hide_unstable = matches.opt_present("hide-unstable-options");
let run_check = matches.opt_present("check");
let generate_redirect_map = matches.opt_present("generate-redirect-map");
let show_type_layout = matches.opt_present("show-type-layout");
Expand Down Expand Up @@ -888,6 +894,8 @@ impl Options {
markdown_playground_url,
document_private,
document_hidden,
hide_deprecated,
hide_unstable,
generate_redirect_map,
show_type_layout,
unstable_features,
Expand Down
7 changes: 6 additions & 1 deletion src/librustdoc/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -384,7 +384,12 @@ pub(crate) fn run_global_ctxt(
impl_trait_bounds: Default::default(),
generated_synthetics: Default::default(),
auto_traits,
cache: Cache::new(render_options.document_private, render_options.document_hidden),
cache: Cache::new(
render_options.document_private,
render_options.document_hidden,
render_options.hide_deprecated,
render_options.hide_unstable,
),
inlined: FxHashSet::default(),
output_format,
show_coverage,
Expand Down
19 changes: 17 additions & 2 deletions src/librustdoc/formats/cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,10 @@ pub(crate) struct Cache {
/// Whether to document hidden items.
/// This is stored in `Cache` so it doesn't need to be passed through all rustdoc functions.
pub(crate) document_hidden: bool,
/// Whether to hide items explicitly marked `#[deprecated]` from listings.
pub(crate) hide_deprecated: bool,
/// Whether to hide items that are unstable from listings.
pub(crate) hide_unstable: bool,

/// Crates marked with [`#[doc(masked)]`][doc_masked].
///
Expand Down Expand Up @@ -143,8 +147,19 @@ struct CacheBuilder<'a, 'tcx> {
}

impl Cache {
pub(crate) fn new(document_private: bool, document_hidden: bool) -> Self {
Cache { document_private, document_hidden, ..Cache::default() }
pub(crate) fn new(
document_private: bool,
document_hidden: bool,
hide_deprecated: bool,
hide_unstable: bool,
) -> Self {
Cache {
document_private,
document_hidden,
hide_deprecated,
hide_unstable,
..Cache::default()
}
}

fn parent_stack_last_impl_and_trait_id(&self) -> (Option<DefId>, Option<DefId>) {
Expand Down
25 changes: 24 additions & 1 deletion src/librustdoc/html/render/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -313,11 +313,25 @@ impl<'tcx> Context<'tcx> {
let mut map: BTreeMap<_, Vec<_>> = BTreeMap::new();
let mut inserted: FxHashMap<ItemType, FxHashSet<Symbol>> = FxHashMap::default();

let hide_deprecated = self.shared.cache.hide_deprecated;
let hide_unstable = self.shared.cache.hide_unstable;
let tcx = self.tcx();

for item in &m.items {
if item.is_stripped() {
continue;
}

let is_deprecated = item.deprecation(tcx).is_some();
let is_unstable = item
.stability(tcx)
.is_some_and(|s| s.is_unstable() && s.feature != sym::rustc_private);

if (hide_deprecated && is_deprecated) || (hide_unstable && is_unstable) {
// Hide deprecated/unstable items from sidebar listings.
continue;
}

let short = item.type_();
let myname = match item.name {
None => continue,
Expand Down Expand Up @@ -866,7 +880,16 @@ impl<'tcx> FormatRenderer<'tcx> for Context<'tcx> {
self.shared.fs.write(joint_dst, buf)?;

if !self.info.render_redirect_pages {
self.shared.all.borrow_mut().append(full_path(self, item), &item_type);
let hide_deprecated = self.shared.cache.hide_deprecated;
let hide_unstable = self.shared.cache.hide_unstable;
let tcx = self.tcx();
let is_deprecated = item.deprecation(tcx).is_some();
let is_unstable = item
.stability(tcx)
.is_some_and(|s| s.is_unstable() && s.feature != sym::rustc_private);
if !(hide_deprecated && is_deprecated) && !(hide_unstable && is_unstable) {
self.shared.all.borrow_mut().append(full_path(self, item), &item_type);
}
}
// If the item is a macro, redirect from the old macro URL (with !)
// to the new one (without).
Expand Down
16 changes: 16 additions & 0 deletions src/librustdoc/html/render/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1584,6 +1584,10 @@ fn render_deref_methods(
}

fn should_render_item(item: &clean::Item, deref_mut_: bool, tcx: TyCtxt<'_>) -> bool {
if item.deprecation(tcx).is_some() {
return false;
}

let self_type_opt = match item.kind {
clean::MethodItem(ref method, _) => method.decl.receiver_type(),
clean::RequiredMethodItem(ref method) => method.decl.receiver_type(),
Expand Down Expand Up @@ -1787,6 +1791,18 @@ fn render_impl(
}
};

// Skip deprecated/unstable associated items when flags are enabled.
let hide_deprecated = cx.shared.cache.hide_deprecated;
let hide_unstable = cx.shared.cache.hide_unstable;
let tcx = cx.tcx();
let is_deprecated = item.deprecation(tcx).is_some();
let is_unstable = item
.stability(tcx)
.is_some_and(|s| s.is_unstable() && s.feature != sym::rustc_private);
if (hide_deprecated && is_deprecated) || (hide_unstable && is_unstable) {
return Ok(());
}

let in_trait_class = if trait_.is_some() { " trait-impl" } else { "" };

let mut doc_buffer = String::new();
Expand Down
39 changes: 39 additions & 0 deletions src/librustdoc/html/render/print_item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -412,6 +412,45 @@ fn item_module(cx: &Context<'_>, item: &clean::Item, items: &[clean::Item]) -> i
)?;

for (_, myitem) in &not_stripped_items[&type_] {
// Skip deprecated/unstable items in module listings when the flags are enabled.
let hide_deprecated = cx.shared.cache.hide_deprecated;
let hide_unstable = cx.shared.cache.hide_unstable;

// Direct attributes on the item
let is_deprecated_item = myitem.deprecation(tcx).is_some();
let is_unstable_item = myitem
.stability(tcx)
.is_some_and(|s| s.is_unstable() && s.feature != sym::rustc_private);

// Reexports/imports/extern crate metadata
let (is_deprecated_reexport, is_unstable_reexport) = match myitem.kind {
clean::ImportItem(ref import) => {
if let Some(import_def_id) = import.source.did {
let depr = tcx.lookup_deprecation(import_def_id).is_some();
let unst = tcx.lookup_stability(import_def_id).is_some_and(|s| {
s.is_unstable() && s.feature != sym::rustc_private
});
(depr, unst)
} else {
(false, false)
}
}
clean::ExternCrateItem { .. } => {
let def_id = myitem.item_id.expect_def_id();
let depr = tcx.lookup_deprecation(def_id).is_some();
let unst = tcx
.lookup_stability(def_id)
.is_some_and(|s| s.is_unstable() && s.feature != sym::rustc_private);
(depr, unst)
}
_ => (false, false),
};

if (hide_deprecated && (is_deprecated_item || is_deprecated_reexport))
|| (hide_unstable && (is_unstable_item || is_unstable_reexport))
{
continue;
}
match myitem.kind {
clean::ExternCrateItem { ref src } => {
use crate::html::format::print_anchor;
Expand Down
16 changes: 16 additions & 0 deletions src/librustdoc/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,22 @@ fn opts() -> Vec<RustcOptGroup> {
"document items that have doc(hidden)",
"",
),
opt(
Unstable,
FlagMulti,
"",
"hide-deprecated-items",
"Hide items marked deprecated from listings, but pages and links still generated.",
"",
),
opt(
Unstable,
FlagMulti,
"",
"hide-unstable-options",
"Hide items marked unstable from listings, but pages and links still generated.",
"",
),
opt(Stable, FlagMulti, "", "test", "run code examples as tests", ""),
opt(Stable, Multi, "", "test-args", "arguments to pass to the test runner", "ARGS"),
opt(
Expand Down
6 changes: 6 additions & 0 deletions tests/run-make/rustdoc-default-output/output-default.stdout
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,12 @@ Options:
document private items
--document-hidden-items
document items that have doc(hidden)
--hide-deprecated-items
Hide items marked deprecated from listings, but pages
and links still generated.
--hide-unstable-options
Hide items marked unstable from listings, but pages
and links still generated.
--test run code examples as tests
--test-args ARGS
arguments to pass to the test runner
Expand Down
Loading