Skip to content

Semantics::expand_macro_call still returns None on some macro calls #19931

Open
@redsun82

Description

@redsun82

After #19873 was closed and a new release rolled out, I went and tested the fix, but found out that only one case was fixed, and in the meantime, I found another case of the same problem. So, picking up the list again from #19873 (I could not reopen it):

  1. a macro call in an impl block expanding to some items: fixed 👍
  2. very specifically, a macro call providing a format specifier for a macro that expands to a format! call (the original example was anyhow!, I recreated it with
    macro_rules! my_macro {
        ($head:expr, $($tail:tt)*) => { format!($head, $($tail)*) };
    }
    
    
    fn test() {
        _ = my_macro!(
            concat!("<", "{}", ">"),  // this doesn't expand since 0.0.274
            "hi",
        );
    }
    (VSCode does not expand further than alloc::__export::format_args! either before or after, but I'm guessing that might be on purpose as format_args! is not really a macro. Still I was getting an expansion of concat! there in 0.0.273, but I'm getting none on 0.0.274) Still seeing this
  3. a macro call in a doc attribute like #[doc = include_str!("README.md")]. This one I can confirm that previous versions of VSCode were able to expand, but now I get no expansion. I understand this is not meant to be supported, and I'm ok with it 👍
  4. a macro call in a .rs file that is included via include! rather than via a normal module item (and apparently that has been done in the wild even for non-generated files). Again when going to the included file with VSCode, the macros can be expanded on older plugin versions, but can't any more on newer ones. Still seeing this
  5. a macro call expanding in a type context
     macro_rules! my_int {
         () => { i32 };
     }
     
     fn answer() -> my_int!() {  // this doesn't expand since 0.0.274
         42
     }
    This also shows up in the IDE. This is newly discovered

I've updated the example crate with the above information.

Thanks for fixing case 1, which was by far the most worrying one. Case 5 though seems also something that could bite us.

rust-analyzer version: 0.0.285 (rust-analyzer as library from crates.io)
rustc version: 1.86
editor or extension: -
relevant settings: -
repository link (if public, optional): example crate

cc @Veykril

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-macromacro expansionC-bugCategory: bug

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions