1use rustc_ast::visit::{self as ast_visit, Visitor, walk_list};
8use rustc_ast::{self as ast, AttrVec, HasAttrs};
9use rustc_data_structures::stack::ensure_sufficient_stack;
10use rustc_errors::{BufferedEarlyLint, LintBuffer};
11use rustc_feature::Features;
12use rustc_middle::ty::RegisteredTools;
13use rustc_session::Session;
14use rustc_session::lint::LintPass;
15use rustc_span::{Ident, Span};
16use tracing::debug;
17
18use crate::DiagAndSess;
19use crate::context::{EarlyContext, LintContext, LintStore};
20use crate::passes::{EarlyLintPass, EarlyLintPassObject};
21
22pub(super) mod diagnostics;
23
24macro_rules! lint_callback { ($cx:expr, $f:ident, $($args:expr),*) => ({
25 $cx.pass.$f(&$cx.context, $($args),*);
26}) }
27
28pub struct EarlyContextAndPass<'ecx, T: EarlyLintPass> {
31 context: EarlyContext<'ecx>,
32 pass: T,
33}
34
35impl<'ecx, T: EarlyLintPass> EarlyContextAndPass<'ecx, T> {
36 fn check_id(&mut self, id: ast::NodeId) {
37 for early_lint in self.context.buffered.take(id) {
38 let BufferedEarlyLint { span, node_id: _, lint_id, diagnostic } = early_lint;
39 self.context.opt_span_lint(
40 lint_id.lint,
41 span,
42 DiagAndSess { callback: diagnostic.0, sess: self.context.sess() },
43 );
44 }
45 }
46
47 fn with_lint_attrs<F>(&mut self, id: ast::NodeId, attrs: &'_ [ast::Attribute], f: F)
51 where
52 F: FnOnce(&mut Self),
53 {
54 let is_crate_node = id == ast::CRATE_NODE_ID;
55 {
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event compiler/rustc_lint/src/early.rs:55",
"rustc_lint::early", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_lint/src/early.rs"),
::tracing_core::__macro_support::Option::Some(55u32),
::tracing_core::__macro_support::Option::Some("rustc_lint::early"),
::tracing_core::field::FieldSet::new(&["id"],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::EVENT)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let enabled =
::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{
let interest = __CALLSITE.interest();
!interest.is_never() &&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest)
};
if enabled {
(|value_set: ::tracing::field::ValueSet|
{
let meta = __CALLSITE.metadata();
::tracing::Event::dispatch(meta, &value_set);
;
})({
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
let mut iter = __CALLSITE.metadata().fields().iter();
__CALLSITE.metadata().fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&debug(&id) as
&dyn Value))])
});
} else { ; }
};debug!(?id);
56 let push = self.context.builder.push(attrs, is_crate_node, None);
57
58 {
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event compiler/rustc_lint/src/early.rs:58",
"rustc_lint::early", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_lint/src/early.rs"),
::tracing_core::__macro_support::Option::Some(58u32),
::tracing_core::__macro_support::Option::Some("rustc_lint::early"),
::tracing_core::field::FieldSet::new(&["message"],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::EVENT)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let enabled =
::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{
let interest = __CALLSITE.interest();
!interest.is_never() &&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest)
};
if enabled {
(|value_set: ::tracing::field::ValueSet|
{
let meta = __CALLSITE.metadata();
::tracing::Event::dispatch(meta, &value_set);
;
})({
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
let mut iter = __CALLSITE.metadata().fields().iter();
__CALLSITE.metadata().fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&format_args!("early context: enter_attrs({0:?})",
attrs) as &dyn Value))])
});
} else { ; }
};debug!("early context: enter_attrs({:?})", attrs);
59 { self.pass.check_attributes(&self.context, attrs); };lint_callback!(self, check_attributes, attrs);
60 ensure_sufficient_stack(|| f(self));
61 {
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event compiler/rustc_lint/src/early.rs:61",
"rustc_lint::early", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_lint/src/early.rs"),
::tracing_core::__macro_support::Option::Some(61u32),
::tracing_core::__macro_support::Option::Some("rustc_lint::early"),
::tracing_core::field::FieldSet::new(&["message"],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::EVENT)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let enabled =
::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{
let interest = __CALLSITE.interest();
!interest.is_never() &&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest)
};
if enabled {
(|value_set: ::tracing::field::ValueSet|
{
let meta = __CALLSITE.metadata();
::tracing::Event::dispatch(meta, &value_set);
;
})({
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
let mut iter = __CALLSITE.metadata().fields().iter();
__CALLSITE.metadata().fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&format_args!("early context: exit_attrs({0:?})",
attrs) as &dyn Value))])
});
} else { ; }
};debug!("early context: exit_attrs({:?})", attrs);
62 { self.pass.check_attributes_post(&self.context, attrs); };lint_callback!(self, check_attributes_post, attrs);
63 self.context.builder.pop(push);
64 }
65}
66
67impl<'ast, 'ecx, T: EarlyLintPass> ast_visit::Visitor<'ast> for EarlyContextAndPass<'ecx, T> {
68 fn visit_id(&mut self, id: rustc_ast::NodeId) {
69 self.check_id(id);
70 }
71
72 fn visit_param(&mut self, param: &'ast ast::Param) {
73 self.with_lint_attrs(param.id, ¶m.attrs, |cx| {
74 { cx.pass.check_param(&cx.context, param); };lint_callback!(cx, check_param, param);
75 ast_visit::walk_param(cx, param);
76 });
77 }
78
79 fn visit_item(&mut self, it: &'ast ast::Item) {
80 self.with_lint_attrs(it.id, &it.attrs, |cx| {
81 { cx.pass.check_item(&cx.context, it); };lint_callback!(cx, check_item, it);
82 ast_visit::walk_item(cx, it);
83 { cx.pass.check_item_post(&cx.context, it); };lint_callback!(cx, check_item_post, it);
84 })
85 }
86
87 fn visit_foreign_item(&mut self, it: &'ast ast::ForeignItem) {
88 self.with_lint_attrs(it.id, &it.attrs, |cx| {
89 ast_visit::walk_item(cx, it);
90 })
91 }
92
93 fn visit_pat(&mut self, p: &'ast ast::Pat) {
94 { self.pass.check_pat(&self.context, p); };lint_callback!(self, check_pat, p);
95 ast_visit::walk_pat(self, p);
96 { self.pass.check_pat_post(&self.context, p); };lint_callback!(self, check_pat_post, p);
97 }
98
99 fn visit_pat_field(&mut self, field: &'ast ast::PatField) {
100 self.with_lint_attrs(field.id, &field.attrs, |cx| {
101 ast_visit::walk_pat_field(cx, field);
102 });
103 }
104
105 fn visit_expr(&mut self, e: &'ast ast::Expr) {
106 self.with_lint_attrs(e.id, &e.attrs, |cx| {
107 { cx.pass.check_expr(&cx.context, e); };lint_callback!(cx, check_expr, e);
108 ast_visit::walk_expr(cx, e);
109 { cx.pass.check_expr_post(&cx.context, e); };lint_callback!(cx, check_expr_post, e);
110 })
111 }
112
113 fn visit_expr_field(&mut self, f: &'ast ast::ExprField) {
114 self.with_lint_attrs(f.id, &f.attrs, |cx| {
115 ast_visit::walk_expr_field(cx, f);
116 })
117 }
118
119 fn visit_stmt(&mut self, s: &'ast ast::Stmt) {
120 self.with_lint_attrs(s.id, s.attrs(), |cx| {
129 { cx.pass.check_stmt(&cx.context, s); };lint_callback!(cx, check_stmt, s);
130 ast_visit::walk_stmt(cx, s);
131 });
132 }
133
134 fn visit_fn(&mut self, fk: ast_visit::FnKind<'ast>, _: &AttrVec, span: Span, id: ast::NodeId) {
135 { self.pass.check_fn(&self.context, fk, span, id); };lint_callback!(self, check_fn, fk, span, id);
136 ast_visit::walk_fn(self, fk);
137 }
138
139 fn visit_field_def(&mut self, s: &'ast ast::FieldDef) {
140 self.with_lint_attrs(s.id, &s.attrs, |cx| {
141 ast_visit::walk_field_def(cx, s);
142 })
143 }
144
145 fn visit_variant(&mut self, v: &'ast ast::Variant) {
146 self.with_lint_attrs(v.id, &v.attrs, |cx| {
147 { cx.pass.check_variant(&cx.context, v); };lint_callback!(cx, check_variant, v);
148 ast_visit::walk_variant(cx, v);
149 })
150 }
151
152 fn visit_ty(&mut self, t: &'ast ast::Ty) {
153 { self.pass.check_ty(&self.context, t); };lint_callback!(self, check_ty, t);
154 ast_visit::walk_ty(self, t);
155 }
156
157 fn visit_ident(&mut self, ident: &Ident) {
158 { self.pass.check_ident(&self.context, ident); };lint_callback!(self, check_ident, ident);
159 }
160
161 fn visit_local(&mut self, l: &'ast ast::Local) {
162 self.with_lint_attrs(l.id, &l.attrs, |cx| {
163 { cx.pass.check_local(&cx.context, l); };lint_callback!(cx, check_local, l);
164 ast_visit::walk_local(cx, l);
165 })
166 }
167
168 fn visit_block(&mut self, b: &'ast ast::Block) {
169 { self.pass.check_block(&self.context, b); };lint_callback!(self, check_block, b);
170 ast_visit::walk_block(self, b);
171 }
172
173 fn visit_arm(&mut self, a: &'ast ast::Arm) {
174 self.with_lint_attrs(a.id, &a.attrs, |cx| {
175 { cx.pass.check_arm(&cx.context, a); };lint_callback!(cx, check_arm, a);
176 ast_visit::walk_arm(cx, a);
177 })
178 }
179
180 fn visit_generic_arg(&mut self, arg: &'ast ast::GenericArg) {
181 { self.pass.check_generic_arg(&self.context, arg); };lint_callback!(self, check_generic_arg, arg);
182 ast_visit::walk_generic_arg(self, arg);
183 }
184
185 fn visit_generic_param(&mut self, param: &'ast ast::GenericParam) {
186 self.with_lint_attrs(param.id, ¶m.attrs, |cx| {
187 { cx.pass.check_generic_param(&cx.context, param); };lint_callback!(cx, check_generic_param, param);
188 ast_visit::walk_generic_param(cx, param);
189 });
190 }
191
192 fn visit_generics(&mut self, g: &'ast ast::Generics) {
193 { self.pass.check_generics(&self.context, g); };lint_callback!(self, check_generics, g);
194 ast_visit::walk_generics(self, g);
195 }
196
197 fn visit_where_predicate(&mut self, p: &'ast ast::WherePredicate) {
198 { self.pass.enter_where_predicate(&self.context, p); };lint_callback!(self, enter_where_predicate, p);
199 ast_visit::walk_where_predicate(self, p);
200 { self.pass.exit_where_predicate(&self.context, p); };lint_callback!(self, exit_where_predicate, p);
201 }
202
203 fn visit_poly_trait_ref(&mut self, t: &'ast ast::PolyTraitRef) {
204 { self.pass.check_poly_trait_ref(&self.context, t); };lint_callback!(self, check_poly_trait_ref, t);
205 ast_visit::walk_poly_trait_ref(self, t);
206 }
207
208 fn visit_assoc_item(&mut self, item: &'ast ast::AssocItem, ctxt: ast_visit::AssocCtxt) {
209 self.with_lint_attrs(item.id, &item.attrs, |cx| {
210 match ctxt {
211 ast_visit::AssocCtxt::Trait => {
212 { cx.pass.check_trait_item(&cx.context, item); };lint_callback!(cx, check_trait_item, item);
213 }
214 ast_visit::AssocCtxt::Impl { .. } => {
215 { cx.pass.check_impl_item(&cx.context, item); };lint_callback!(cx, check_impl_item, item);
216 }
217 }
218 ast_visit::walk_assoc_item(cx, item, ctxt);
219 match ctxt {
220 ast_visit::AssocCtxt::Trait => {
221 { cx.pass.check_trait_item_post(&cx.context, item); };lint_callback!(cx, check_trait_item_post, item);
222 }
223 ast_visit::AssocCtxt::Impl { .. } => {
224 { cx.pass.check_impl_item_post(&cx.context, item); };lint_callback!(cx, check_impl_item_post, item);
225 }
226 }
227 });
228 }
229
230 fn visit_attribute(&mut self, attr: &'ast ast::Attribute) {
231 { self.pass.check_attribute(&self.context, attr); };lint_callback!(self, check_attribute, attr);
232 ast_visit::walk_attribute(self, attr);
233 }
234
235 fn visit_macro_def(&mut self, mac: &'ast ast::MacroDef) {
236 { self.pass.check_mac_def(&self.context, mac); };lint_callback!(self, check_mac_def, mac);
237 }
238
239 fn visit_mac_call(&mut self, mac: &'ast ast::MacCall) {
240 { self.pass.check_mac(&self.context, mac); };lint_callback!(self, check_mac, mac);
241 ast_visit::walk_mac(self, mac);
242 }
243}
244
245struct RuntimeCombinedEarlyLintPass<'a> {
250 passes: &'a mut [EarlyLintPassObject],
251}
252
253#[allow(rustc::lint_pass_impl_without_macro)]
254impl LintPass for RuntimeCombinedEarlyLintPass<'_> {
255 fn name(&self) -> &'static str {
256 ::core::panicking::panic("explicit panic")panic!()
257 }
258 fn get_lints(&self) -> crate::LintVec {
259 ::core::panicking::panic("explicit panic")panic!()
260 }
261}
262
263macro_rules! impl_early_lint_pass {
264 ([], [$($(#[$attr:meta])* fn $f:ident($($param:ident: $arg:ty),*);)*]) => (
265 impl EarlyLintPass for RuntimeCombinedEarlyLintPass<'_> {
266 $(fn $f(&mut self, context: &EarlyContext<'_>, $($param: $arg),*) {
267 for pass in self.passes.iter_mut() {
268 pass.$f(context, $($param),*);
269 }
270 })*
271 }
272 )
273}
274
275impl EarlyLintPass for RuntimeCombinedEarlyLintPass<'_> {
fn check_param(&mut self, context: &EarlyContext<'_>,
a: &rustc_ast::Param) {
for pass in self.passes.iter_mut() { pass.check_param(context, a); }
}
fn check_ident(&mut self, context: &EarlyContext<'_>,
a: &rustc_span::Ident) {
for pass in self.passes.iter_mut() { pass.check_ident(context, a); }
}
fn check_crate(&mut self, context: &EarlyContext<'_>,
a: &rustc_ast::Crate) {
for pass in self.passes.iter_mut() { pass.check_crate(context, a); }
}
fn check_crate_post(&mut self, context: &EarlyContext<'_>,
a: &rustc_ast::Crate) {
for pass in self.passes.iter_mut() {
pass.check_crate_post(context, a);
}
}
fn check_item(&mut self, context: &EarlyContext<'_>,
a: &rustc_ast::Item) {
for pass in self.passes.iter_mut() { pass.check_item(context, a); }
}
fn check_item_post(&mut self, context: &EarlyContext<'_>,
a: &rustc_ast::Item) {
for pass in self.passes.iter_mut() {
pass.check_item_post(context, a);
}
}
fn check_local(&mut self, context: &EarlyContext<'_>,
a: &rustc_ast::Local) {
for pass in self.passes.iter_mut() { pass.check_local(context, a); }
}
fn check_block(&mut self, context: &EarlyContext<'_>,
a: &rustc_ast::Block) {
for pass in self.passes.iter_mut() { pass.check_block(context, a); }
}
fn check_stmt(&mut self, context: &EarlyContext<'_>,
a: &rustc_ast::Stmt) {
for pass in self.passes.iter_mut() { pass.check_stmt(context, a); }
}
fn check_arm(&mut self, context: &EarlyContext<'_>, a: &rustc_ast::Arm) {
for pass in self.passes.iter_mut() { pass.check_arm(context, a); }
}
fn check_pat(&mut self, context: &EarlyContext<'_>, a: &rustc_ast::Pat) {
for pass in self.passes.iter_mut() { pass.check_pat(context, a); }
}
fn check_pat_post(&mut self, context: &EarlyContext<'_>,
a: &rustc_ast::Pat) {
for pass in self.passes.iter_mut() {
pass.check_pat_post(context, a);
}
}
fn check_expr(&mut self, context: &EarlyContext<'_>,
a: &rustc_ast::Expr) {
for pass in self.passes.iter_mut() { pass.check_expr(context, a); }
}
fn check_expr_post(&mut self, context: &EarlyContext<'_>,
a: &rustc_ast::Expr) {
for pass in self.passes.iter_mut() {
pass.check_expr_post(context, a);
}
}
fn check_ty(&mut self, context: &EarlyContext<'_>, a: &rustc_ast::Ty) {
for pass in self.passes.iter_mut() { pass.check_ty(context, a); }
}
fn check_generic_arg(&mut self, context: &EarlyContext<'_>,
a: &rustc_ast::GenericArg) {
for pass in self.passes.iter_mut() {
pass.check_generic_arg(context, a);
}
}
fn check_generic_param(&mut self, context: &EarlyContext<'_>,
a: &rustc_ast::GenericParam) {
for pass in self.passes.iter_mut() {
pass.check_generic_param(context, a);
}
}
fn check_generics(&mut self, context: &EarlyContext<'_>,
a: &rustc_ast::Generics) {
for pass in self.passes.iter_mut() {
pass.check_generics(context, a);
}
}
fn check_poly_trait_ref(&mut self, context: &EarlyContext<'_>,
a: &rustc_ast::PolyTraitRef) {
for pass in self.passes.iter_mut() {
pass.check_poly_trait_ref(context, a);
}
}
fn check_fn(&mut self, context: &EarlyContext<'_>,
a: rustc_ast::visit::FnKind<'_>, c: rustc_span::Span,
d_: rustc_ast::NodeId) {
for pass in self.passes.iter_mut() {
pass.check_fn(context, a, c, d_);
}
}
fn check_trait_item(&mut self, context: &EarlyContext<'_>,
a: &rustc_ast::AssocItem) {
for pass in self.passes.iter_mut() {
pass.check_trait_item(context, a);
}
}
fn check_trait_item_post(&mut self, context: &EarlyContext<'_>,
a: &rustc_ast::AssocItem) {
for pass in self.passes.iter_mut() {
pass.check_trait_item_post(context, a);
}
}
fn check_impl_item(&mut self, context: &EarlyContext<'_>,
a: &rustc_ast::AssocItem) {
for pass in self.passes.iter_mut() {
pass.check_impl_item(context, a);
}
}
fn check_impl_item_post(&mut self, context: &EarlyContext<'_>,
a: &rustc_ast::AssocItem) {
for pass in self.passes.iter_mut() {
pass.check_impl_item_post(context, a);
}
}
fn check_variant(&mut self, context: &EarlyContext<'_>,
a: &rustc_ast::Variant) {
for pass in self.passes.iter_mut() { pass.check_variant(context, a); }
}
fn check_attribute(&mut self, context: &EarlyContext<'_>,
a: &rustc_ast::Attribute) {
for pass in self.passes.iter_mut() {
pass.check_attribute(context, a);
}
}
fn check_attributes(&mut self, context: &EarlyContext<'_>,
a: &[rustc_ast::Attribute]) {
for pass in self.passes.iter_mut() {
pass.check_attributes(context, a);
}
}
fn check_attributes_post(&mut self, context: &EarlyContext<'_>,
a: &[rustc_ast::Attribute]) {
for pass in self.passes.iter_mut() {
pass.check_attributes_post(context, a);
}
}
fn check_mac_def(&mut self, context: &EarlyContext<'_>,
a: &rustc_ast::MacroDef) {
for pass in self.passes.iter_mut() { pass.check_mac_def(context, a); }
}
fn check_mac(&mut self, context: &EarlyContext<'_>,
a: &rustc_ast::MacCall) {
for pass in self.passes.iter_mut() { pass.check_mac(context, a); }
}
fn enter_where_predicate(&mut self, context: &EarlyContext<'_>,
a: &rustc_ast::WherePredicate) {
for pass in self.passes.iter_mut() {
pass.enter_where_predicate(context, a);
}
}
fn exit_where_predicate(&mut self, context: &EarlyContext<'_>,
a: &rustc_ast::WherePredicate) {
for pass in self.passes.iter_mut() {
pass.exit_where_predicate(context, a);
}
}
}crate::early_lint_methods!(impl_early_lint_pass, []);
276
277pub trait EarlyCheckNode<'a>: Copy {
280 fn id(self) -> ast::NodeId;
281 fn attrs(self) -> &'a [ast::Attribute];
282 fn check<'ecx, T: EarlyLintPass>(self, cx: &mut EarlyContextAndPass<'ecx, T>);
283}
284
285impl<'a> EarlyCheckNode<'a> for (&'a ast::Crate, &'a [ast::Attribute]) {
286 fn id(self) -> ast::NodeId {
287 ast::CRATE_NODE_ID
288 }
289 fn attrs(self) -> &'a [ast::Attribute] {
290 self.1
291 }
292 fn check<'ecx, T: EarlyLintPass>(self, cx: &mut EarlyContextAndPass<'ecx, T>) {
293 { cx.pass.check_crate(&cx.context, self.0); };lint_callback!(cx, check_crate, self.0);
294 ast_visit::walk_crate(cx, self.0);
295 { cx.pass.check_crate_post(&cx.context, self.0); };lint_callback!(cx, check_crate_post, self.0);
296 }
297}
298
299impl<'a> EarlyCheckNode<'a> for (ast::NodeId, &'a [ast::Attribute], &'a [Box<ast::Item>]) {
300 fn id(self) -> ast::NodeId {
301 self.0
302 }
303 fn attrs(self) -> &'a [ast::Attribute] {
304 self.1
305 }
306 fn check<'ecx, T: EarlyLintPass>(self, cx: &mut EarlyContextAndPass<'ecx, T>) {
307 for elem in self.1 {
match ::rustc_ast_ir::visit::VisitorResult::branch(cx.visit_attribute(elem))
{
core::ops::ControlFlow::Continue(()) =>
(),
#[allow(unreachable_code)]
core::ops::ControlFlow::Break(r) => {
return ::rustc_ast_ir::visit::VisitorResult::from_residual(r);
}
};
};walk_list!(cx, visit_attribute, self.1);
308 for elem in self.2 {
match ::rustc_ast_ir::visit::VisitorResult::branch(cx.visit_item(elem)) {
core::ops::ControlFlow::Continue(()) =>
(),
#[allow(unreachable_code)]
core::ops::ControlFlow::Break(r) => {
return ::rustc_ast_ir::visit::VisitorResult::from_residual(r);
}
};
};walk_list!(cx, visit_item, self.2);
309 }
310}
311
312pub fn check_ast_node<'a>(
313 sess: &Session,
314 features: &Features,
315 pre_expansion: bool,
316 lint_store: &LintStore,
317 registered_tools: &RegisteredTools,
318 lint_buffer: Option<LintBuffer>,
319 builtin_lints: impl EarlyLintPass + 'static,
320 check_node: impl EarlyCheckNode<'a>,
321) {
322 let context = EarlyContext::new(
323 sess,
324 features,
325 !pre_expansion,
326 lint_store,
327 registered_tools,
328 lint_buffer.unwrap_or_default(),
329 );
330
331 let passes =
335 if pre_expansion { &lint_store.pre_expansion_passes } else { &lint_store.early_passes };
336 if passes.is_empty() {
337 check_ast_node_inner(sess, check_node, context, builtin_lints);
338 } else {
339 let mut passes: Vec<_> = passes.iter().map(|mk_pass| (mk_pass)()).collect();
340 passes.push(Box::new(builtin_lints));
341 let pass = RuntimeCombinedEarlyLintPass { passes: &mut passes[..] };
342 check_ast_node_inner(sess, check_node, context, pass);
343 }
344}
345
346fn check_ast_node_inner<'a, T: EarlyLintPass>(
347 sess: &Session,
348 check_node: impl EarlyCheckNode<'a>,
349 context: EarlyContext<'_>,
350 pass: T,
351) {
352 let mut cx = EarlyContextAndPass { context, pass };
353
354 cx.with_lint_attrs(check_node.id(), check_node.attrs(), |cx| check_node.check(cx));
355
356 for (id, lints) in cx.context.buffered.map {
360 if !lints.is_empty() {
361 if !sess.dcx().has_errors().is_some() {
{
::core::panicking::panic_fmt(format_args!("failed to process buffered lint here (dummy = {0})",
id == ast::DUMMY_NODE_ID));
}
};assert!(
362 sess.dcx().has_errors().is_some(),
363 "failed to process buffered lint here (dummy = {})",
364 id == ast::DUMMY_NODE_ID
365 );
366 break;
367 }
368 }
369}