Skip to content

Consolidate rustdoc's lint passes into a single pass #104757

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

Merged
merged 1 commit into from
Dec 4, 2022
Merged
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
110 changes: 0 additions & 110 deletions src/librustdoc/passes/bare_urls.rs

This file was deleted.

209 changes: 0 additions & 209 deletions src/librustdoc/passes/check_code_block_syntax.rs

This file was deleted.

33 changes: 33 additions & 0 deletions src/librustdoc/passes/lint.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
//! 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;

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: 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 {
Linter { cx }.visit_crate(&krate);
krate
}

impl<'a, 'tcx> DocVisitor for Linter<'a, 'tcx> {
fn visit_item(&mut self, item: &Item) {
bare_urls::visit_item(self.cx, item);
check_code_block_syntax::visit_item(self.cx, item);
html_tags::visit_item(self.cx, item);
Copy link
Member

Choose a reason for hiding this comment

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

All of these start by computing the collapsed_doc_value, it might save time to compute that once here and pass in an Option<&str> for it.

Copy link
Member

Choose a reason for hiding this comment

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

Yeah I think that's one way to unify passes: unify everything that needs the doc value


self.visit_item_recur(item)
}
}
Loading