Skip to content

Commit 423b316

Browse files
authored
Rollup merge of #94884 - c410-f3r:meta-take-2, r=petrochenkov
Fix remaining meta-variable expression TODOs As promised on #93545. cc #83527 cc `@mark-i-m` cc `@petrochenkov`
2 parents 6548a36 + 5d333c1 commit 423b316

File tree

4 files changed

+16
-9
lines changed

4 files changed

+16
-9
lines changed

compiler/rustc_expand/src/mbe/macro_check.rs

+6-2
Original file line numberDiff line numberDiff line change
@@ -337,8 +337,12 @@ fn check_occurrences(
337337
let name = MacroRulesNormalizedIdent::new(name);
338338
check_ops_is_prefix(sess, node_id, macros, binders, ops, span, name);
339339
}
340-
// FIXME(c410-f3r) Check token (https://github.com/rust-lang/rust/issues/93902)
341-
TokenTree::MetaVarExpr(..) => {}
340+
TokenTree::MetaVarExpr(dl, ref mve) => {
341+
let Some(name) = mve.ident().map(MacroRulesNormalizedIdent::new) else {
342+
return;
343+
};
344+
check_ops_is_prefix(sess, node_id, macros, binders, ops, dl.entire(), name);
345+
}
342346
TokenTree::Delimited(_, ref del) => {
343347
check_nested_occurrences(sess, node_id, &del.tts, macros, binders, ops, valid);
344348
}

compiler/rustc_expand/src/mbe/macro_parser.rs

+5-2
Original file line numberDiff line numberDiff line change
@@ -324,8 +324,11 @@ pub(super) fn count_names(ms: &[TokenTree]) -> usize {
324324
TokenTree::Delimited(_, ref delim) => count_names(&delim.tts),
325325
TokenTree::MetaVar(..) => 0,
326326
TokenTree::MetaVarDecl(..) => 1,
327-
// FIXME(c410-f3r) MetaVarExpr should be handled instead of being ignored
328-
// https://github.com/rust-lang/rust/issues/9390
327+
// Panicking here would abort execution because `parse_tree` makes use of this
328+
// function. In other words, RHS meta-variable expressions eventually end-up here.
329+
//
330+
// `0` is still returned to inform that no meta-variable was found. `Meta-variables
331+
// != Meta-variable expressions`
329332
TokenTree::MetaVarExpr(..) => 0,
330333
TokenTree::Sequence(_, ref seq) => seq.num_captures,
331334
TokenTree::Token(..) => 0,

compiler/rustc_expand/src/mbe/metavar_expr.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,9 @@ impl MetaVarExpr {
6262
Ok(rslt)
6363
}
6464

65-
crate fn ident(&self) -> Option<&Ident> {
66-
match self {
67-
MetaVarExpr::Count(ident, _) | MetaVarExpr::Ignore(ident) => Some(&ident),
65+
crate fn ident(&self) -> Option<Ident> {
66+
match *self {
67+
MetaVarExpr::Count(ident, _) | MetaVarExpr::Ignore(ident) => Some(ident),
6868
MetaVarExpr::Index(..) | MetaVarExpr::Length(..) => None,
6969
}
7070
}

compiler/rustc_expand/src/mbe/transcribe.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -399,7 +399,7 @@ fn lockstep_iter_size(
399399
TokenTree::MetaVarExpr(_, ref expr) => {
400400
let default_rslt = LockstepIterSize::Unconstrained;
401401
let Some(ident) = expr.ident() else { return default_rslt; };
402-
let name = MacroRulesNormalizedIdent::new(ident.clone());
402+
let name = MacroRulesNormalizedIdent::new(ident);
403403
match lookup_cur_matched(name, interpolations, repeats) {
404404
Some(MatchedSeq(ref ads)) => {
405405
default_rslt.with(LockstepIterSize::Constraint(ads.len(), name))
@@ -479,7 +479,7 @@ fn count_repetitions<'a>(
479479
count(cx, 0, depth_opt, matched, sp)
480480
}
481481

482-
/// Returns a `NamedMatch` item declared on the RHS given an arbitrary [Ident]
482+
/// Returns a `NamedMatch` item declared on the LHS given an arbitrary [Ident]
483483
fn matched_from_ident<'ctx, 'interp, 'rslt>(
484484
cx: &ExtCtxt<'ctx>,
485485
ident: Ident,

0 commit comments

Comments
 (0)