Skip to content

Conversation

@GuillaumeGomez
Copy link
Member

@GuillaumeGomez GuillaumeGomez commented Feb 9, 2026

Fixes #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

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue. T-rustdoc-frontend Relevant to the rustdoc-frontend team, which will review and decide on the web UI/UX output. labels Feb 9, 2026
@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@GuillaumeGomez
Copy link
Member Author

Finally made unit tests happy as well.

@lolbinarycat
Copy link
Contributor

macro_rules is only a weak keyword, meaning the following code is valid:

fn main() {
    let macro_rules = 3;
    dbg!(macro_rules != 3);
}

I don't think this is handled correctly.

@GuillaumeGomez
Copy link
Member Author

TIL, so yeah, fix is invalid.

@GuillaumeGomez
Copy link
Member Author

Hopefully it's good now.

@lolbinarycat
Copy link
Contributor

I think everything is handled correctly now, but I've found an even more absurd edge case, unsure if it's worthy of an additional test case.

macro_rules! r#macro_rules {
    () => {
        fn main() {
            println!("why can you do this.");
        }
    }
}

r#macro_rules!();

@GuillaumeGomez
Copy link
Member Author

I added a test for this case too. :)

@lolbinarycat
Copy link
Contributor

Thanks!

@bors r+ rollup

@rust-bors
Copy link
Contributor

rust-bors bot commented Feb 11, 2026

📌 Commit 5107af2 has been approved by lolbinarycat

It is now in the queue for this repository.

@rust-bors rust-bors bot added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Feb 11, 2026
Zalathar added a commit to Zalathar/rust that referenced this pull request Feb 12, 2026
…narycat

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

Fixes rust-lang#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
rust-bors bot pushed a commit that referenced this pull request Feb 12, 2026
Rollup of 17 pull requests

Successful merges:

 - #142415 (Add note when inherent impl for a alias type defined outside of the crate)
 - #142680 (Fix passing/returning structs with the 64-bit SPARC ABI)
 - #150768 (Don't compute FnAbi for LLVM intrinsics in backends)
 - #151152 (Add FCW for derive helper attributes that will conflict with built-in attributes)
 - #151814 (layout: handle rigid aliases without params)
 - #151863 (Borrowck: simplify diagnostics for placeholders)
 - #152159 (Add note for `?Sized` params in int-ptr casts diag)
 - #152434 (Clarify names of `QueryVTable` functions for "executing" a query)
 - #152478 (Remove tm_factory field from CodegenContext)
 - #152498 (Partially revert "resolve: Update `NameBindingData::vis` in place")
 - #152316 (fix: add continue)
 - #152394 (Correctly check if a macro call is actually a macro call in rustdoc highlighter)
 - #152425 (Port #![test_runner] to the attribute parser)
 - #152481 (Use cg_ssa's produce_final_output_artifacts in cg_clif)
 - #152485 (fix issue#152482)
 - #152495 (Clean up some subdiagnostics)
 - #152502 (Implement `BinaryHeap::from_raw_vec`)
@rust-bors rust-bors bot merged commit 4bc9024 into rust-lang:main Feb 12, 2026
11 checks passed
@GuillaumeGomez GuillaumeGomez deleted the macro-call branch February 12, 2026 10:12
rust-timer added a commit that referenced this pull request Feb 12, 2026
Rollup merge of #152394 - GuillaumeGomez:macro-call, r=lolbinarycat

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

Fixes #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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue. T-rustdoc-frontend Relevant to the rustdoc-frontend team, which will review and decide on the web UI/UX output.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Rustdoc syntax highlighting of ident != is displayed as a macro invocation ident!

4 participants