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
33 changes: 0 additions & 33 deletions src/librustdoc/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ use crate::externalfiles::ExternalHtml;
use crate::html::markdown::IdMap;
use crate::html::render::StylePath;
use crate::html::static_files;
use crate::passes::{self, Condition};
use crate::scrape_examples::{AllCallLocations, ScrapeExamplesOptions};
use crate::{html, opts, theme};

Expand Down Expand Up @@ -422,38 +421,6 @@ impl Options {
// check for deprecated options
check_deprecated_options(matches, dcx);

if matches.opt_strs("passes") == ["list"] {
println!("Available passes for running rustdoc:");
for pass in passes::PASSES {
println!("{:>20} - {}", pass.name, pass.description);
}
println!("\nDefault passes for rustdoc:");
for p in passes::DEFAULT_PASSES {
print!("{:>20}", p.pass.name);
println_condition(p.condition);
}

if nightly_options::match_is_nightly_build(matches) {
println!("\nPasses run with `--show-coverage`:");
for p in passes::COVERAGE_PASSES {
print!("{:>20}", p.pass.name);
println_condition(p.condition);
}
}

fn println_condition(condition: Condition) {
use Condition::*;
match condition {
Always => println!(),
WhenDocumentPrivate => println!(" (when --document-private-items)"),
WhenNotDocumentPrivate => println!(" (when not --document-private-items)"),
WhenNotDocumentHidden => println!(" (when not --document-hidden-items)"),
}
}

return None;
}

let mut emit = FxIndexMap::<_, EmitType>::default();
for list in matches.opt_strs("emit") {
for kind in list.split(',') {
Expand Down
54 changes: 27 additions & 27 deletions src/librustdoc/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ use crate::config::{Options as RustdocOptions, OutputFormat, RenderOptions};
use crate::formats::cache::Cache;
use crate::html::macro_expansion::{ExpandedCode, source_macro_expansion};
use crate::passes;
use crate::passes::Condition::*;
use crate::passes::collect_intra_doc_links::LinkCollector;

pub(crate) struct DocContext<'tcx> {
Expand Down Expand Up @@ -421,38 +420,39 @@ pub(crate) fn run_global_ctxt(
}
}

info!("Executing passes");

let mut visited = FxHashMap::default();
let mut ambiguous = FxIndexMap::default();

for p in passes::defaults(show_coverage) {
let run = match p.condition {
Always => true,
WhenDocumentPrivate => ctxt.render_options.document_private,
WhenNotDocumentPrivate => !ctxt.render_options.document_private,
WhenNotDocumentHidden => !ctxt.render_options.document_hidden,
};
if run {
debug!("running pass {}", p.pass.name);
if let Some(run_fn) = p.pass.run {
krate = tcx.sess.time(p.pass.name, || run_fn(krate, &mut ctxt));
} else {
let (k, LinkCollector { visited_links, ambiguous_links, .. }) =
passes::collect_intra_doc_links::collect_intra_doc_links(krate, &mut ctxt);
krate = k;
visited = visited_links;
ambiguous = ambiguous_links;
}
}
info!("running passes");

let mut visited_links = FxHashMap::default();
let mut ambiguous_links = FxIndexMap::default();

if !show_coverage {
krate = passes::track!(tcx, collect_trait_impls(krate, &mut ctxt));
krate = passes::track!(tcx, check_doc_test_visibility(krate, &mut ctxt));
krate = passes::track!(tcx, check_doc_cfg(krate, &mut ctxt));
krate = passes::track!(tcx, strip_aliased_non_local(krate, &mut ctxt));
}

krate = passes::track!(tcx, strip_hidden(krate, &mut ctxt));
krate = passes::track!(tcx, strip_private(krate, &mut ctxt));

if show_coverage {
krate = passes::track!(tcx, calculate_doc_coverage(krate, &mut ctxt));
}

if !show_coverage {
krate = passes::track!(tcx, strip_priv_imports(krate, &mut ctxt));
(krate, LinkCollector { visited_links, ambiguous_links, .. }) =
passes::track!(tcx, collect_intra_doc_links(krate, &mut ctxt));
krate = passes::track!(tcx, propagate_doc_cfg(krate, &mut ctxt));
krate = passes::track!(tcx, propagate_stability(krate, &mut ctxt));
krate = passes::track!(tcx, lint(krate, &mut ctxt));
}

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

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

let mut collector =
LinkCollector { cx: &mut ctxt, visited_links: visited, ambiguous_links: ambiguous };
let mut collector = LinkCollector { cx: &mut ctxt, visited_links, ambiguous_links };
collector.resolve_ambiguities();

tcx.dcx().abort_if_errors();
Expand Down
3 changes: 2 additions & 1 deletion src/librustdoc/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#![feature(assert_matches)]
#![feature(box_patterns)]
#![feature(debug_closure_helpers)]
#![feature(decl_macro)]
#![feature(file_buffered)]
#![feature(if_let_guard)]
#![feature(iter_advance_by)]
Expand Down Expand Up @@ -218,7 +219,7 @@ fn init_logging(early_dcx: &EarlyDiagCtxt) {
.with_ansi(color_logs)
.with_targets(true)
.with_wraparound(10)
.with_verbose_exit(true)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FIXME: nocheckin

.with_verbose_exit(false)
.with_verbose_entry(true)
.with_indent_amount(2);
#[cfg(debug_assertions)]
Expand Down
12 changes: 4 additions & 8 deletions src/librustdoc/passes/calculate_doc_coverage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,13 @@ use tracing::debug;
use crate::clean;
use crate::core::DocContext;
use crate::html::markdown::{ErrorCodes, find_testable_code};
use crate::passes::Pass;
use crate::passes::check_doc_test_visibility::{Tests, should_have_doc_example};
use crate::visit::DocVisitor;

pub(crate) const CALCULATE_DOC_COVERAGE: Pass = Pass {
name: "calculate-doc-coverage",
run: Some(calculate_doc_coverage),
description: "counts the number of items with and without documentation",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we keep the description as doc-comments?

};

fn calculate_doc_coverage(krate: clean::Crate, ctx: &mut DocContext<'_>) -> clean::Crate {
pub(crate) fn calculate_doc_coverage(
krate: clean::Crate,
ctx: &mut DocContext<'_>,
) -> clean::Crate {
let mut calc = CoverageCalculator { items: Default::default(), ctx };
calc.visit_crate(&krate);

Expand Down
7 changes: 0 additions & 7 deletions src/librustdoc/passes/check_doc_cfg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,10 @@ use rustc_hir::def_id::LocalDefId;
use rustc_middle::ty::TyCtxt;
use rustc_span::sym;

use super::Pass;
use crate::clean::{Attributes, Crate, Item};
use crate::core::DocContext;
use crate::visit::DocVisitor;

pub(crate) const CHECK_DOC_CFG: Pass = Pass {
name: "check-doc-cfg",
run: Some(check_doc_cfg),
description: "checks `#[doc(cfg(...))]` for stability feature and unexpected cfgs",
};

pub(crate) fn check_doc_cfg(krate: Crate, cx: &mut DocContext<'_>) -> Crate {
let mut checker = DocCfgChecker { cx };
checker.visit_crate(&krate);
Expand Down
10 changes: 1 addition & 9 deletions src/librustdoc/passes/check_doc_test_visibility.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,12 @@ use rustc_middle::lint::{LevelAndSource, LintLevelSource};
use rustc_session::lint;
use tracing::debug;

use super::Pass;
use crate::clean;
use crate::clean::utils::inherits_doc_hidden;
use crate::clean::*;
use crate::clean::{self, *};
use crate::core::DocContext;
use crate::html::markdown::{ErrorCodes, Ignore, LangString, MdRelLine, find_testable_code};
use crate::visit::DocVisitor;

pub(crate) const CHECK_DOC_TEST_VISIBILITY: Pass = Pass {
name: "check_doc_test_visibility",
run: Some(check_doc_test_visibility),
description: "run various visibility-related lints on doctests",
};

struct DocTestVisibilityLinter<'a, 'tcx> {
cx: &'a mut DocContext<'tcx>,
}
Expand Down
4 changes: 0 additions & 4 deletions src/librustdoc/passes/collect_intra_doc_links.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,8 @@ use crate::clean::{self, Crate, Item, ItemId, ItemLink, PrimitiveType};
use crate::core::DocContext;
use crate::html::markdown::{MarkdownLink, MarkdownLinkRange, markdown_links};
use crate::lint::{BROKEN_INTRA_DOC_LINKS, PRIVATE_INTRA_DOC_LINKS};
use crate::passes::Pass;
use crate::visit::DocVisitor;

pub(crate) const COLLECT_INTRA_DOC_LINKS: Pass =
Pass { name: "collect-intra-doc-links", run: None, description: "resolves intra-doc links" };

pub(crate) fn collect_intra_doc_links<'a, 'tcx>(
krate: Crate,
cx: &'a mut DocContext<'tcx>,
Expand Down
7 changes: 0 additions & 7 deletions src/librustdoc/passes/collect_trait_impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,11 @@ use rustc_middle::ty;
use rustc_span::symbol::sym;
use tracing::debug;

use super::Pass;
use crate::clean::*;
use crate::core::DocContext;
use crate::formats::cache::Cache;
use crate::visit::DocVisitor;

pub(crate) const COLLECT_TRAIT_IMPLS: Pass = Pass {
name: "collect-trait-impls",
run: Some(collect_trait_impls),
description: "retrieves trait impls for items in the crate",
};

pub(crate) fn collect_trait_impls(mut krate: Crate, cx: &mut DocContext<'_>) -> Crate {
let tcx = cx.tcx;
// We need to check if there are errors before running this pass because it would crash when
Expand Down
6 changes: 1 addition & 5 deletions src/librustdoc/passes/lint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,15 @@ mod html_tags;
mod redundant_explicit_links;
mod unescaped_backticks;

use super::Pass;
use crate::clean::*;
use crate::core::DocContext;
use crate::visit::DocVisitor;

pub(crate) const RUN_LINTS: Pass =
Pass { name: "run-lints", run: Some(run_lints), description: "runs some of rustdoc's lints" };

struct Linter<'a, 'tcx> {
cx: &'a mut DocContext<'tcx>,
}

pub(crate) fn run_lints(krate: Crate, cx: &mut DocContext<'_>) -> Crate {
pub(crate) fn lint(krate: Crate, cx: &mut DocContext<'_>) -> Crate {
Linter { cx }.visit_crate(&krate);
krate
}
Expand Down
136 changes: 16 additions & 120 deletions src/librustdoc/passes/mod.rs
Original file line number Diff line number Diff line change
@@ -1,127 +1,23 @@
//! Contains information about "passes", used to modify crate information during the documentation
//! process.

use self::Condition::*;
use crate::clean;
use crate::core::DocContext;

mod stripper;
pub(crate) use stripper::*;

mod strip_aliased_non_local;
pub(crate) use self::strip_aliased_non_local::STRIP_ALIASED_NON_LOCAL;

mod strip_hidden;
pub(crate) use self::strip_hidden::STRIP_HIDDEN;

mod strip_private;
pub(crate) use self::strip_private::STRIP_PRIVATE;

mod strip_priv_imports;
pub(crate) use self::strip_priv_imports::STRIP_PRIV_IMPORTS;

mod propagate_doc_cfg;
pub(crate) use self::propagate_doc_cfg::PROPAGATE_DOC_CFG;

mod propagate_stability;
pub(crate) use self::propagate_stability::PROPAGATE_STABILITY;

pub(crate) mod calculate_doc_coverage;
pub(crate) mod check_doc_cfg;
pub(crate) mod check_doc_test_visibility;
pub(crate) mod collect_intra_doc_links;
pub(crate) use self::collect_intra_doc_links::COLLECT_INTRA_DOC_LINKS;

mod check_doc_test_visibility;
pub(crate) use self::check_doc_test_visibility::CHECK_DOC_TEST_VISIBILITY;

mod check_doc_cfg;
pub(crate) use self::check_doc_cfg::CHECK_DOC_CFG;

mod collect_trait_impls;
pub(crate) use self::collect_trait_impls::COLLECT_TRAIT_IMPLS;

mod calculate_doc_coverage;
pub(crate) use self::calculate_doc_coverage::CALCULATE_DOC_COVERAGE;

mod lint;
pub(crate) use self::lint::RUN_LINTS;

/// A single pass over the cleaned documentation.
///
/// Runs in the compiler context, so it has access to types and traits and the like.
#[derive(Copy, Clone)]
pub(crate) struct Pass {
pub(crate) name: &'static str,
pub(crate) run: Option<fn(clean::Crate, &mut DocContext<'_>) -> clean::Crate>,
pub(crate) description: &'static str,
}

/// In a list of passes, a pass that may or may not need to be run depending on options.
#[derive(Copy, Clone)]
pub(crate) struct ConditionalPass {
pub(crate) pass: Pass,
pub(crate) condition: Condition,
}

/// How to decide whether to run a conditional pass.
#[derive(Copy, Clone)]
pub(crate) enum Condition {
Always,
/// When `--document-private-items` is passed.
WhenDocumentPrivate,
/// When `--document-private-items` is not passed.
WhenNotDocumentPrivate,
/// When `--document-hidden-items` is not passed.
WhenNotDocumentHidden,
}

/// The full list of passes.
pub(crate) const PASSES: &[Pass] = &[
CHECK_DOC_CFG,
CHECK_DOC_TEST_VISIBILITY,
STRIP_ALIASED_NON_LOCAL,
STRIP_HIDDEN,
STRIP_PRIVATE,
STRIP_PRIV_IMPORTS,
PROPAGATE_DOC_CFG,
PROPAGATE_STABILITY,
COLLECT_INTRA_DOC_LINKS,
COLLECT_TRAIT_IMPLS,
CALCULATE_DOC_COVERAGE,
RUN_LINTS,
];

/// The list of passes run by default.
pub(crate) const DEFAULT_PASSES: &[ConditionalPass] = &[
ConditionalPass::always(COLLECT_TRAIT_IMPLS),
ConditionalPass::always(CHECK_DOC_TEST_VISIBILITY),
ConditionalPass::always(CHECK_DOC_CFG),
ConditionalPass::always(STRIP_ALIASED_NON_LOCAL),
ConditionalPass::new(STRIP_HIDDEN, WhenNotDocumentHidden),
ConditionalPass::new(STRIP_PRIVATE, WhenNotDocumentPrivate),
ConditionalPass::new(STRIP_PRIV_IMPORTS, WhenDocumentPrivate),
ConditionalPass::always(COLLECT_INTRA_DOC_LINKS),
ConditionalPass::always(PROPAGATE_DOC_CFG),
ConditionalPass::always(PROPAGATE_STABILITY),
ConditionalPass::always(RUN_LINTS),
];

/// The list of default passes run when `--doc-coverage` is passed to rustdoc.
pub(crate) const COVERAGE_PASSES: &[ConditionalPass] = &[
ConditionalPass::new(STRIP_HIDDEN, WhenNotDocumentHidden),
ConditionalPass::new(STRIP_PRIVATE, WhenNotDocumentPrivate),
ConditionalPass::always(CALCULATE_DOC_COVERAGE),
];

impl ConditionalPass {
pub(crate) const fn always(pass: Pass) -> Self {
Self::new(pass, Always)
}

pub(crate) const fn new(pass: Pass, condition: Condition) -> Self {
ConditionalPass { pass, condition }
}
}

/// Returns the given default set of passes.
pub(crate) fn defaults(show_coverage: bool) -> &'static [ConditionalPass] {
if show_coverage { COVERAGE_PASSES } else { DEFAULT_PASSES }
}
pub(crate) mod collect_trait_impls;
pub(crate) mod lint;
pub(crate) mod propagate_doc_cfg;
pub(crate) mod propagate_stability;
pub(crate) mod strip_aliased_non_local;
pub(crate) mod strip_hidden;
pub(crate) mod strip_priv_imports;
pub(crate) mod strip_private;

pub(crate) macro track($tcx:expr, $name:ident($( $args:tt )*)) {{
tracing::debug!("running pass `{}`", stringify!($name));
$tcx.sess.time(stringify!($name), || self::$name::$name($( $args )*))
}}
Loading
Loading