Skip to content

Incorrect macro expansion with doubly nested macros #10125

Open
@jonas-schievink

Description

@jonas-schievink
macro_rules! outer {
    ($block:block) => {
        {
            macro_rules! with_dollar_sign {
                ($a:tt => $b:tt) => {
                    macro_rules! __with_dollar_sign { $a => $b }
                    __with_dollar_sign!($);
                }
            }

            with_dollar_sign! {
                ($d:tt) => {
                    macro_rules! inner {
                        ($blk:block) => {
                            $blk
                        };
                    }
                }
            }
            $block
        }
    };
}

fn main() {
    outer!({
        let s = String::new();
        s.len();
        inner!({
            s.len();
        });
    });
}

Hover does not work within the inner! invocation here.

According to "Expand macro recursively" we expand inner! just fine, but fail to expand __with_dollar_sign! to the definition of inner!, which makes no sense:

{
  macro_rules!with_dollar_sign {
    ($a:tt = > $b:tt) = >{
      macro_rules!__with_dollar_sign {
        $a = > $b
      }__with_dollar_sign!($);
      
    }
  }macro_rules!__with_dollar_sign {
    ($d:tt) = >{
      macro_rules!inner {
        ($blk:block) = >{
          $blk
        };
        
      }
    }
  }__with_dollar_sign!($);
  {
    let s = String::new();
    s.len();
    {
      s.len();
      
    };
    
  }
}

It is possible that that part is due to a bug in the implementation of "Expand macro recursively".

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-hygieneA-macromacro expansionS-actionableSomeone could pick this issue up and work on it right now

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions