In our experimental CodeQL rust analysis we piggy-back on rust-analyzer analysis library, and specifically for macro calls we rely on ra_ap_hir::Semantics::expand_macro_call. While updating from rust-analyzer 0.0.273 to 0.0.274 we suddenly saw in the wild a significant number of cases of that function returning None. I managed to recreate a small reproduction crate of the 4 classes of unexpanded macros I saw so far. For 2 of them I also managed to reproduce the behaviour on the VSCode extension (that is, newer versions give no expansion with the Expand macro recursively at caret command, while an older one those. The crate can be accessed here. Here's the 4 cases I found:
- a macro call in an
impl block expanding to some items:
impl S {
def_x!(); // this doesn't expand since 0.0.274
}
(this does still expand in VSCode)
- 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)
- 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.
- 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.
I've seen some substantial changes in that area in the code, but I can't put my finger on what could be causing this. For us the most concerning instance is the first one, as it's not that uncommon.
Do you have any guidance on this?
rust-analyzer version: 0.0.274 (rust-analyzer as library from crates.io)
rustc version: 1.86
editor or extension: -
relevant settings: -
repository link (if public, optional): example crate
In our experimental CodeQL rust analysis we piggy-back on rust-analyzer analysis library, and specifically for macro calls we rely on
ra_ap_hir::Semantics::expand_macro_call. While updating from rust-analyzer 0.0.273 to 0.0.274 we suddenly saw in the wild a significant number of cases of that function returningNone. I managed to recreate a small reproduction crate of the 4 classes of unexpanded macros I saw so far. For 2 of them I also managed to reproduce the behaviour on the VSCode extension (that is, newer versions give no expansion with theExpand macro recursively at caretcommand, while an older one those. The crate can be accessed here. Here's the 4 cases I found:implblock expanding to some items:format!call (the original example wasanyhow!, I recreated it withalloc::__export::format_args!either before or after, but I'm guessing that might be on purpose asformat_args!is not really a macro. Still I was getting an expansion ofconcat!there in 0.0.273, but I'm getting none on 0.0.274)docattribute 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..rsfile that is included viainclude!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.I've seen some substantial changes in that area in the code, but I can't put my finger on what could be causing this. For us the most concerning instance is the first one, as it's not that uncommon.
Do you have any guidance on this?
rust-analyzer version: 0.0.274 (rust-analyzer as library from crates.io)
rustc version: 1.86
editor or extension: -
relevant settings: -
repository link (if public, optional): example crate