@@ -267,6 +267,9 @@ pub fn is_macro_rule_match<'db>(
267267/// Helper function for [expand_macro_rule].
268268/// Traverses the macro expansion and replaces the placeholders with the provided values,
269269/// while collecting the result in `res_buffer`.
270+ /// Returns `Some(true)` if the match succeeded and some input was consumed,
271+ /// `Some(false)` if the match succeeded but no input was consumed (empty match),
272+ /// and `None` if the match failed.
270273fn is_macro_rule_match_ex < ' db > (
271274 db : & ' db dyn Database ,
272275 matcher_elements : ast:: MacroElements < ' db > ,
@@ -275,10 +278,12 @@ fn is_macro_rule_match_ex<'db>(
275278 > ,
276279 ctx : & mut MatcherContext < ' db > ,
277280 consume_all_input : bool ,
278- ) -> Option < ( ) > {
281+ ) -> Option < bool > {
282+ let mut advanced = false ;
279283 for matcher_element in matcher_elements. elements ( db) {
280284 match matcher_element {
281285 ast:: MacroElement :: Token ( matcher_token) => {
286+ advanced = true ;
282287 let input_token = input_iter. next ( ) ?;
283288 match input_token {
284289 ast:: TokenTree :: Token ( token_tree_leaf) => {
@@ -296,6 +301,7 @@ fn is_macro_rule_match_ex<'db>(
296301 }
297302 }
298303 ast:: MacroElement :: Param ( param) => {
304+ advanced = true ;
299305 let placeholder_kind: PlaceholderKind =
300306 if let ast:: OptionParamKind :: ParamKind ( param_kind) = param. kind ( db) {
301307 param_kind. kind ( db) . into ( )
@@ -370,6 +376,7 @@ fn is_macro_rule_match_ex<'db>(
370376 }
371377 }
372378 ast:: MacroElement :: Subtree ( matcher_subtree) => {
379+ advanced = true ;
373380 let input_token = input_iter. next ( ) ?;
374381 if let ast:: TokenTree :: Subtree ( input_subtree) = input_token {
375382 let inner_elements = get_macro_elements ( db, matcher_subtree. subtree ( db) ) ;
@@ -404,17 +411,16 @@ fn is_macro_rule_match_ex<'db>(
404411 loop {
405412 let mut inner_ctx = ctx. clone ( ) ;
406413 let mut temp_iter = input_iter. clone ( ) ;
407- if is_macro_rule_match_ex (
414+ let Some ( true ) = is_macro_rule_match_ex (
408415 db,
409416 elements. clone ( ) ,
410417 & mut temp_iter,
411418 & mut inner_ctx,
412419 false ,
413- )
414- . is_none ( )
415- {
420+ ) else {
416421 break ;
417- }
422+ } ;
423+ advanced = true ;
418424 * ctx = inner_ctx;
419425 * input_iter = temp_iter;
420426 match_count += 1 ;
@@ -449,7 +455,7 @@ fn is_macro_rule_match_ex<'db>(
449455 if consume_all_input && input_iter. next ( ) . is_some ( ) {
450456 return None ;
451457 }
452- Some ( ( ) )
458+ Some ( advanced )
453459}
454460
455461fn validate_repetition_operator_constraints ( ctx : & MatcherContext < ' _ > ) -> bool {
0 commit comments