Rename {enter,exit}_lint_attrs
to check_attributes{,_post}
This commit is contained in:
parent
4a52e9cc2a
commit
2cb53473d9
8 changed files with 19 additions and 34 deletions
|
@ -73,10 +73,10 @@ impl<'a, T: EarlyLintPass> EarlyContextAndPass<'a, T> {
|
||||||
|
|
||||||
self.inlined_check_id(id);
|
self.inlined_check_id(id);
|
||||||
debug!("early context: enter_attrs({:?})", attrs);
|
debug!("early context: enter_attrs({:?})", attrs);
|
||||||
lint_callback!(self, enter_lint_attrs, attrs);
|
lint_callback!(self, check_attributes, attrs);
|
||||||
ensure_sufficient_stack(|| f(self));
|
ensure_sufficient_stack(|| f(self));
|
||||||
debug!("early context: exit_attrs({:?})", attrs);
|
debug!("early context: exit_attrs({:?})", attrs);
|
||||||
lint_callback!(self, exit_lint_attrs, attrs);
|
lint_callback!(self, check_attributes_post, attrs);
|
||||||
self.context.builder.pop(push);
|
self.context.builder.pop(push);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,7 +15,6 @@
|
||||||
//! for all lint attributes.
|
//! for all lint attributes.
|
||||||
|
|
||||||
use crate::{passes::LateLintPassObject, LateContext, LateLintPass, LintStore};
|
use crate::{passes::LateLintPassObject, LateContext, LateLintPass, LintStore};
|
||||||
use rustc_ast as ast;
|
|
||||||
use rustc_data_structures::stack::ensure_sufficient_stack;
|
use rustc_data_structures::stack::ensure_sufficient_stack;
|
||||||
use rustc_data_structures::sync::{join, Lrc};
|
use rustc_data_structures::sync::{join, Lrc};
|
||||||
use rustc_hir as hir;
|
use rustc_hir as hir;
|
||||||
|
@ -62,13 +61,13 @@ impl<'tcx, T: LateLintPass<'tcx>> LateContextAndPass<'tcx, T> {
|
||||||
let prev = self.context.last_node_with_lint_attrs;
|
let prev = self.context.last_node_with_lint_attrs;
|
||||||
self.context.last_node_with_lint_attrs = id;
|
self.context.last_node_with_lint_attrs = id;
|
||||||
debug!("late context: enter_attrs({:?})", attrs);
|
debug!("late context: enter_attrs({:?})", attrs);
|
||||||
lint_callback!(self, enter_lint_attrs, attrs);
|
lint_callback!(self, check_attributes, attrs);
|
||||||
for attr in attrs {
|
for attr in attrs {
|
||||||
lint_callback!(self, check_attribute, attr);
|
lint_callback!(self, check_attribute, attr);
|
||||||
}
|
}
|
||||||
f(self);
|
f(self);
|
||||||
debug!("late context: exit_attrs({:?})", attrs);
|
debug!("late context: exit_attrs({:?})", attrs);
|
||||||
lint_callback!(self, exit_lint_attrs, attrs);
|
lint_callback!(self, check_attributes_post, attrs);
|
||||||
self.context.last_node_with_lint_attrs = prev;
|
self.context.last_node_with_lint_attrs = prev;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -310,10 +309,6 @@ impl<'tcx, T: LateLintPass<'tcx>> hir_visit::Visitor<'tcx> for LateContextAndPas
|
||||||
lint_callback!(self, check_path, p, id);
|
lint_callback!(self, check_path, p, id);
|
||||||
hir_visit::walk_path(self, p);
|
hir_visit::walk_path(self, p);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn visit_attribute(&mut self, attr: &'tcx ast::Attribute) {
|
|
||||||
lint_callback!(self, check_attribute, attr);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Combines multiple lint passes into a single pass, at runtime. Each
|
// Combines multiple lint passes into a single pass, at runtime. Each
|
||||||
|
|
|
@ -41,13 +41,8 @@ macro_rules! late_lint_methods {
|
||||||
fn check_variant(a: &'tcx rustc_hir::Variant<'tcx>);
|
fn check_variant(a: &'tcx rustc_hir::Variant<'tcx>);
|
||||||
fn check_path(a: &rustc_hir::Path<'tcx>, b: rustc_hir::HirId);
|
fn check_path(a: &rustc_hir::Path<'tcx>, b: rustc_hir::HirId);
|
||||||
fn check_attribute(a: &'tcx rustc_ast::Attribute);
|
fn check_attribute(a: &'tcx rustc_ast::Attribute);
|
||||||
|
fn check_attributes(a: &'tcx [rustc_ast::Attribute]);
|
||||||
/// Called when entering a syntax node that can have lint attributes such
|
fn check_attributes_post(a: &'tcx [rustc_ast::Attribute]);
|
||||||
/// as `#[allow(...)]`. Called with *all* the attributes of that node.
|
|
||||||
fn enter_lint_attrs(a: &'tcx [rustc_ast::Attribute]);
|
|
||||||
|
|
||||||
/// Counterpart to `enter_lint_attrs`.
|
|
||||||
fn exit_lint_attrs(a: &'tcx [rustc_ast::Attribute]);
|
|
||||||
]);
|
]);
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
@ -162,16 +157,11 @@ macro_rules! early_lint_methods {
|
||||||
fn check_impl_item(a: &rustc_ast::AssocItem);
|
fn check_impl_item(a: &rustc_ast::AssocItem);
|
||||||
fn check_variant(a: &rustc_ast::Variant);
|
fn check_variant(a: &rustc_ast::Variant);
|
||||||
fn check_attribute(a: &rustc_ast::Attribute);
|
fn check_attribute(a: &rustc_ast::Attribute);
|
||||||
|
fn check_attributes(a: &[rustc_ast::Attribute]);
|
||||||
|
fn check_attributes_post(a: &[rustc_ast::Attribute]);
|
||||||
fn check_mac_def(a: &rustc_ast::MacroDef);
|
fn check_mac_def(a: &rustc_ast::MacroDef);
|
||||||
fn check_mac(a: &rustc_ast::MacCall);
|
fn check_mac(a: &rustc_ast::MacCall);
|
||||||
|
|
||||||
/// Called when entering a syntax node that can have lint attributes such
|
|
||||||
/// as `#[allow(...)]`. Called with *all* the attributes of that node.
|
|
||||||
fn enter_lint_attrs(a: &[rustc_ast::Attribute]);
|
|
||||||
|
|
||||||
/// Counterpart to `enter_lint_attrs`.
|
|
||||||
fn exit_lint_attrs(a: &[rustc_ast::Attribute]);
|
|
||||||
|
|
||||||
fn enter_where_predicate(a: &rustc_ast::WherePredicate);
|
fn enter_where_predicate(a: &rustc_ast::WherePredicate);
|
||||||
fn exit_where_predicate(a: &rustc_ast::WherePredicate);
|
fn exit_where_predicate(a: &rustc_ast::WherePredicate);
|
||||||
]);
|
]);
|
||||||
|
|
|
@ -143,13 +143,13 @@ impl Msrv {
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn enter_lint_attrs(&mut self, sess: &Session, attrs: &[Attribute]) {
|
pub fn check_attributes(&mut self, sess: &Session, attrs: &[Attribute]) {
|
||||||
if let Some(version) = Self::parse_attr(sess, attrs) {
|
if let Some(version) = Self::parse_attr(sess, attrs) {
|
||||||
self.stack.push(version);
|
self.stack.push(version);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn exit_lint_attrs(&mut self, sess: &Session, attrs: &[Attribute]) {
|
pub fn check_attributes_post(&mut self, sess: &Session, attrs: &[Attribute]) {
|
||||||
if Self::parse_attr(sess, attrs).is_some() {
|
if Self::parse_attr(sess, attrs).is_some() {
|
||||||
self.stack.pop();
|
self.stack.pop();
|
||||||
}
|
}
|
||||||
|
|
|
@ -158,10 +158,10 @@ impl<'tcx> LateLintPass<'tcx> for CognitiveComplexity {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn enter_lint_attrs(&mut self, cx: &LateContext<'tcx>, attrs: &'tcx [Attribute]) {
|
fn check_attributes(&mut self, cx: &LateContext<'tcx>, attrs: &'tcx [Attribute]) {
|
||||||
self.limit.push_attrs(cx.sess(), attrs, "cognitive_complexity");
|
self.limit.push_attrs(cx.sess(), attrs, "cognitive_complexity");
|
||||||
}
|
}
|
||||||
fn exit_lint_attrs(&mut self, cx: &LateContext<'tcx>, attrs: &'tcx [Attribute]) {
|
fn check_attributes_post(&mut self, cx: &LateContext<'tcx>, attrs: &'tcx [Attribute]) {
|
||||||
self.limit.pop_attrs(cx.sess(), attrs, "cognitive_complexity");
|
self.limit.pop_attrs(cx.sess(), attrs, "cognitive_complexity");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -162,12 +162,12 @@ impl MissingDoc {
|
||||||
impl_lint_pass!(MissingDoc => [MISSING_DOCS_IN_PRIVATE_ITEMS]);
|
impl_lint_pass!(MissingDoc => [MISSING_DOCS_IN_PRIVATE_ITEMS]);
|
||||||
|
|
||||||
impl<'tcx> LateLintPass<'tcx> for MissingDoc {
|
impl<'tcx> LateLintPass<'tcx> for MissingDoc {
|
||||||
fn enter_lint_attrs(&mut self, _: &LateContext<'tcx>, attrs: &'tcx [ast::Attribute]) {
|
fn check_attributes(&mut self, _: &LateContext<'tcx>, attrs: &'tcx [ast::Attribute]) {
|
||||||
let doc_hidden = self.doc_hidden() || is_doc_hidden(attrs);
|
let doc_hidden = self.doc_hidden() || is_doc_hidden(attrs);
|
||||||
self.doc_hidden_stack.push(doc_hidden);
|
self.doc_hidden_stack.push(doc_hidden);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn exit_lint_attrs(&mut self, _: &LateContext<'tcx>, _: &'tcx [ast::Attribute]) {
|
fn check_attributes_post(&mut self, _: &LateContext<'tcx>, _: &'tcx [ast::Attribute]) {
|
||||||
self.doc_hidden_stack.pop().expect("empty doc_hidden_stack");
|
self.doc_hidden_stack.pop().expect("empty doc_hidden_stack");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -42,7 +42,7 @@ impl LateLintPass<'_> for MsrvAttrImpl {
|
||||||
.filter(|t| matches!(t.unpack(), GenericArgKind::Type(_)))
|
.filter(|t| matches!(t.unpack(), GenericArgKind::Type(_)))
|
||||||
.any(|t| match_type(cx, t.expect_ty(), &paths::MSRV))
|
.any(|t| match_type(cx, t.expect_ty(), &paths::MSRV))
|
||||||
})
|
})
|
||||||
&& !items.iter().any(|item| item.ident.name == sym!(enter_lint_attrs))
|
&& !items.iter().any(|item| item.ident.name == sym!(check_attributes))
|
||||||
{
|
{
|
||||||
let context = if is_late_pass { "LateContext" } else { "EarlyContext" };
|
let context = if is_late_pass { "LateContext" } else { "EarlyContext" };
|
||||||
let lint_pass = if is_late_pass { "LateLintPass" } else { "EarlyLintPass" };
|
let lint_pass = if is_late_pass { "LateLintPass" } else { "EarlyLintPass" };
|
||||||
|
|
|
@ -131,14 +131,14 @@ use rustc_middle::hir::nested_filter;
|
||||||
#[macro_export]
|
#[macro_export]
|
||||||
macro_rules! extract_msrv_attr {
|
macro_rules! extract_msrv_attr {
|
||||||
($context:ident) => {
|
($context:ident) => {
|
||||||
fn enter_lint_attrs(&mut self, cx: &rustc_lint::$context<'_>, attrs: &[rustc_ast::ast::Attribute]) {
|
fn check_attributes(&mut self, cx: &rustc_lint::$context<'_>, attrs: &[rustc_ast::ast::Attribute]) {
|
||||||
let sess = rustc_lint::LintContext::sess(cx);
|
let sess = rustc_lint::LintContext::sess(cx);
|
||||||
self.msrv.enter_lint_attrs(sess, attrs);
|
self.msrv.check_attributes(sess, attrs);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn exit_lint_attrs(&mut self, cx: &rustc_lint::$context<'_>, attrs: &[rustc_ast::ast::Attribute]) {
|
fn check_attributes_post(&mut self, cx: &rustc_lint::$context<'_>, attrs: &[rustc_ast::ast::Attribute]) {
|
||||||
let sess = rustc_lint::LintContext::sess(cx);
|
let sess = rustc_lint::LintContext::sess(cx);
|
||||||
self.msrv.exit_lint_attrs(sess, attrs);
|
self.msrv.check_attributes_post(sess, attrs);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue