Skip to content

Commit 219856d

Browse files
Auto merge of #146529 - fmease:rustdoc-nuke-passes-list, r=<try>
rustdoc: Nuke `--passes=list`
2 parents ade8487 + 18dcad6 commit 219856d

17 files changed

+70
-296
lines changed

src/librustdoc/config.rs

Lines changed: 0 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ use crate::externalfiles::ExternalHtml;
2424
use crate::html::markdown::IdMap;
2525
use crate::html::render::StylePath;
2626
use crate::html::static_files;
27-
use crate::passes::{self, Condition};
2827
use crate::scrape_examples::{AllCallLocations, ScrapeExamplesOptions};
2928
use crate::{html, opts, theme};
3029

@@ -422,38 +421,6 @@ impl Options {
422421
// check for deprecated options
423422
check_deprecated_options(matches, dcx);
424423

425-
if matches.opt_strs("passes") == ["list"] {
426-
println!("Available passes for running rustdoc:");
427-
for pass in passes::PASSES {
428-
println!("{:>20} - {}", pass.name, pass.description);
429-
}
430-
println!("\nDefault passes for rustdoc:");
431-
for p in passes::DEFAULT_PASSES {
432-
print!("{:>20}", p.pass.name);
433-
println_condition(p.condition);
434-
}
435-
436-
if nightly_options::match_is_nightly_build(matches) {
437-
println!("\nPasses run with `--show-coverage`:");
438-
for p in passes::COVERAGE_PASSES {
439-
print!("{:>20}", p.pass.name);
440-
println_condition(p.condition);
441-
}
442-
}
443-
444-
fn println_condition(condition: Condition) {
445-
use Condition::*;
446-
match condition {
447-
Always => println!(),
448-
WhenDocumentPrivate => println!(" (when --document-private-items)"),
449-
WhenNotDocumentPrivate => println!(" (when not --document-private-items)"),
450-
WhenNotDocumentHidden => println!(" (when not --document-hidden-items)"),
451-
}
452-
}
453-
454-
return None;
455-
}
456-
457424
let mut emit = FxIndexMap::<_, EmitType>::default();
458425
for list in matches.opt_strs("emit") {
459426
for kind in list.split(',') {

src/librustdoc/core.rs

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ use crate::config::{Options as RustdocOptions, OutputFormat, RenderOptions};
3333
use crate::formats::cache::Cache;
3434
use crate::html::macro_expansion::{ExpandedCode, source_macro_expansion};
3535
use crate::passes;
36-
use crate::passes::Condition::*;
3736
use crate::passes::collect_intra_doc_links::LinkCollector;
3837

3938
pub(crate) struct DocContext<'tcx> {
@@ -421,38 +420,39 @@ pub(crate) fn run_global_ctxt(
421420
}
422421
}
423422

424-
info!("Executing passes");
425-
426-
let mut visited = FxHashMap::default();
427-
let mut ambiguous = FxIndexMap::default();
428-
429-
for p in passes::defaults(show_coverage) {
430-
let run = match p.condition {
431-
Always => true,
432-
WhenDocumentPrivate => ctxt.render_options.document_private,
433-
WhenNotDocumentPrivate => !ctxt.render_options.document_private,
434-
WhenNotDocumentHidden => !ctxt.render_options.document_hidden,
435-
};
436-
if run {
437-
debug!("running pass {}", p.pass.name);
438-
if let Some(run_fn) = p.pass.run {
439-
krate = tcx.sess.time(p.pass.name, || run_fn(krate, &mut ctxt));
440-
} else {
441-
let (k, LinkCollector { visited_links, ambiguous_links, .. }) =
442-
passes::collect_intra_doc_links::collect_intra_doc_links(krate, &mut ctxt);
443-
krate = k;
444-
visited = visited_links;
445-
ambiguous = ambiguous_links;
446-
}
447-
}
423+
info!("running passes");
424+
425+
let mut visited_links = FxHashMap::default();
426+
let mut ambiguous_links = FxIndexMap::default();
427+
428+
if !show_coverage {
429+
krate = passes::track!(tcx, collect_trait_impls(krate, &mut ctxt));
430+
krate = passes::track!(tcx, check_doc_test_visibility(krate, &mut ctxt));
431+
krate = passes::track!(tcx, check_doc_cfg(krate, &mut ctxt));
432+
krate = passes::track!(tcx, strip_aliased_non_local(krate, &mut ctxt));
433+
}
434+
435+
krate = passes::track!(tcx, strip_hidden(krate, &mut ctxt));
436+
krate = passes::track!(tcx, strip_private(krate, &mut ctxt));
437+
438+
if show_coverage {
439+
krate = passes::track!(tcx, calculate_doc_coverage(krate, &mut ctxt));
440+
}
441+
442+
if !show_coverage {
443+
krate = passes::track!(tcx, strip_priv_imports(krate, &mut ctxt));
444+
(krate, LinkCollector { visited_links, ambiguous_links, .. }) =
445+
passes::track!(tcx, collect_intra_doc_links(krate, &mut ctxt));
446+
krate = passes::track!(tcx, propagate_doc_cfg(krate, &mut ctxt));
447+
krate = passes::track!(tcx, propagate_stability(krate, &mut ctxt));
448+
krate = passes::track!(tcx, lint(krate, &mut ctxt));
448449
}
449450

450451
tcx.sess.time("check_lint_expectations", || tcx.check_expectations(Some(sym::rustdoc)));
451452

452453
krate = tcx.sess.time("create_format_cache", || Cache::populate(&mut ctxt, krate));
453454

454-
let mut collector =
455-
LinkCollector { cx: &mut ctxt, visited_links: visited, ambiguous_links: ambiguous };
455+
let mut collector = LinkCollector { cx: &mut ctxt, visited_links, ambiguous_links };
456456
collector.resolve_ambiguities();
457457

458458
tcx.dcx().abort_if_errors();

src/librustdoc/lib.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#![feature(assert_matches)]
99
#![feature(box_patterns)]
1010
#![feature(debug_closure_helpers)]
11+
#![feature(decl_macro)]
1112
#![feature(file_buffered)]
1213
#![feature(formatting_options)]
1314
#![feature(if_let_guard)]
@@ -218,7 +219,7 @@ fn init_logging(early_dcx: &EarlyDiagCtxt) {
218219
.with_ansi(color_logs)
219220
.with_targets(true)
220221
.with_wraparound(10)
221-
.with_verbose_exit(true)
222+
.with_verbose_exit(false)
222223
.with_verbose_entry(true)
223224
.with_indent_amount(2);
224225
#[cfg(debug_assertions)]

src/librustdoc/passes/calculate_doc_coverage.rs

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,13 @@ use tracing::debug;
1414
use crate::clean;
1515
use crate::core::DocContext;
1616
use crate::html::markdown::{ErrorCodes, find_testable_code};
17-
use crate::passes::Pass;
1817
use crate::passes::check_doc_test_visibility::{Tests, should_have_doc_example};
1918
use crate::visit::DocVisitor;
2019

21-
pub(crate) const CALCULATE_DOC_COVERAGE: Pass = Pass {
22-
name: "calculate-doc-coverage",
23-
run: Some(calculate_doc_coverage),
24-
description: "counts the number of items with and without documentation",
25-
};
26-
27-
fn calculate_doc_coverage(krate: clean::Crate, ctx: &mut DocContext<'_>) -> clean::Crate {
20+
pub(crate) fn calculate_doc_coverage(
21+
krate: clean::Crate,
22+
ctx: &mut DocContext<'_>,
23+
) -> clean::Crate {
2824
let mut calc = CoverageCalculator { items: Default::default(), ctx };
2925
calc.visit_crate(&krate);
3026

src/librustdoc/passes/check_doc_cfg.rs

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,10 @@ use rustc_hir::def_id::LocalDefId;
33
use rustc_middle::ty::TyCtxt;
44
use rustc_span::sym;
55

6-
use super::Pass;
76
use crate::clean::{Attributes, Crate, Item};
87
use crate::core::DocContext;
98
use crate::visit::DocVisitor;
109

11-
pub(crate) const CHECK_DOC_CFG: Pass = Pass {
12-
name: "check-doc-cfg",
13-
run: Some(check_doc_cfg),
14-
description: "checks `#[doc(cfg(...))]` for stability feature and unexpected cfgs",
15-
};
16-
1710
pub(crate) fn check_doc_cfg(krate: Crate, cx: &mut DocContext<'_>) -> Crate {
1811
let mut checker = DocCfgChecker { cx };
1912
checker.visit_crate(&krate);

src/librustdoc/passes/check_doc_test_visibility.rs

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,20 +10,12 @@ use rustc_middle::lint::{LevelAndSource, LintLevelSource};
1010
use rustc_session::lint;
1111
use tracing::debug;
1212

13-
use super::Pass;
14-
use crate::clean;
1513
use crate::clean::utils::inherits_doc_hidden;
16-
use crate::clean::*;
14+
use crate::clean::{self, *};
1715
use crate::core::DocContext;
1816
use crate::html::markdown::{ErrorCodes, Ignore, LangString, MdRelLine, find_testable_code};
1917
use crate::visit::DocVisitor;
2018

21-
pub(crate) const CHECK_DOC_TEST_VISIBILITY: Pass = Pass {
22-
name: "check_doc_test_visibility",
23-
run: Some(check_doc_test_visibility),
24-
description: "run various visibility-related lints on doctests",
25-
};
26-
2719
struct DocTestVisibilityLinter<'a, 'tcx> {
2820
cx: &'a mut DocContext<'tcx>,
2921
}

src/librustdoc/passes/collect_intra_doc_links.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,8 @@ use crate::clean::{self, Crate, Item, ItemId, ItemLink, PrimitiveType};
3434
use crate::core::DocContext;
3535
use crate::html::markdown::{MarkdownLink, MarkdownLinkRange, markdown_links};
3636
use crate::lint::{BROKEN_INTRA_DOC_LINKS, PRIVATE_INTRA_DOC_LINKS};
37-
use crate::passes::Pass;
3837
use crate::visit::DocVisitor;
3938

40-
pub(crate) const COLLECT_INTRA_DOC_LINKS: Pass =
41-
Pass { name: "collect-intra-doc-links", run: None, description: "resolves intra-doc links" };
42-
4339
pub(crate) fn collect_intra_doc_links<'a, 'tcx>(
4440
krate: Crate,
4541
cx: &'a mut DocContext<'tcx>,

src/librustdoc/passes/collect_trait_impls.rs

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,11 @@ use rustc_middle::ty;
88
use rustc_span::symbol::sym;
99
use tracing::debug;
1010

11-
use super::Pass;
1211
use crate::clean::*;
1312
use crate::core::DocContext;
1413
use crate::formats::cache::Cache;
1514
use crate::visit::DocVisitor;
1615

17-
pub(crate) const COLLECT_TRAIT_IMPLS: Pass = Pass {
18-
name: "collect-trait-impls",
19-
run: Some(collect_trait_impls),
20-
description: "retrieves trait impls for items in the crate",
21-
};
22-
2316
pub(crate) fn collect_trait_impls(mut krate: Crate, cx: &mut DocContext<'_>) -> Crate {
2417
let tcx = cx.tcx;
2518
// We need to check if there are errors before running this pass because it would crash when

src/librustdoc/passes/lint.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,15 @@ mod html_tags;
77
mod redundant_explicit_links;
88
mod unescaped_backticks;
99

10-
use super::Pass;
1110
use crate::clean::*;
1211
use crate::core::DocContext;
1312
use crate::visit::DocVisitor;
1413

15-
pub(crate) const RUN_LINTS: Pass =
16-
Pass { name: "run-lints", run: Some(run_lints), description: "runs some of rustdoc's lints" };
17-
1814
struct Linter<'a, 'tcx> {
1915
cx: &'a mut DocContext<'tcx>,
2016
}
2117

22-
pub(crate) fn run_lints(krate: Crate, cx: &mut DocContext<'_>) -> Crate {
18+
pub(crate) fn lint(krate: Crate, cx: &mut DocContext<'_>) -> Crate {
2319
Linter { cx }.visit_crate(&krate);
2420
krate
2521
}

src/librustdoc/passes/mod.rs

Lines changed: 16 additions & 120 deletions
Original file line numberDiff line numberDiff line change
@@ -1,127 +1,23 @@
11
//! Contains information about "passes", used to modify crate information during the documentation
22
//! process.
33
4-
use self::Condition::*;
5-
use crate::clean;
6-
use crate::core::DocContext;
7-
84
mod stripper;
95
pub(crate) use stripper::*;
106

11-
mod strip_aliased_non_local;
12-
pub(crate) use self::strip_aliased_non_local::STRIP_ALIASED_NON_LOCAL;
13-
14-
mod strip_hidden;
15-
pub(crate) use self::strip_hidden::STRIP_HIDDEN;
16-
17-
mod strip_private;
18-
pub(crate) use self::strip_private::STRIP_PRIVATE;
19-
20-
mod strip_priv_imports;
21-
pub(crate) use self::strip_priv_imports::STRIP_PRIV_IMPORTS;
22-
23-
mod propagate_doc_cfg;
24-
pub(crate) use self::propagate_doc_cfg::PROPAGATE_DOC_CFG;
25-
26-
mod propagate_stability;
27-
pub(crate) use self::propagate_stability::PROPAGATE_STABILITY;
28-
7+
pub(crate) mod calculate_doc_coverage;
8+
pub(crate) mod check_doc_cfg;
9+
pub(crate) mod check_doc_test_visibility;
2910
pub(crate) mod collect_intra_doc_links;
30-
pub(crate) use self::collect_intra_doc_links::COLLECT_INTRA_DOC_LINKS;
31-
32-
mod check_doc_test_visibility;
33-
pub(crate) use self::check_doc_test_visibility::CHECK_DOC_TEST_VISIBILITY;
34-
35-
mod check_doc_cfg;
36-
pub(crate) use self::check_doc_cfg::CHECK_DOC_CFG;
37-
38-
mod collect_trait_impls;
39-
pub(crate) use self::collect_trait_impls::COLLECT_TRAIT_IMPLS;
40-
41-
mod calculate_doc_coverage;
42-
pub(crate) use self::calculate_doc_coverage::CALCULATE_DOC_COVERAGE;
43-
44-
mod lint;
45-
pub(crate) use self::lint::RUN_LINTS;
46-
47-
/// A single pass over the cleaned documentation.
48-
///
49-
/// Runs in the compiler context, so it has access to types and traits and the like.
50-
#[derive(Copy, Clone)]
51-
pub(crate) struct Pass {
52-
pub(crate) name: &'static str,
53-
pub(crate) run: Option<fn(clean::Crate, &mut DocContext<'_>) -> clean::Crate>,
54-
pub(crate) description: &'static str,
55-
}
56-
57-
/// In a list of passes, a pass that may or may not need to be run depending on options.
58-
#[derive(Copy, Clone)]
59-
pub(crate) struct ConditionalPass {
60-
pub(crate) pass: Pass,
61-
pub(crate) condition: Condition,
62-
}
63-
64-
/// How to decide whether to run a conditional pass.
65-
#[derive(Copy, Clone)]
66-
pub(crate) enum Condition {
67-
Always,
68-
/// When `--document-private-items` is passed.
69-
WhenDocumentPrivate,
70-
/// When `--document-private-items` is not passed.
71-
WhenNotDocumentPrivate,
72-
/// When `--document-hidden-items` is not passed.
73-
WhenNotDocumentHidden,
74-
}
75-
76-
/// The full list of passes.
77-
pub(crate) const PASSES: &[Pass] = &[
78-
CHECK_DOC_CFG,
79-
CHECK_DOC_TEST_VISIBILITY,
80-
STRIP_ALIASED_NON_LOCAL,
81-
STRIP_HIDDEN,
82-
STRIP_PRIVATE,
83-
STRIP_PRIV_IMPORTS,
84-
PROPAGATE_DOC_CFG,
85-
PROPAGATE_STABILITY,
86-
COLLECT_INTRA_DOC_LINKS,
87-
COLLECT_TRAIT_IMPLS,
88-
CALCULATE_DOC_COVERAGE,
89-
RUN_LINTS,
90-
];
91-
92-
/// The list of passes run by default.
93-
pub(crate) const DEFAULT_PASSES: &[ConditionalPass] = &[
94-
ConditionalPass::always(COLLECT_TRAIT_IMPLS),
95-
ConditionalPass::always(CHECK_DOC_TEST_VISIBILITY),
96-
ConditionalPass::always(CHECK_DOC_CFG),
97-
ConditionalPass::always(STRIP_ALIASED_NON_LOCAL),
98-
ConditionalPass::new(STRIP_HIDDEN, WhenNotDocumentHidden),
99-
ConditionalPass::new(STRIP_PRIVATE, WhenNotDocumentPrivate),
100-
ConditionalPass::new(STRIP_PRIV_IMPORTS, WhenDocumentPrivate),
101-
ConditionalPass::always(COLLECT_INTRA_DOC_LINKS),
102-
ConditionalPass::always(PROPAGATE_DOC_CFG),
103-
ConditionalPass::always(PROPAGATE_STABILITY),
104-
ConditionalPass::always(RUN_LINTS),
105-
];
106-
107-
/// The list of default passes run when `--doc-coverage` is passed to rustdoc.
108-
pub(crate) const COVERAGE_PASSES: &[ConditionalPass] = &[
109-
ConditionalPass::new(STRIP_HIDDEN, WhenNotDocumentHidden),
110-
ConditionalPass::new(STRIP_PRIVATE, WhenNotDocumentPrivate),
111-
ConditionalPass::always(CALCULATE_DOC_COVERAGE),
112-
];
113-
114-
impl ConditionalPass {
115-
pub(crate) const fn always(pass: Pass) -> Self {
116-
Self::new(pass, Always)
117-
}
118-
119-
pub(crate) const fn new(pass: Pass, condition: Condition) -> Self {
120-
ConditionalPass { pass, condition }
121-
}
122-
}
123-
124-
/// Returns the given default set of passes.
125-
pub(crate) fn defaults(show_coverage: bool) -> &'static [ConditionalPass] {
126-
if show_coverage { COVERAGE_PASSES } else { DEFAULT_PASSES }
127-
}
11+
pub(crate) mod collect_trait_impls;
12+
pub(crate) mod lint;
13+
pub(crate) mod propagate_doc_cfg;
14+
pub(crate) mod propagate_stability;
15+
pub(crate) mod strip_aliased_non_local;
16+
pub(crate) mod strip_hidden;
17+
pub(crate) mod strip_priv_imports;
18+
pub(crate) mod strip_private;
19+
20+
pub(crate) macro track($tcx:expr, $name:ident($( $args:tt )*)) {{
21+
tracing::debug!("running pass `{}`", stringify!($name));
22+
$tcx.sess.time(stringify!($name), || self::$name::$name($( $args )*))
23+
}}

0 commit comments

Comments
 (0)