Reorder inline asm operands in pretty printer to satisfy grammar constraints#154088
Merged
rust-bors[bot] merged 2 commits intorust-lang:mainfrom Mar 26, 2026
Merged
Reorder inline asm operands in pretty printer to satisfy grammar constraints#154088rust-bors[bot] merged 2 commits intorust-lang:mainfrom
rust-bors[bot] merged 2 commits intorust-lang:mainfrom
Conversation
Collaborator
|
r? @davidtwco rustbot has assigned @davidtwco. Use Why was this reviewer chosen?The reviewer was selected based on:
|
1d98bca to
f2ef828
Compare
…traints
After macro expansion, named `asm!` operands are converted to positional
operands and the template string uses numeric indices. However, the pretty
printer previously emitted operands in their original AST order, which could
place positional (formerly named) register-class operands after explicit
register operands. This violates the `asm!` grammar rule that positional
arguments cannot follow explicit register arguments, causing the expanded
output from `rustc -Zunpretty=expanded` to fail to reparse.
When reordering is needed, the fix partitions operands into non-explicit and
explicit register groups, emits non-explicit operands first, then explicit
register operands, and remaps template placeholder indices (`{N}`) to match
the new positions. When operands are already correctly ordered, the original
code path is used unchanged.
Signed-off-by: Andrew V. Teylu <andrew.teylu@vector.com>
f2ef828 to
9975d47
Compare
…overage Extract the inline asm operand reorder/remap logic into a dedicated helper so `print_inline_asm` stays focused on assembling the printed argument list. This keeps the reordered-template logic local to the AST pretty printer while making the main printing path easier to read. Also extend the pretty regression test with a `const` operand case. That checks that non-register operands other than `in(reg)` are also moved ahead of explicit register operands and that the remapped template indices still match the new operand order. Signed-off-by: Andrew V. Teylu <andrew.teylu@vector.com>
davidtwco
approved these changes
Mar 26, 2026
Member
|
@bors r+ rollup |
Contributor
rust-bors Bot
pushed a commit
that referenced
this pull request
Mar 26, 2026
…uwer Rollup of 5 pull requests Successful merges: - #152757 (Add x86_64-unknown-linux-gnu{m,t}san target which enables {M,T}San by default) - #154354 (Add more tests for the parallel frontend) - #154088 (Reorder inline asm operands in pretty printer to satisfy grammar constraints) - #154407 (Link from `assert_matches` to `debug_assert_matches`) - #154420 (Use extended regex syntax)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
After macro expansion, named
asm!operands are converted to positional operands and the template string uses numeric indices. However, the pretty printer previously emitted operands in their original AST order, which could place positional (formerly named) register-class operands after explicit register operands. This violates theasm!grammar rule that positional arguments cannot follow explicit register arguments, causing the expanded output fromrustc -Zunpretty=expandedto fail to reparse.When reordering is needed, the fix partitions operands into non-explicit and explicit register groups, emits non-explicit operands first, then explicit register operands, and remaps template placeholder indices (
{N}) to match the new positions. When operands are already correctly ordered, the original code path is used unchanged.Example
before (
rustc 1.96.0-nightly (3b1b0ef4d 2026-03-11)):after (this branch):
Notice the operand reordering: in the before, explicit register operands (
out("rax")) appear before positional operands (in(reg)), violating the grammar (E0662). The template references are also wrong ({1}instead of{0}). The after moves positional operands first and renumbers the template references accordingly.