rustc_expand/mbe/macro_check.rs
1//! Checks that meta-variables in macro definition are correctly declared and used.
2//!
3//! # What is checked
4//!
5//! ## Meta-variables must not be bound twice
6//!
7//! ```compile_fail
8//! macro_rules! foo { ($x:tt $x:tt) => { $x }; }
9//! ```
10//!
11//! This check is sound (no false-negative) and complete (no false-positive).
12//!
13//! ## Meta-variables must not be free
14//!
15//! ```
16//! macro_rules! foo { () => { $x }; }
17//! ```
18//!
19//! This check is also done at macro instantiation but only if the branch is taken.
20//!
21//! ## Meta-variables must repeat at least as many times as their binder
22//!
23//! ```
24//! macro_rules! foo { ($($x:tt)*) => { $x }; }
25//! ```
26//!
27//! This check is also done at macro instantiation but only if the branch is taken.
28//!
29//! ## Meta-variables must repeat with the same Kleene operators as their binder
30//!
31//! ```
32//! macro_rules! foo { ($($x:tt)+) => { $($x)* }; }
33//! ```
34//!
35//! This check is not done at macro instantiation.
36//!
37//! # Disclaimer
38//!
39//! In the presence of nested macros (a macro defined in a macro), those checks may have false
40//! positives and false negatives. We try to detect those cases by recognizing potential macro
41//! definitions in RHSes, but nested macros may be hidden through the use of particular values of
42//! meta-variables.
43//!
44//! ## Examples of false positive
45//!
46//! False positives can come from cases where we don't recognize a nested macro, because it depends
47//! on particular values of meta-variables. In the following example, we think both instances of
48//! `$x` are free, which is a correct statement if `$name` is anything but `macro_rules`. But when
49//! `$name` is `macro_rules`, like in the instantiation below, then `$x:tt` is actually a binder of
50//! the nested macro and `$x` is bound to it.
51//!
52//! ```
53//! macro_rules! foo { ($name:ident) => { $name! bar { ($x:tt) => { $x }; } }; }
54//! foo!(macro_rules);
55//! ```
56//!
57//! False positives can also come from cases where we think there is a nested macro while there
58//! isn't. In the following example, we think `$x` is free, which is incorrect because `bar` is not
59//! a nested macro since it is not evaluated as code by `stringify!`.
60//!
61//! ```
62//! macro_rules! foo { () => { stringify!(macro_rules! bar { () => { $x }; }) }; }
63//! ```
64//!
65//! ## Examples of false negative
66//!
67//! False negatives can come from cases where we don't recognize a meta-variable, because it depends
68//! on particular values of meta-variables. In the following examples, we don't see that if `$d` is
69//! instantiated with `$` then `$d z` becomes `$z` in the nested macro definition and is thus a free
70//! meta-variable. Note however, that if `foo` is instantiated, then we would check the definition
71//! of `bar` and would see the issue.
72//!
73//! ```
74//! macro_rules! foo { ($d:tt) => { macro_rules! bar { ($y:tt) => { $d z }; } }; }
75//! ```
76//!
77//! # How it is checked
78//!
79//! There are 3 main functions: `check_binders`, `check_occurrences`, and `check_nested_macro`. They
80//! all need some kind of environment.
81//!
82//! ## Environments
83//!
84//! Environments are used to pass information.
85//!
86//! ### From LHS to RHS
87//!
88//! When checking a LHS with `check_binders`, we produce (and use) an environment for binders,
89//! namely `Binders`. This is a mapping from binder name to information about that binder: the span
90//! of the binder for error messages and the stack of Kleene operators under which it was bound in
91//! the LHS.
92//!
93//! This environment is used by both the LHS and RHS. The LHS uses it to detect duplicate binders.
94//! The RHS uses it to detect the other errors.
95//!
96//! ### From outer macro to inner macro
97//!
98//! When checking the RHS of an outer macro and we detect a nested macro definition, we push the
99//! current state, namely `MacroState`, to an environment of nested macro definitions. Each state
100//! stores the LHS binders when entering the macro definition as well as the stack of Kleene
101//! operators under which the inner macro is defined in the RHS.
102//!
103//! This environment is a stack representing the nesting of macro definitions. As such, the stack of
104//! Kleene operators under which a meta-variable is repeating is the concatenation of the stacks
105//! stored when entering a macro definition starting from the state in which the meta-variable is
106//! bound.
107
108use rustc_ast::token::{Delimiter, IdentIsRaw, Token, TokenKind};
109use rustc_ast::{DUMMY_NODE_ID, NodeId};
110use rustc_data_structures::fx::FxHashMap;
111use rustc_errors::DecorateDiagCompat;
112use rustc_session::lint::builtin::META_VARIABLE_MISUSE;
113use rustc_session::parse::ParseSess;
114use rustc_span::{ErrorGuaranteed, MacroRulesNormalizedIdent, Span, kw};
115use smallvec::SmallVec;
116
117use crate::errors;
118use crate::mbe::{KleeneToken, TokenTree};
119
120/// Stack represented as linked list.
121///
122/// Those are used for environments because they grow incrementally and are not mutable.
123enum Stack<'a, T> {
124 /// Empty stack.
125 Empty,
126 /// A non-empty stack.
127 Push {
128 /// The top element.
129 top: T,
130 /// The previous elements.
131 prev: &'a Stack<'a, T>,
132 },
133}
134
135impl<'a, T> Stack<'a, T> {
136 /// Returns whether a stack is empty.
137 fn is_empty(&self) -> bool {
138 matches!(*self, Stack::Empty)
139 }
140
141 /// Returns a new stack with an element of top.
142 fn push(&'a self, top: T) -> Stack<'a, T> {
143 Stack::Push { top, prev: self }
144 }
145}
146
147impl<'a, T> Iterator for &'a Stack<'a, T> {
148 type Item = &'a T;
149
150 // Iterates from top to bottom of the stack.
151 fn next(&mut self) -> Option<&'a T> {
152 match self {
153 Stack::Empty => None,
154 Stack::Push { top, prev } => {
155 *self = prev;
156 Some(top)
157 }
158 }
159 }
160}
161
162impl From<&Stack<'_, KleeneToken>> for SmallVec<[KleeneToken; 1]> {
163 fn from(ops: &Stack<'_, KleeneToken>) -> SmallVec<[KleeneToken; 1]> {
164 let mut ops: SmallVec<[KleeneToken; 1]> = ops.cloned().collect();
165 // The stack is innermost on top. We want outermost first.
166 ops.reverse();
167 ops
168 }
169}
170
171/// Information attached to a meta-variable binder in LHS.
172struct BinderInfo {
173 /// The span of the meta-variable in LHS.
174 span: Span,
175 /// The stack of Kleene operators (outermost first).
176 ops: SmallVec<[KleeneToken; 1]>,
177}
178
179/// An environment of meta-variables to their binder information.
180type Binders = FxHashMap<MacroRulesNormalizedIdent, BinderInfo>;
181
182/// The state at which we entered a macro definition in the RHS of another macro definition.
183struct MacroState<'a> {
184 /// The binders of the branch where we entered the macro definition.
185 binders: &'a Binders,
186 /// The stack of Kleene operators (outermost first) where we entered the macro definition.
187 ops: SmallVec<[KleeneToken; 1]>,
188}
189
190/// Checks that meta-variables are used correctly in one rule of a macro definition.
191///
192/// Arguments:
193/// - `psess` is used to emit diagnostics and lints
194/// - `node_id` is used to emit lints
195/// - `args`, `lhs`, and `rhs` represent the rule
196pub(super) fn check_meta_variables(
197 psess: &ParseSess,
198 node_id: NodeId,
199 args: Option<&TokenTree>,
200 lhs: &TokenTree,
201 rhs: &TokenTree,
202) -> Result<(), ErrorGuaranteed> {
203 let mut guar = None;
204 let mut binders = Binders::default();
205 if let Some(args) = args {
206 check_binders(psess, node_id, args, &Stack::Empty, &mut binders, &Stack::Empty, &mut guar);
207 }
208 check_binders(psess, node_id, lhs, &Stack::Empty, &mut binders, &Stack::Empty, &mut guar);
209 check_occurrences(psess, node_id, rhs, &Stack::Empty, &binders, &Stack::Empty, &mut guar);
210 guar.map_or(Ok(()), Err)
211}
212
213/// Checks `lhs` as part of the LHS of a macro definition.
214///
215/// Arguments:
216/// - `psess` is used to emit diagnostics and lints
217/// - `node_id` is used to emit lints
218/// - `lhs` is checked as part of a LHS
219/// - `macros` is the stack of possible outer macros
220/// - `binders` contains the binders of the LHS
221/// - `ops` is the stack of Kleene operators from the LHS
222/// - `guar` is set in case of errors
223fn check_binders(
224 psess: &ParseSess,
225 node_id: NodeId,
226 lhs: &TokenTree,
227 macros: &Stack<'_, MacroState<'_>>,
228 binders: &mut Binders,
229 ops: &Stack<'_, KleeneToken>,
230 guar: &mut Option<ErrorGuaranteed>,
231) {
232 match *lhs {
233 TokenTree::Token(..) => {}
234 // This can only happen when checking a nested macro because this LHS is then in the RHS of
235 // the outer macro. See ui/macros/macro-of-higher-order.rs where $y:$fragment in the
236 // LHS of the nested macro (and RHS of the outer macro) is parsed as MetaVar(y) Colon
237 // MetaVar(fragment) and not as MetaVarDecl(y, fragment).
238 TokenTree::MetaVar(span, name) => {
239 if macros.is_empty() {
240 psess.dcx().span_bug(span, "unexpected MetaVar in lhs");
241 }
242 let name = MacroRulesNormalizedIdent::new(name);
243 // There are 3 possibilities:
244 if let Some(prev_info) = binders.get(&name) {
245 // 1. The meta-variable is already bound in the current LHS: This is an error.
246 buffer_lint(
247 psess,
248 span,
249 node_id,
250 errors::DuplicateMatcherBindingLint { span, prev: prev_info.span },
251 );
252 } else if get_binder_info(macros, binders, name).is_none() {
253 // 2. The meta-variable is free: This is a binder.
254 binders.insert(name, BinderInfo { span, ops: ops.into() });
255 } else {
256 // 3. The meta-variable is bound: This is an occurrence.
257 check_occurrences(psess, node_id, lhs, macros, binders, ops, guar);
258 }
259 }
260 // Similarly, this can only happen when checking a toplevel macro.
261 TokenTree::MetaVarDecl { span, name, .. } => {
262 if !macros.is_empty() {
263 psess.dcx().span_bug(span, "unexpected MetaVarDecl in nested lhs");
264 }
265 let name = MacroRulesNormalizedIdent::new(name);
266 if let Some(prev_info) = get_binder_info(macros, binders, name) {
267 // Duplicate binders at the top-level macro definition are errors. The lint is only
268 // for nested macro definitions.
269 *guar = Some(
270 psess
271 .dcx()
272 .emit_err(errors::DuplicateMatcherBinding { span, prev: prev_info.span }),
273 );
274 } else {
275 binders.insert(name, BinderInfo { span, ops: ops.into() });
276 }
277 }
278 // `MetaVarExpr` can not appear in the LHS of a macro arm
279 TokenTree::MetaVarExpr(..) => {}
280 TokenTree::Delimited(.., ref del) => {
281 for tt in &del.tts {
282 check_binders(psess, node_id, tt, macros, binders, ops, guar);
283 }
284 }
285 TokenTree::Sequence(_, ref seq) => {
286 let ops = ops.push(seq.kleene);
287 for tt in &seq.tts {
288 check_binders(psess, node_id, tt, macros, binders, &ops, guar);
289 }
290 }
291 }
292}
293
294/// Returns the binder information of a meta-variable.
295///
296/// Arguments:
297/// - `macros` is the stack of possible outer macros
298/// - `binders` contains the current binders
299/// - `name` is the name of the meta-variable we are looking for
300fn get_binder_info<'a>(
301 mut macros: &'a Stack<'a, MacroState<'a>>,
302 binders: &'a Binders,
303 name: MacroRulesNormalizedIdent,
304) -> Option<&'a BinderInfo> {
305 binders.get(&name).or_else(|| macros.find_map(|state| state.binders.get(&name)))
306}
307
308/// Checks `rhs` as part of the RHS of a macro definition.
309///
310/// Arguments:
311/// - `psess` is used to emit diagnostics and lints
312/// - `node_id` is used to emit lints
313/// - `rhs` is checked as part of a RHS
314/// - `macros` is the stack of possible outer macros
315/// - `binders` contains the binders of the associated LHS
316/// - `ops` is the stack of Kleene operators from the RHS
317/// - `guar` is set in case of errors
318fn check_occurrences(
319 psess: &ParseSess,
320 node_id: NodeId,
321 rhs: &TokenTree,
322 macros: &Stack<'_, MacroState<'_>>,
323 binders: &Binders,
324 ops: &Stack<'_, KleeneToken>,
325 guar: &mut Option<ErrorGuaranteed>,
326) {
327 match *rhs {
328 TokenTree::Token(..) => {}
329 TokenTree::MetaVarDecl { span, .. } => {
330 psess.dcx().span_bug(span, "unexpected MetaVarDecl in rhs")
331 }
332 TokenTree::MetaVar(span, name) => {
333 let name = MacroRulesNormalizedIdent::new(name);
334 check_ops_is_prefix(psess, node_id, macros, binders, ops, span, name);
335 }
336 TokenTree::MetaVarExpr(dl, ref mve) => {
337 mve.for_each_metavar((), |_, ident| {
338 let name = MacroRulesNormalizedIdent::new(*ident);
339 check_ops_is_prefix(psess, node_id, macros, binders, ops, dl.entire(), name);
340 });
341 }
342 TokenTree::Delimited(.., ref del) => {
343 check_nested_occurrences(psess, node_id, &del.tts, macros, binders, ops, guar);
344 }
345 TokenTree::Sequence(_, ref seq) => {
346 let ops = ops.push(seq.kleene);
347 check_nested_occurrences(psess, node_id, &seq.tts, macros, binders, &ops, guar);
348 }
349 }
350}
351
352/// Represents the processed prefix of a nested macro.
353#[derive(Clone, Copy, PartialEq, Eq)]
354enum NestedMacroState {
355 /// Nothing that matches a nested macro definition was processed yet.
356 Empty,
357 /// The token `macro_rules` was processed.
358 MacroRules,
359 /// The tokens `macro_rules!` were processed.
360 MacroRulesBang,
361 /// The tokens `macro_rules!` followed by a name were processed. The name may be either directly
362 /// an identifier or a meta-variable (that hopefully would be instantiated by an identifier).
363 MacroRulesBangName,
364 /// The keyword `macro` was processed.
365 Macro,
366 /// The keyword `macro` followed by a name was processed.
367 MacroName,
368 /// The keyword `macro` followed by a name and a token delimited by parentheses was processed.
369 MacroNameParen,
370}
371
372/// Checks `tts` as part of the RHS of a macro definition, tries to recognize nested macro
373/// definitions.
374///
375/// Arguments:
376/// - `psess` is used to emit diagnostics and lints
377/// - `node_id` is used to emit lints
378/// - `tts` is checked as part of a RHS and may contain macro definitions
379/// - `macros` is the stack of possible outer macros
380/// - `binders` contains the binders of the associated LHS
381/// - `ops` is the stack of Kleene operators from the RHS
382/// - `guar` is set in case of errors
383fn check_nested_occurrences(
384 psess: &ParseSess,
385 node_id: NodeId,
386 tts: &[TokenTree],
387 macros: &Stack<'_, MacroState<'_>>,
388 binders: &Binders,
389 ops: &Stack<'_, KleeneToken>,
390 guar: &mut Option<ErrorGuaranteed>,
391) {
392 let mut state = NestedMacroState::Empty;
393 let nested_macros = macros.push(MacroState { binders, ops: ops.into() });
394 let mut nested_binders = Binders::default();
395 for tt in tts {
396 match (state, tt) {
397 (
398 NestedMacroState::Empty,
399 &TokenTree::Token(Token { kind: TokenKind::Ident(name, IdentIsRaw::No), .. }),
400 ) => {
401 if name == kw::MacroRules {
402 state = NestedMacroState::MacroRules;
403 } else if name == kw::Macro {
404 state = NestedMacroState::Macro;
405 }
406 }
407 (
408 NestedMacroState::MacroRules,
409 &TokenTree::Token(Token { kind: TokenKind::Bang, .. }),
410 ) => {
411 state = NestedMacroState::MacroRulesBang;
412 }
413 (
414 NestedMacroState::MacroRulesBang,
415 &TokenTree::Token(Token { kind: TokenKind::Ident(..), .. }),
416 ) => {
417 state = NestedMacroState::MacroRulesBangName;
418 }
419 (NestedMacroState::MacroRulesBang, &TokenTree::MetaVar(..)) => {
420 state = NestedMacroState::MacroRulesBangName;
421 // We check that the meta-variable is correctly used.
422 check_occurrences(psess, node_id, tt, macros, binders, ops, guar);
423 }
424 (NestedMacroState::MacroRulesBangName, TokenTree::Delimited(.., del))
425 | (NestedMacroState::MacroName, TokenTree::Delimited(.., del))
426 if del.delim == Delimiter::Brace =>
427 {
428 let macro_rules = state == NestedMacroState::MacroRulesBangName;
429 state = NestedMacroState::Empty;
430 let rest =
431 check_nested_macro(psess, node_id, macro_rules, &del.tts, &nested_macros, guar);
432 // If we did not check the whole macro definition, then check the rest as if outside
433 // the macro definition.
434 check_nested_occurrences(
435 psess,
436 node_id,
437 &del.tts[rest..],
438 macros,
439 binders,
440 ops,
441 guar,
442 );
443 }
444 (
445 NestedMacroState::Macro,
446 &TokenTree::Token(Token { kind: TokenKind::Ident(..), .. }),
447 ) => {
448 state = NestedMacroState::MacroName;
449 }
450 (NestedMacroState::Macro, &TokenTree::MetaVar(..)) => {
451 state = NestedMacroState::MacroName;
452 // We check that the meta-variable is correctly used.
453 check_occurrences(psess, node_id, tt, macros, binders, ops, guar);
454 }
455 (NestedMacroState::MacroName, TokenTree::Delimited(.., del))
456 if del.delim == Delimiter::Parenthesis =>
457 {
458 state = NestedMacroState::MacroNameParen;
459 nested_binders = Binders::default();
460 check_binders(
461 psess,
462 node_id,
463 tt,
464 &nested_macros,
465 &mut nested_binders,
466 &Stack::Empty,
467 guar,
468 );
469 }
470 (NestedMacroState::MacroNameParen, TokenTree::Delimited(.., del))
471 if del.delim == Delimiter::Brace =>
472 {
473 state = NestedMacroState::Empty;
474 check_occurrences(
475 psess,
476 node_id,
477 tt,
478 &nested_macros,
479 &nested_binders,
480 &Stack::Empty,
481 guar,
482 );
483 }
484 (_, tt) => {
485 state = NestedMacroState::Empty;
486 check_occurrences(psess, node_id, tt, macros, binders, ops, guar);
487 }
488 }
489 }
490}
491
492/// Checks the body of nested macro, returns where the check stopped.
493///
494/// The token trees are checked as long as they look like a list of (LHS) => {RHS} token trees. This
495/// check is a best-effort to detect a macro definition. It returns the position in `tts` where we
496/// stopped checking because we detected we were not in a macro definition anymore.
497///
498/// Arguments:
499/// - `psess` is used to emit diagnostics and lints
500/// - `node_id` is used to emit lints
501/// - `macro_rules` specifies whether the macro is `macro_rules`
502/// - `tts` is checked as a list of (LHS) => {RHS}
503/// - `macros` is the stack of outer macros
504/// - `guar` is set in case of errors
505fn check_nested_macro(
506 psess: &ParseSess,
507 node_id: NodeId,
508 macro_rules: bool,
509 tts: &[TokenTree],
510 macros: &Stack<'_, MacroState<'_>>,
511 guar: &mut Option<ErrorGuaranteed>,
512) -> usize {
513 let n = tts.len();
514 let mut i = 0;
515 let separator = if macro_rules { TokenKind::Semi } else { TokenKind::Comma };
516 loop {
517 // We expect 3 token trees: `(LHS) => {RHS}`. The separator is checked after.
518 if i + 2 >= n
519 || !tts[i].is_delimited()
520 || !tts[i + 1].is_token(&TokenKind::FatArrow)
521 || !tts[i + 2].is_delimited()
522 {
523 break;
524 }
525 let lhs = &tts[i];
526 let rhs = &tts[i + 2];
527 let mut binders = Binders::default();
528 check_binders(psess, node_id, lhs, macros, &mut binders, &Stack::Empty, guar);
529 check_occurrences(psess, node_id, rhs, macros, &binders, &Stack::Empty, guar);
530 // Since the last semicolon is optional for `macro_rules` macros and decl_macro are not terminated,
531 // we increment our checked position by how many token trees we already checked (the 3
532 // above) before checking for the separator.
533 i += 3;
534 if i == n || !tts[i].is_token(&separator) {
535 break;
536 }
537 // We increment our checked position for the semicolon.
538 i += 1;
539 }
540 i
541}
542
543/// Checks that a meta-variable occurrence is valid.
544///
545/// Arguments:
546/// - `psess` is used to emit diagnostics and lints
547/// - `node_id` is used to emit lints
548/// - `macros` is the stack of possible outer macros
549/// - `binders` contains the binders of the associated LHS
550/// - `ops` is the stack of Kleene operators from the RHS
551/// - `span` is the span of the meta-variable to check
552/// - `name` is the name of the meta-variable to check
553fn check_ops_is_prefix(
554 psess: &ParseSess,
555 node_id: NodeId,
556 macros: &Stack<'_, MacroState<'_>>,
557 binders: &Binders,
558 ops: &Stack<'_, KleeneToken>,
559 span: Span,
560 name: MacroRulesNormalizedIdent,
561) {
562 let macros = macros.push(MacroState { binders, ops: ops.into() });
563 // Accumulates the stacks the operators of each state until (and including when) the
564 // meta-variable is found. The innermost stack is first.
565 let mut acc: SmallVec<[&SmallVec<[KleeneToken; 1]>; 1]> = SmallVec::new();
566 for state in ¯os {
567 acc.push(&state.ops);
568 if let Some(binder) = state.binders.get(&name) {
569 // This variable concatenates the stack of operators from the RHS of the LHS where the
570 // meta-variable was defined to where it is used (in possibly nested macros). The
571 // outermost operator is first.
572 let mut occurrence_ops: SmallVec<[KleeneToken; 2]> = SmallVec::new();
573 // We need to iterate from the end to start with outermost stack.
574 for ops in acc.iter().rev() {
575 occurrence_ops.extend_from_slice(ops);
576 }
577 ops_is_prefix(psess, node_id, span, name, &binder.ops, &occurrence_ops);
578 return;
579 }
580 }
581 buffer_lint(psess, span, node_id, errors::UnknownMacroVariable { name });
582}
583
584/// Returns whether `binder_ops` is a prefix of `occurrence_ops`.
585///
586/// The stack of Kleene operators of a meta-variable occurrence just needs to have the stack of
587/// Kleene operators of its binder as a prefix.
588///
589/// Consider $i in the following example:
590/// ```ignore (illustrative)
591/// ( $( $i:ident = $($j:ident),+ );* ) => { $($( $i += $j; )+)* }
592/// ```
593/// It occurs under the Kleene stack ["*", "+"] and is bound under ["*"] only.
594///
595/// Arguments:
596/// - `psess` is used to emit diagnostics and lints
597/// - `node_id` is used to emit lints
598/// - `span` is the span of the meta-variable being check
599/// - `name` is the name of the meta-variable being check
600/// - `binder_ops` is the stack of Kleene operators for the binder
601/// - `occurrence_ops` is the stack of Kleene operators for the occurrence
602fn ops_is_prefix(
603 psess: &ParseSess,
604 node_id: NodeId,
605 span: Span,
606 ident: MacroRulesNormalizedIdent,
607 binder_ops: &[KleeneToken],
608 occurrence_ops: &[KleeneToken],
609) {
610 for (i, binder) in binder_ops.iter().enumerate() {
611 if i >= occurrence_ops.len() {
612 buffer_lint(
613 psess,
614 span,
615 node_id,
616 errors::MetaVarStillRepeatingLint { label: binder.span, ident },
617 );
618 return;
619 }
620 let occurrence = &occurrence_ops[i];
621 if occurrence.op != binder.op {
622 buffer_lint(
623 psess,
624 span,
625 node_id,
626 errors::MetaVariableWrongOperator {
627 binder: binder.span,
628 occurrence: occurrence.span,
629 },
630 );
631 return;
632 }
633 }
634}
635
636fn buffer_lint(
637 psess: &ParseSess,
638 span: Span,
639 node_id: NodeId,
640 diag: impl Into<DecorateDiagCompat>,
641) {
642 // Macros loaded from other crates have dummy node ids.
643 if node_id != DUMMY_NODE_ID {
644 psess.buffer_lint(META_VARIABLE_MISUSE, span, node_id, diag);
645 }
646}