From cc3c5d2700481bae497d6cde825c1d48e79c776a Mon Sep 17 00:00:00 2001 From: est31 Date: Fri, 13 May 2022 08:42:39 +0200 Subject: [PATCH 1/2] Improve name and documentation of generic_extension This function doesn't *create* a (rules based) macro, it *expands* it. Thus, the documentation was wrong. --- compiler/rustc_expand/src/mbe/macro_rules.rs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/compiler/rustc_expand/src/mbe/macro_rules.rs b/compiler/rustc_expand/src/mbe/macro_rules.rs index ba0b35470b6ba..4cc3169180ea5 100644 --- a/compiler/rustc_expand/src/mbe/macro_rules.rs +++ b/compiler/rustc_expand/src/mbe/macro_rules.rs @@ -175,7 +175,7 @@ impl TTMacroExpander for MacroRulesMacroExpander { if !self.valid { return DummyResult::any(sp); } - generic_extension( + expand_macro( cx, sp, self.span, @@ -202,8 +202,9 @@ fn trace_macros_note(cx_expansions: &mut FxHashMap>, sp: Span, cx_expansions.entry(sp).or_default().push(message); } -/// Given `lhses` and `rhses`, this is the new macro we create -fn generic_extension<'cx, 'tt>( +/// Expands the rules based macro defined by `lhses` and `rhses` for a given +/// input `arg`. +fn expand_macro<'cx, 'tt>( cx: &'cx mut ExtCtxt<'_>, sp: Span, def_span: Span, From e6ccf9b5d8e56d08936cd77f1bb72abd5e2582ed Mon Sep 17 00:00:00 2001 From: est31 Date: Fri, 13 May 2022 08:48:35 +0200 Subject: [PATCH 2/2] Use pluralize in one instance --- compiler/rustc_expand/src/mbe/macro_parser.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/compiler/rustc_expand/src/mbe/macro_parser.rs b/compiler/rustc_expand/src/mbe/macro_parser.rs index 29f354d572802..ddfbef945efaa 100644 --- a/compiler/rustc_expand/src/mbe/macro_parser.rs +++ b/compiler/rustc_expand/src/mbe/macro_parser.rs @@ -76,6 +76,7 @@ crate use ParseResult::*; use crate::mbe::{KleeneOp, TokenTree}; use rustc_ast::token::{self, DocComment, Nonterminal, NonterminalKind, Token}; +use rustc_lint_defs::pluralize; use rustc_parse::parser::{NtOrTt, Parser}; use rustc_span::symbol::MacroRulesNormalizedIdent; use rustc_span::Span; @@ -668,8 +669,7 @@ impl TtParser { self.macro_name, match self.next_mps.len() { 0 => format!("built-in NTs {}.", nts), - 1 => format!("built-in NTs {} or 1 other option.", nts), - n => format!("built-in NTs {} or {} other options.", nts, n), + n => format!("built-in NTs {} or {n} other option{s}.", nts, s = pluralize!(n)), } ), )