-
Notifications
You must be signed in to change notification settings - Fork 13.9k
rustdoc: Nuke --passes=list and defossilize the passes infrastructure
#146529
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
fmease
wants to merge
2
commits into
rust-lang:master
Choose a base branch
from
fmease:rustdoc-nuke-passes-list
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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", | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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); | ||
|
|
||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 )*)) | ||
| }} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FIXME: nocheckin