rustc_lint: Remove some redundant fields from EarlyContext
Use consistent function parameter order for early context construction and early linting Rename some functions to make it clear that they do not necessarily work on the whole crate
This commit is contained in:
parent
d13e8dd41d
commit
452aa81770
8 changed files with 81 additions and 105 deletions
|
@ -57,7 +57,7 @@ impl<'a, T: EarlyLintPass> EarlyContextAndPass<'a, T> {
|
|||
F: FnOnce(&mut Self),
|
||||
{
|
||||
let is_crate_node = id == ast::CRATE_NODE_ID;
|
||||
let push = self.context.builder.push(attrs, &self.context.lint_store, is_crate_node);
|
||||
let push = self.context.builder.push(attrs, is_crate_node);
|
||||
self.check_id(id);
|
||||
self.enter_attrs(attrs);
|
||||
f(self);
|
||||
|
@ -325,48 +325,36 @@ macro_rules! early_lint_pass_impl {
|
|||
|
||||
crate::early_lint_methods!(early_lint_pass_impl, []);
|
||||
|
||||
fn early_lint_crate<T: EarlyLintPass>(
|
||||
fn early_lint_node(
|
||||
sess: &Session,
|
||||
lint_store: &LintStore,
|
||||
krate: &ast::Crate,
|
||||
crate_attrs: &[ast::Attribute],
|
||||
pass: T,
|
||||
buffered: LintBuffer,
|
||||
warn_about_weird_lints: bool,
|
||||
lint_store: &LintStore,
|
||||
crate_attrs: &[ast::Attribute],
|
||||
buffered: LintBuffer,
|
||||
pass: impl EarlyLintPass,
|
||||
check_node: &ast::Crate,
|
||||
) -> LintBuffer {
|
||||
let mut cx = EarlyContextAndPass {
|
||||
context: EarlyContext::new(
|
||||
sess,
|
||||
lint_store,
|
||||
krate,
|
||||
crate_attrs,
|
||||
buffered,
|
||||
warn_about_weird_lints,
|
||||
),
|
||||
context: EarlyContext::new(sess, warn_about_weird_lints, lint_store, crate_attrs, buffered),
|
||||
pass,
|
||||
};
|
||||
|
||||
// Visit the whole crate.
|
||||
cx.with_lint_attrs(ast::CRATE_NODE_ID, &krate.attrs, |cx| {
|
||||
// since the root module isn't visited as an item (because it isn't an
|
||||
// item), warn for it here.
|
||||
run_early_pass!(cx, check_crate, krate);
|
||||
|
||||
ast_visit::walk_crate(cx, krate);
|
||||
|
||||
run_early_pass!(cx, check_crate_post, krate);
|
||||
cx.with_lint_attrs(ast::CRATE_NODE_ID, &check_node.attrs, |cx| {
|
||||
run_early_pass!(cx, check_crate, check_node);
|
||||
ast_visit::walk_crate(cx, check_node);
|
||||
run_early_pass!(cx, check_crate_post, check_node);
|
||||
});
|
||||
cx.context.buffered
|
||||
}
|
||||
|
||||
pub fn check_ast_crate<T: EarlyLintPass>(
|
||||
pub fn check_ast_node(
|
||||
sess: &Session,
|
||||
lint_store: &LintStore,
|
||||
krate: &ast::Crate,
|
||||
crate_attrs: &[ast::Attribute],
|
||||
pre_expansion: bool,
|
||||
lint_store: &LintStore,
|
||||
crate_attrs: &[ast::Attribute],
|
||||
lint_buffer: Option<LintBuffer>,
|
||||
builtin_lints: T,
|
||||
builtin_lints: impl EarlyLintPass,
|
||||
check_node: &ast::Crate,
|
||||
) {
|
||||
let passes =
|
||||
if pre_expansion { &lint_store.pre_expansion_passes } else { &lint_store.early_passes };
|
||||
|
@ -374,39 +362,39 @@ pub fn check_ast_crate<T: EarlyLintPass>(
|
|||
let mut buffered = lint_buffer.unwrap_or_default();
|
||||
|
||||
if !sess.opts.debugging_opts.no_interleave_lints {
|
||||
buffered = early_lint_crate(
|
||||
buffered = early_lint_node(
|
||||
sess,
|
||||
lint_store,
|
||||
krate,
|
||||
crate_attrs,
|
||||
builtin_lints,
|
||||
buffered,
|
||||
pre_expansion,
|
||||
lint_store,
|
||||
crate_attrs,
|
||||
buffered,
|
||||
builtin_lints,
|
||||
check_node,
|
||||
);
|
||||
|
||||
if !passes.is_empty() {
|
||||
buffered = early_lint_crate(
|
||||
buffered = early_lint_node(
|
||||
sess,
|
||||
lint_store,
|
||||
krate,
|
||||
crate_attrs,
|
||||
EarlyLintPassObjects { lints: &mut passes[..] },
|
||||
buffered,
|
||||
false,
|
||||
lint_store,
|
||||
crate_attrs,
|
||||
buffered,
|
||||
EarlyLintPassObjects { lints: &mut passes[..] },
|
||||
check_node,
|
||||
);
|
||||
}
|
||||
} else {
|
||||
for (i, pass) in passes.iter_mut().enumerate() {
|
||||
buffered =
|
||||
sess.prof.extra_verbose_generic_activity("run_lint", pass.name()).run(|| {
|
||||
early_lint_crate(
|
||||
early_lint_node(
|
||||
sess,
|
||||
lint_store,
|
||||
krate,
|
||||
crate_attrs,
|
||||
EarlyLintPassObjects { lints: slice::from_mut(pass) },
|
||||
buffered,
|
||||
pre_expansion && i == 0,
|
||||
lint_store,
|
||||
crate_attrs,
|
||||
buffered,
|
||||
EarlyLintPassObjects { lints: slice::from_mut(pass) },
|
||||
check_node,
|
||||
)
|
||||
});
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue