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::MultiSpan;
112use rustc_lint_defs::BuiltinLintDiag;
113use rustc_session::lint::builtin::META_VARIABLE_MISUSE;
114use rustc_session::parse::ParseSess;
115use rustc_span::{ErrorGuaranteed, MacroRulesNormalizedIdent, Span, kw};
116use smallvec::SmallVec;
117
118use crate::errors;
119use crate::mbe::{KleeneToken, TokenTree};
120
121/// Stack represented as linked list.
122///
123/// Those are used for environments because they grow incrementally and are not mutable.
124enum Stack<'a, T> {
125    /// Empty stack.
126    Empty,
127    /// A non-empty stack.
128    Push {
129        /// The top element.
130        top: T,
131        /// The previous elements.
132        prev: &'a Stack<'a, T>,
133    },
134}
135
136impl<'a, T> Stack<'a, T> {
137    /// Returns whether a stack is empty.
138    fn is_empty(&self) -> bool {
139        matches!(*self, Stack::Empty)
140    }
141
142    /// Returns a new stack with an element of top.
143    fn push(&'a self, top: T) -> Stack<'a, T> {
144        Stack::Push { top, prev: self }
145    }
146}
147
148impl<'a, T> Iterator for &'a Stack<'a, T> {
149    type Item = &'a T;
150
151    // Iterates from top to bottom of the stack.
152    fn next(&mut self) -> Option<&'a T> {
153        match self {
154            Stack::Empty => None,
155            Stack::Push { top, prev } => {
156                *self = prev;
157                Some(top)
158            }
159        }
160    }
161}
162
163impl From<&Stack<'_, KleeneToken>> for SmallVec<[KleeneToken; 1]> {
164    fn from(ops: &Stack<'_, KleeneToken>) -> SmallVec<[KleeneToken; 1]> {
165        let mut ops: SmallVec<[KleeneToken; 1]> = ops.cloned().collect();
166        // The stack is innermost on top. We want outermost first.
167        ops.reverse();
168        ops
169    }
170}
171
172/// Information attached to a meta-variable binder in LHS.
173struct BinderInfo {
174    /// The span of the meta-variable in LHS.
175    span: Span,
176    /// The stack of Kleene operators (outermost first).
177    ops: SmallVec<[KleeneToken; 1]>,
178}
179
180/// An environment of meta-variables to their binder information.
181type Binders = FxHashMap<MacroRulesNormalizedIdent, BinderInfo>;
182
183/// The state at which we entered a macro definition in the RHS of another macro definition.
184struct MacroState<'a> {
185    /// The binders of the branch where we entered the macro definition.
186    binders: &'a Binders,
187    /// The stack of Kleene operators (outermost first) where we entered the macro definition.
188    ops: SmallVec<[KleeneToken; 1]>,
189}
190
191/// Checks that meta-variables are used correctly in one rule of a macro definition.
192///
193/// Arguments:
194/// - `psess` is used to emit diagnostics and lints
195/// - `node_id` is used to emit lints
196/// - `lhs` and `rhs` represent the rule
197pub(super) fn check_meta_variables(
198    psess: &ParseSess,
199    node_id: NodeId,
200    lhs: &TokenTree,
201    rhs: &TokenTree,
202) -> Result<(), ErrorGuaranteed> {
203    let mut guar = None;
204    let mut binders = Binders::default();
205    check_binders(psess, node_id, lhs, &Stack::Empty, &mut binders, &Stack::Empty, &mut guar);
206    check_occurrences(psess, node_id, rhs, &Stack::Empty, &binders, &Stack::Empty, &mut guar);
207    guar.map_or(Ok(()), Err)
208}
209
210/// Checks `lhs` as part of the LHS of a macro definition, extends `binders` with new binders, and
211/// sets `valid` to false in case of errors.
212///
213/// Arguments:
214/// - `psess` is used to emit diagnostics and lints
215/// - `node_id` is used to emit lints
216/// - `lhs` is checked as part of a LHS
217/// - `macros` is the stack of possible outer macros
218/// - `binders` contains the binders of the LHS
219/// - `ops` is the stack of Kleene operators from the LHS
220/// - `guar` is set in case of errors
221fn check_binders(
222    psess: &ParseSess,
223    node_id: NodeId,
224    lhs: &TokenTree,
225    macros: &Stack<'_, MacroState<'_>>,
226    binders: &mut Binders,
227    ops: &Stack<'_, KleeneToken>,
228    guar: &mut Option<ErrorGuaranteed>,
229) {
230    match *lhs {
231        TokenTree::Token(..) => {}
232        // This can only happen when checking a nested macro because this LHS is then in the RHS of
233        // the outer macro. See ui/macros/macro-of-higher-order.rs where $y:$fragment in the
234        // LHS of the nested macro (and RHS of the outer macro) is parsed as MetaVar(y) Colon
235        // MetaVar(fragment) and not as MetaVarDecl(y, fragment).
236        TokenTree::MetaVar(span, name) => {
237            if macros.is_empty() {
238                psess.dcx().span_bug(span, "unexpected MetaVar in lhs");
239            }
240            let name = MacroRulesNormalizedIdent::new(name);
241            // There are 3 possibilities:
242            if let Some(prev_info) = binders.get(&name) {
243                // 1. The meta-variable is already bound in the current LHS: This is an error.
244                let mut span = MultiSpan::from_span(span);
245                span.push_span_label(prev_info.span, "previous declaration");
246                buffer_lint(psess, span, node_id, BuiltinLintDiag::DuplicateMatcherBinding);
247            } else if get_binder_info(macros, binders, name).is_none() {
248                // 2. The meta-variable is free: This is a binder.
249                binders.insert(name, BinderInfo { span, ops: ops.into() });
250            } else {
251                // 3. The meta-variable is bound: This is an occurrence.
252                check_occurrences(psess, node_id, lhs, macros, binders, ops, guar);
253            }
254        }
255        // Similarly, this can only happen when checking a toplevel macro.
256        TokenTree::MetaVarDecl { span, name, .. } => {
257            if !macros.is_empty() {
258                psess.dcx().span_bug(span, "unexpected MetaVarDecl in nested lhs");
259            }
260            let name = MacroRulesNormalizedIdent::new(name);
261            if let Some(prev_info) = get_binder_info(macros, binders, name) {
262                // Duplicate binders at the top-level macro definition are errors. The lint is only
263                // for nested macro definitions.
264                *guar = Some(
265                    psess
266                        .dcx()
267                        .emit_err(errors::DuplicateMatcherBinding { span, prev: prev_info.span }),
268                );
269            } else {
270                binders.insert(name, BinderInfo { span, ops: ops.into() });
271            }
272        }
273        // `MetaVarExpr` can not appear in the LHS of a macro arm
274        TokenTree::MetaVarExpr(..) => {}
275        TokenTree::Delimited(.., ref del) => {
276            for tt in &del.tts {
277                check_binders(psess, node_id, tt, macros, binders, ops, guar);
278            }
279        }
280        TokenTree::Sequence(_, ref seq) => {
281            let ops = ops.push(seq.kleene);
282            for tt in &seq.tts {
283                check_binders(psess, node_id, tt, macros, binders, &ops, guar);
284            }
285        }
286    }
287}
288
289/// Returns the binder information of a meta-variable.
290///
291/// Arguments:
292/// - `macros` is the stack of possible outer macros
293/// - `binders` contains the current binders
294/// - `name` is the name of the meta-variable we are looking for
295fn get_binder_info<'a>(
296    mut macros: &'a Stack<'a, MacroState<'a>>,
297    binders: &'a Binders,
298    name: MacroRulesNormalizedIdent,
299) -> Option<&'a BinderInfo> {
300    binders.get(&name).or_else(|| macros.find_map(|state| state.binders.get(&name)))
301}
302
303/// Checks `rhs` as part of the RHS of a macro definition and sets `valid` to false in case of
304/// errors.
305///
306/// Arguments:
307/// - `psess` is used to emit diagnostics and lints
308/// - `node_id` is used to emit lints
309/// - `rhs` is checked as part of a RHS
310/// - `macros` is the stack of possible outer macros
311/// - `binders` contains the binders of the associated LHS
312/// - `ops` is the stack of Kleene operators from the RHS
313/// - `guar` is set in case of errors
314fn check_occurrences(
315    psess: &ParseSess,
316    node_id: NodeId,
317    rhs: &TokenTree,
318    macros: &Stack<'_, MacroState<'_>>,
319    binders: &Binders,
320    ops: &Stack<'_, KleeneToken>,
321    guar: &mut Option<ErrorGuaranteed>,
322) {
323    match *rhs {
324        TokenTree::Token(..) => {}
325        TokenTree::MetaVarDecl { span, .. } => {
326            psess.dcx().span_bug(span, "unexpected MetaVarDecl in rhs")
327        }
328        TokenTree::MetaVar(span, name) => {
329            let name = MacroRulesNormalizedIdent::new(name);
330            check_ops_is_prefix(psess, node_id, macros, binders, ops, span, name);
331        }
332        TokenTree::MetaVarExpr(dl, ref mve) => {
333            mve.for_each_metavar((), |_, ident| {
334                let name = MacroRulesNormalizedIdent::new(*ident);
335                check_ops_is_prefix(psess, node_id, macros, binders, ops, dl.entire(), name);
336            });
337        }
338        TokenTree::Delimited(.., ref del) => {
339            check_nested_occurrences(psess, node_id, &del.tts, macros, binders, ops, guar);
340        }
341        TokenTree::Sequence(_, ref seq) => {
342            let ops = ops.push(seq.kleene);
343            check_nested_occurrences(psess, node_id, &seq.tts, macros, binders, &ops, guar);
344        }
345    }
346}
347
348/// Represents the processed prefix of a nested macro.
349#[derive(Clone, Copy, PartialEq, Eq)]
350enum NestedMacroState {
351    /// Nothing that matches a nested macro definition was processed yet.
352    Empty,
353    /// The token `macro_rules` was processed.
354    MacroRules,
355    /// The tokens `macro_rules!` were processed.
356    MacroRulesNot,
357    /// The tokens `macro_rules!` followed by a name were processed. The name may be either directly
358    /// an identifier or a meta-variable (that hopefully would be instantiated by an identifier).
359    MacroRulesNotName,
360    /// The keyword `macro` was processed.
361    Macro,
362    /// The keyword `macro` followed by a name was processed.
363    MacroName,
364    /// The keyword `macro` followed by a name and a token delimited by parentheses was processed.
365    MacroNameParen,
366}
367
368/// Checks `tts` as part of the RHS of a macro definition, tries to recognize nested macro
369/// definitions, and sets `valid` to false in case of errors.
370///
371/// Arguments:
372/// - `psess` is used to emit diagnostics and lints
373/// - `node_id` is used to emit lints
374/// - `tts` is checked as part of a RHS and may contain macro definitions
375/// - `macros` is the stack of possible outer macros
376/// - `binders` contains the binders of the associated LHS
377/// - `ops` is the stack of Kleene operators from the RHS
378/// - `guar` is set in case of errors
379fn check_nested_occurrences(
380    psess: &ParseSess,
381    node_id: NodeId,
382    tts: &[TokenTree],
383    macros: &Stack<'_, MacroState<'_>>,
384    binders: &Binders,
385    ops: &Stack<'_, KleeneToken>,
386    guar: &mut Option<ErrorGuaranteed>,
387) {
388    let mut state = NestedMacroState::Empty;
389    let nested_macros = macros.push(MacroState { binders, ops: ops.into() });
390    let mut nested_binders = Binders::default();
391    for tt in tts {
392        match (state, tt) {
393            (
394                NestedMacroState::Empty,
395                &TokenTree::Token(Token { kind: TokenKind::Ident(name, IdentIsRaw::No), .. }),
396            ) => {
397                if name == kw::MacroRules {
398                    state = NestedMacroState::MacroRules;
399                } else if name == kw::Macro {
400                    state = NestedMacroState::Macro;
401                }
402            }
403            (
404                NestedMacroState::MacroRules,
405                &TokenTree::Token(Token { kind: TokenKind::Bang, .. }),
406            ) => {
407                state = NestedMacroState::MacroRulesNot;
408            }
409            (
410                NestedMacroState::MacroRulesNot,
411                &TokenTree::Token(Token { kind: TokenKind::Ident(..), .. }),
412            ) => {
413                state = NestedMacroState::MacroRulesNotName;
414            }
415            (NestedMacroState::MacroRulesNot, &TokenTree::MetaVar(..)) => {
416                state = NestedMacroState::MacroRulesNotName;
417                // We check that the meta-variable is correctly used.
418                check_occurrences(psess, node_id, tt, macros, binders, ops, guar);
419            }
420            (NestedMacroState::MacroRulesNotName, TokenTree::Delimited(.., del))
421            | (NestedMacroState::MacroName, TokenTree::Delimited(.., del))
422                if del.delim == Delimiter::Brace =>
423            {
424                let macro_rules = state == NestedMacroState::MacroRulesNotName;
425                state = NestedMacroState::Empty;
426                let rest =
427                    check_nested_macro(psess, node_id, macro_rules, &del.tts, &nested_macros, guar);
428                // If we did not check the whole macro definition, then check the rest as if outside
429                // the macro definition.
430                check_nested_occurrences(
431                    psess,
432                    node_id,
433                    &del.tts[rest..],
434                    macros,
435                    binders,
436                    ops,
437                    guar,
438                );
439            }
440            (
441                NestedMacroState::Macro,
442                &TokenTree::Token(Token { kind: TokenKind::Ident(..), .. }),
443            ) => {
444                state = NestedMacroState::MacroName;
445            }
446            (NestedMacroState::Macro, &TokenTree::MetaVar(..)) => {
447                state = NestedMacroState::MacroName;
448                // We check that the meta-variable is correctly used.
449                check_occurrences(psess, node_id, tt, macros, binders, ops, guar);
450            }
451            (NestedMacroState::MacroName, TokenTree::Delimited(.., del))
452                if del.delim == Delimiter::Parenthesis =>
453            {
454                state = NestedMacroState::MacroNameParen;
455                nested_binders = Binders::default();
456                check_binders(
457                    psess,
458                    node_id,
459                    tt,
460                    &nested_macros,
461                    &mut nested_binders,
462                    &Stack::Empty,
463                    guar,
464                );
465            }
466            (NestedMacroState::MacroNameParen, TokenTree::Delimited(.., del))
467                if del.delim == Delimiter::Brace =>
468            {
469                state = NestedMacroState::Empty;
470                check_occurrences(
471                    psess,
472                    node_id,
473                    tt,
474                    &nested_macros,
475                    &nested_binders,
476                    &Stack::Empty,
477                    guar,
478                );
479            }
480            (_, tt) => {
481                state = NestedMacroState::Empty;
482                check_occurrences(psess, node_id, tt, macros, binders, ops, guar);
483            }
484        }
485    }
486}
487
488/// Checks the body of nested macro, returns where the check stopped, and sets `valid` to false in
489/// case of errors.
490///
491/// The token trees are checked as long as they look like a list of (LHS) => {RHS} token trees. This
492/// check is a best-effort to detect a macro definition. It returns the position in `tts` where we
493/// stopped checking because we detected we were not in a macro definition anymore.
494///
495/// Arguments:
496/// - `psess` is used to emit diagnostics and lints
497/// - `node_id` is used to emit lints
498/// - `macro_rules` specifies whether the macro is `macro_rules`
499/// - `tts` is checked as a list of (LHS) => {RHS}
500/// - `macros` is the stack of outer macros
501/// - `guar` is set in case of errors
502fn check_nested_macro(
503    psess: &ParseSess,
504    node_id: NodeId,
505    macro_rules: bool,
506    tts: &[TokenTree],
507    macros: &Stack<'_, MacroState<'_>>,
508    guar: &mut Option<ErrorGuaranteed>,
509) -> usize {
510    let n = tts.len();
511    let mut i = 0;
512    let separator = if macro_rules { TokenKind::Semi } else { TokenKind::Comma };
513    loop {
514        // We expect 3 token trees: `(LHS) => {RHS}`. The separator is checked after.
515        if i + 2 >= n
516            || !tts[i].is_delimited()
517            || !tts[i + 1].is_token(&TokenKind::FatArrow)
518            || !tts[i + 2].is_delimited()
519        {
520            break;
521        }
522        let lhs = &tts[i];
523        let rhs = &tts[i + 2];
524        let mut binders = Binders::default();
525        check_binders(psess, node_id, lhs, macros, &mut binders, &Stack::Empty, guar);
526        check_occurrences(psess, node_id, rhs, macros, &binders, &Stack::Empty, guar);
527        // Since the last semicolon is optional for `macro_rules` macros and decl_macro are not terminated,
528        // we increment our checked position by how many token trees we already checked (the 3
529        // above) before checking for the separator.
530        i += 3;
531        if i == n || !tts[i].is_token(&separator) {
532            break;
533        }
534        // We increment our checked position for the semicolon.
535        i += 1;
536    }
537    i
538}
539
540/// Checks that a meta-variable occurrence is valid.
541///
542/// Arguments:
543/// - `psess` is used to emit diagnostics and lints
544/// - `node_id` is used to emit lints
545/// - `macros` is the stack of possible outer macros
546/// - `binders` contains the binders of the associated LHS
547/// - `ops` is the stack of Kleene operators from the RHS
548/// - `span` is the span of the meta-variable to check
549/// - `name` is the name of the meta-variable to check
550fn check_ops_is_prefix(
551    psess: &ParseSess,
552    node_id: NodeId,
553    macros: &Stack<'_, MacroState<'_>>,
554    binders: &Binders,
555    ops: &Stack<'_, KleeneToken>,
556    span: Span,
557    name: MacroRulesNormalizedIdent,
558) {
559    let macros = macros.push(MacroState { binders, ops: ops.into() });
560    // Accumulates the stacks the operators of each state until (and including when) the
561    // meta-variable is found. The innermost stack is first.
562    let mut acc: SmallVec<[&SmallVec<[KleeneToken; 1]>; 1]> = SmallVec::new();
563    for state in &macros {
564        acc.push(&state.ops);
565        if let Some(binder) = state.binders.get(&name) {
566            // This variable concatenates the stack of operators from the RHS of the LHS where the
567            // meta-variable was defined to where it is used (in possibly nested macros). The
568            // outermost operator is first.
569            let mut occurrence_ops: SmallVec<[KleeneToken; 2]> = SmallVec::new();
570            // We need to iterate from the end to start with outermost stack.
571            for ops in acc.iter().rev() {
572                occurrence_ops.extend_from_slice(ops);
573            }
574            ops_is_prefix(psess, node_id, span, name, &binder.ops, &occurrence_ops);
575            return;
576        }
577    }
578    buffer_lint(psess, span.into(), node_id, BuiltinLintDiag::UnknownMacroVariable(name));
579}
580
581/// Returns whether `binder_ops` is a prefix of `occurrence_ops`.
582///
583/// The stack of Kleene operators of a meta-variable occurrence just needs to have the stack of
584/// Kleene operators of its binder as a prefix.
585///
586/// Consider $i in the following example:
587/// ```ignore (illustrative)
588/// ( $( $i:ident = $($j:ident),+ );* ) => { $($( $i += $j; )+)* }
589/// ```
590/// It occurs under the Kleene stack ["*", "+"] and is bound under ["*"] only.
591///
592/// Arguments:
593/// - `psess` is used to emit diagnostics and lints
594/// - `node_id` is used to emit lints
595/// - `span` is the span of the meta-variable being check
596/// - `name` is the name of the meta-variable being check
597/// - `binder_ops` is the stack of Kleene operators for the binder
598/// - `occurrence_ops` is the stack of Kleene operators for the occurrence
599fn ops_is_prefix(
600    psess: &ParseSess,
601    node_id: NodeId,
602    span: Span,
603    name: MacroRulesNormalizedIdent,
604    binder_ops: &[KleeneToken],
605    occurrence_ops: &[KleeneToken],
606) {
607    for (i, binder) in binder_ops.iter().enumerate() {
608        if i >= occurrence_ops.len() {
609            let mut span = MultiSpan::from_span(span);
610            span.push_span_label(binder.span, "expected repetition");
611            buffer_lint(psess, span, node_id, BuiltinLintDiag::MetaVariableStillRepeating(name));
612            return;
613        }
614        let occurrence = &occurrence_ops[i];
615        if occurrence.op != binder.op {
616            let mut span = MultiSpan::from_span(span);
617            span.push_span_label(binder.span, "expected repetition");
618            span.push_span_label(occurrence.span, "conflicting repetition");
619            buffer_lint(psess, span, node_id, BuiltinLintDiag::MetaVariableWrongOperator);
620            return;
621        }
622    }
623}
624
625fn buffer_lint(psess: &ParseSess, span: MultiSpan, node_id: NodeId, diag: BuiltinLintDiag) {
626    // Macros loaded from other crates have dummy node ids.
627    if node_id != DUMMY_NODE_ID {
628        psess.buffer_lint(META_VARIABLE_MISUSE, span, node_id, diag);
629    }
630}