Rollup merge of #97005 - est31:master, r=petrochenkov

Two small improvements of rustc_expand

I found them while doing #96150

r? ``@petrochenkov``
This commit is contained in:
Yuki Okushi 2022-05-14 13:42:53 +09:00 committed by GitHub
commit e6fc0c4b43
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 6 additions and 5 deletions

View File

@ -76,6 +76,7 @@ crate use ParseResult::*;
use crate::mbe::{KleeneOp, TokenTree}; use crate::mbe::{KleeneOp, TokenTree};
use rustc_ast::token::{self, DocComment, Nonterminal, NonterminalKind, Token}; use rustc_ast::token::{self, DocComment, Nonterminal, NonterminalKind, Token};
use rustc_lint_defs::pluralize;
use rustc_parse::parser::{NtOrTt, Parser}; use rustc_parse::parser::{NtOrTt, Parser};
use rustc_span::symbol::MacroRulesNormalizedIdent; use rustc_span::symbol::MacroRulesNormalizedIdent;
use rustc_span::Span; use rustc_span::Span;
@ -668,8 +669,7 @@ impl TtParser {
self.macro_name, self.macro_name,
match self.next_mps.len() { match self.next_mps.len() {
0 => format!("built-in NTs {}.", nts), 0 => format!("built-in NTs {}.", nts),
1 => format!("built-in NTs {} or 1 other option.", nts), n => format!("built-in NTs {} or {n} other option{s}.", nts, s = pluralize!(n)),
n => format!("built-in NTs {} or {} other options.", nts, n),
} }
), ),
) )

View File

@ -175,7 +175,7 @@ impl TTMacroExpander for MacroRulesMacroExpander {
if !self.valid { if !self.valid {
return DummyResult::any(sp); return DummyResult::any(sp);
} }
generic_extension( expand_macro(
cx, cx,
sp, sp,
self.span, self.span,
@ -202,8 +202,9 @@ fn trace_macros_note(cx_expansions: &mut FxHashMap<Span, Vec<String>>, sp: Span,
cx_expansions.entry(sp).or_default().push(message); cx_expansions.entry(sp).or_default().push(message);
} }
/// Given `lhses` and `rhses`, this is the new macro we create /// Expands the rules based macro defined by `lhses` and `rhses` for a given
fn generic_extension<'cx, 'tt>( /// input `arg`.
fn expand_macro<'cx, 'tt>(
cx: &'cx mut ExtCtxt<'_>, cx: &'cx mut ExtCtxt<'_>,
sp: Span, sp: Span,
def_span: Span, def_span: Span,