Skip to content

Commit 87cd178

Browse files
committed
mbe: Factor out a helper to check an LHS
This currently gets called only once, but will get called multiple times when handling attributes.
1 parent 8d5eb6b commit 87cd178

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

compiler/rustc_expand/src/mbe/macro_rules.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -397,8 +397,7 @@ pub fn compile_declarative_macro(
397397
let lhs_tt = parse_one_tt(lhs_tt, RulePart::Pattern, sess, node_id, features, edition);
398398
// We don't handle errors here, the driver will abort after parsing/expansion. We can
399399
// report every error in every macro this way.
400-
check_emission(check_lhs_nt_follows(sess, node_id, &lhs_tt));
401-
check_emission(check_lhs_no_empty_seq(sess, slice::from_ref(&lhs_tt)));
400+
check_emission(check_lhs(sess, node_id, &lhs_tt));
402401
if let Err(e) = p.expect(exp!(FatArrow)) {
403402
return dummy_syn_ext(e.emit());
404403
}
@@ -454,6 +453,12 @@ pub fn compile_declarative_macro(
454453
(mk_syn_ext(expander), nrules)
455454
}
456455

456+
fn check_lhs(sess: &Session, node_id: NodeId, lhs: &mbe::TokenTree) -> Result<(), ErrorGuaranteed> {
457+
let e1 = check_lhs_nt_follows(sess, node_id, lhs);
458+
let e2 = check_lhs_no_empty_seq(sess, slice::from_ref(lhs));
459+
e1.and(e2)
460+
}
461+
457462
fn check_lhs_nt_follows(
458463
sess: &Session,
459464
node_id: NodeId,

0 commit comments

Comments
 (0)