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
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 @@ -421,38 +420,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
53 changes: 26 additions & 27 deletions src/librustdoc/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,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 @@ -423,39 +422,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.document_private(),
WhenNotDocumentPrivate => !ctxt.document_private(),
WhenNotDocumentHidden => !ctxt.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");
passes::initialize!(tcx, ctxt);

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

if !show_coverage {
krate = track!(collect_trait_impls(krate));
krate = track!(check_doc_test_visibility(krate));
krate = track!(check_doc_cfg(krate));
krate = track!(strip_aliased_non_local(krate));
krate = track!(propagate_doc_cfg(krate));
}

krate = track!(strip_hidden(krate));
krate = track!(strip_private(krate));

if show_coverage {
krate = track!(calculate_doc_coverage(krate));
} else {
krate = track!(strip_priv_imports(krate));
(krate, LinkCollector { visited_links, ambiguous_links, .. }) =
track!(collect_intra_doc_links(krate));
krate = track!(propagate_stability(krate));
krate = track!(lint(krate));
}

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

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

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
17 changes: 8 additions & 9 deletions src/librustdoc/passes/calculate_doc_coverage.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
//! Calculates information used for the --show-coverage flag.
//! Calculates information used for the `--show-coverage` flag.
//!
//! More specifically, it counts the number of items with documentation, ones with
//! "examples" (i.e., non-ignored Rust code blocks) and various totals.

use std::collections::BTreeMap;
use std::ops;
Expand All @@ -14,17 +17,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",
};

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
9 changes: 2 additions & 7 deletions src/librustdoc/passes/check_doc_cfg.rs
Original file line number Diff line number Diff line change
@@ -1,19 +1,14 @@
//! Checks `#[doc(cfg(…))]` for unexpected cfgs wrt. `--check-cfg`.

use rustc_hir::HirId;
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
8 changes: 2 additions & 6 deletions src/librustdoc/passes/collect_intra_doc_links.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//! This module implements [RFC 1946]: Intra-rustdoc-links
//! Resolves intra-doc links ([RFC 1946]).
//!
//! [RFC 1946]: https://github.com/rust-lang/rfcs/blob/master/text/1946-intra-rustdoc-links.md
//! [RFC 1946]: https://rust-lang.github.io/rfcs/1946-intra-rustdoc-links.html
use std::borrow::Cow;
use std::fmt::Display;
Expand Down 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
14 changes: 4 additions & 10 deletions src/librustdoc/passes/collect_trait_impls.rs
Original file line number Diff line number Diff line change
@@ -1,25 +1,19 @@
//! Collects trait impls for each item in the crate. For example, if a crate
//! defines a struct that implements a trait, this pass will note that the
//! struct implements that trait.
//! Collects trait impls for each item in the crate.
//!
//! For example, if a crate defines a struct that implements a trait,
//! this pass will note that the struct implements that trait.

use rustc_data_structures::fx::FxHashSet;
use rustc_hir::def_id::{DefId, DefIdMap, DefIdSet, LOCAL_CRATE};
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
9 changes: 2 additions & 7 deletions src/librustdoc/passes/lint.rs
Original file line number Diff line number Diff line change
@@ -1,25 +1,20 @@
//! Runs several rustdoc lints, consolidating them into a single pass for
//! efficiency and simplicity.
//! Runs several rustdoc lints, consolidating them into a single pass for efficiency and simplicity.

mod bare_urls;
mod check_code_block_syntax;
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
Loading
Loading