From df6ead557d6c1f2ec87793d95b8a8bc9453e0f66 Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Fri, 25 Mar 2022 15:32:34 +1100 Subject: [PATCH] Add a useful assertion. --- compiler/rustc_expand/src/mbe/macro_parser.rs | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/compiler/rustc_expand/src/mbe/macro_parser.rs b/compiler/rustc_expand/src/mbe/macro_parser.rs index 5a6a2b2c57b9..69da3f232a0b 100644 --- a/compiler/rustc_expand/src/mbe/macro_parser.rs +++ b/compiler/rustc_expand/src/mbe/macro_parser.rs @@ -588,8 +588,13 @@ impl<'tt> TtParser<'tt> { if *token == token::Eof { Some(match eof_items { EofItems::One(mut eof_item) => { - let matches = - eof_item.matches.iter_mut().map(|dv| Lrc::make_mut(dv).pop().unwrap()); + let matches = eof_item.matches.iter_mut().map(|dv| { + // Top-level metavars only ever get one match. (Sub-matchers can get + // multiple matches, which get aggregated into a `MatcherSeq` before being + // put into the top-level.) + debug_assert_eq!(dv.len(), 1); + Lrc::make_mut(dv).pop().unwrap() + }); nameize(sess, ms, matches) } EofItems::Multiple => {