Rollup merge of #152394 - GuillaumeGomez:macro-call, r=lolbinarycat

Correctly check if a macro call is actually a macro call in rustdoc highlighter

Fixes rust-lang/rust#151904.

Issues was that if there was a `!` following an ident, we would always assume it's a macro call... except it's very lacking. I'm actually surprised it went for so long unnoticed. To fix it, I added a check for the next (non-blank) token after the `!`, if it's a `{` or a `[` or a `(`, then only do we consider it to be a macro call.

r? @lolbinarycat
This commit is contained in:
Jacob Pratt 2026-02-12 00:41:10 -05:00 committed by GitHub
commit 4bc90240e1
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 81 additions and 5 deletions

View file

@ -0,0 +1,18 @@
// This is yet another test to ensure that only macro calls are considered as such
// by the rustdoc highlighter, in particular when named `macro_rules`.
// This is a regression test for <https://github.com/rust-lang/rust/issues/151904>.
#![crate_name = "foo"]
//@ has src/foo/macro-call-2.rs.html
//@ count - '//code/span[@class="macro"]' 2
//@ has - '//code/span[@class="macro"]' 'macro_rules!'
//@ has - '//code/span[@class="macro"]' 'r#macro_rules!'
macro_rules! r#macro_rules {
() => {
fn main() {}
}
}
r#macro_rules!();

View file

@ -0,0 +1,29 @@
// This is yet another test to ensure that only macro calls are considered as such
// by the rustdoc highlighter.
// This is a regression test for <https://github.com/rust-lang/rust/issues/151904>.
#![crate_name = "foo"]
//@ has src/foo/macro-call.rs.html
//@ count - '//code/span[@class="macro"]' 2
//@ has - '//code/span[@class="macro"]' 'panic!'
//@ has - '//code/span[@class="macro"]' 'macro_rules!'
pub struct Layout;
impl Layout {
pub fn new<X: std::fmt::Debug>() {}
}
pub fn bar() {
let layout = Layout::new::<u32>();
if layout != Layout::new::<u32>() {
panic!();
}
let macro_rules = 3;
if macro_rules != 3 {}
}
macro_rules! blob {
() => {}
}