From 551cb9f1f4fa315639033e3db39794e10a14b7f7 Mon Sep 17 00:00:00 2001 From: Josh Triplett Date: Tue, 22 Jul 2025 00:32:59 -0700 Subject: mbe: Use concrete type for `get_unused_rule` Rather than adding `get_unused_rule` to the `TTMacroExpander` trait, put it on the concrete `MacroRulesMacroExpander`, and downcast to that type via `Any` in order to call it. Suggested-by: Vadim Petrochenkov --- compiler/rustc_expand/src/base.rs | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) (limited to 'compiler/rustc_expand/src/base.rs') diff --git a/compiler/rustc_expand/src/base.rs b/compiler/rustc_expand/src/base.rs index 1928cfd9048..25ec5401111 100644 --- a/compiler/rustc_expand/src/base.rs +++ b/compiler/rustc_expand/src/base.rs @@ -1,3 +1,4 @@ +use std::any::Any; use std::default::Default; use std::iter; use std::path::Component::Prefix; @@ -361,17 +362,13 @@ where } /// Represents a thing that maps token trees to Macro Results -pub trait TTMacroExpander { +pub trait TTMacroExpander: Any { fn expand<'cx>( &self, ecx: &'cx mut ExtCtxt<'_>, span: Span, input: TokenStream, ) -> MacroExpanderResult<'cx>; - - fn get_unused_rule(&self, _rule_i: usize) -> Option<(&Ident, Span)> { - None - } } pub type MacroExpanderResult<'cx> = ExpandResult, ()>; @@ -379,7 +376,7 @@ pub type MacroExpanderResult<'cx> = ExpandResult, ()>; pub type MacroExpanderFn = for<'cx> fn(&'cx mut ExtCtxt<'_>, Span, TokenStream) -> MacroExpanderResult<'cx>; -impl TTMacroExpander for F +impl TTMacroExpander for F where F: for<'cx> Fn(&'cx mut ExtCtxt<'_>, Span, TokenStream) -> MacroExpanderResult<'cx>, { -- cgit 1.4.1-3-g733a5