Skip to content

Commit 5c6db7b

Browse files
committed
mbe: Fold calls to check_meta_variables into the parser loop
1 parent 01f38b4 commit 5c6db7b

File tree

2 files changed

+8
-18
lines changed

2 files changed

+8
-18
lines changed

compiler/rustc_expand/src/mbe/macro_check.rs

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -105,8 +105,6 @@
105105
//! stored when entering a macro definition starting from the state in which the meta-variable is
106106
//! bound.
107107
108-
use std::iter;
109-
110108
use rustc_ast::token::{Delimiter, IdentIsRaw, Token, TokenKind};
111109
use rustc_ast::{DUMMY_NODE_ID, NodeId};
112110
use rustc_data_structures::fx::FxHashMap;
@@ -192,29 +190,22 @@ struct MacroState<'a> {
192190
ops: SmallVec<[KleeneToken; 1]>,
193191
}
194192

195-
/// Checks that meta-variables are used correctly in a macro definition.
193+
/// Checks that meta-variables are used correctly in one rule of a macro definition.
196194
///
197195
/// Arguments:
198196
/// - `psess` is used to emit diagnostics and lints
199197
/// - `node_id` is used to emit lints
200-
/// - `span` is used when no spans are available
201-
/// - `lhses` and `rhses` should have the same length and represent the macro definition
198+
/// - `lhs` and `rhs` represent the rule
202199
pub(super) fn check_meta_variables(
203200
psess: &ParseSess,
204201
node_id: NodeId,
205-
span: Span,
206-
lhses: &[TokenTree],
207-
rhses: &[TokenTree],
202+
lhs: &TokenTree,
203+
rhs: &TokenTree,
208204
) -> Result<(), ErrorGuaranteed> {
209-
if lhses.len() != rhses.len() {
210-
psess.dcx().span_bug(span, "length mismatch between LHSes and RHSes")
211-
}
212205
let mut guar = None;
213-
for (lhs, rhs) in iter::zip(lhses, rhses) {
214-
let mut binders = Binders::default();
215-
check_binders(psess, node_id, lhs, &Stack::Empty, &mut binders, &Stack::Empty, &mut guar);
216-
check_occurrences(psess, node_id, rhs, &Stack::Empty, &binders, &Stack::Empty, &mut guar);
217-
}
206+
let mut binders = Binders::default();
207+
check_binders(psess, node_id, lhs, &Stack::Empty, &mut binders, &Stack::Empty, &mut guar);
208+
check_occurrences(psess, node_id, rhs, &Stack::Empty, &binders, &Stack::Empty, &mut guar);
218209
guar.map_or(Ok(()), Err)
219210
}
220211

compiler/rustc_expand/src/mbe/macro_rules.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -423,6 +423,7 @@ pub fn compile_declarative_macro(
423423
.pop()
424424
.unwrap();
425425
check_emission(check_rhs(sess, &rhs_tt));
426+
check_emission(macro_check::check_meta_variables(&sess.psess, node_id, &lhs_tt, &rhs_tt));
426427
lhses.push(lhs_tt);
427428
rhses.push(rhs_tt);
428429
if p.token == token::Eof {
@@ -438,8 +439,6 @@ pub fn compile_declarative_macro(
438439
return dummy_syn_ext(guar);
439440
}
440441

441-
check_emission(macro_check::check_meta_variables(&sess.psess, node_id, span, &lhses, &rhses));
442-
443442
let transparency = find_attr!(attrs, AttributeKind::MacroTransparency(x) => *x)
444443
.unwrap_or(Transparency::fallback(macro_rules));
445444

0 commit comments

Comments
 (0)