Rust: reconstruct format-macro expansions on pre-1.94 toolchains - #22350
Draft
redsun82 wants to merge 1 commit into
Draft
Rust: reconstruct format-macro expansions on pre-1.94 toolchains#22350redsun82 wants to merge 1 commit into
redsun82 wants to merge 1 commit into
Conversation
redsun82
force-pushed
the
redsun82-format-macro-flow-recovery
branch
from
August 14, 2026 17:35
962c659 to
da97573
Compare
`rust-analyzer` 0.0.347 no longer expands the format-family macros (`format!`, `println!`, `write!`, `panic!`, ...) against a pre-1.94 std, so flow through them and the security-query sinks keyed on their callees were lost. Rebuild each macro's real expansion (a `FormatArgsExpr` wrapped in its callee) from the argument tokens so both keep working. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: 7492ff50-9c8e-47ef-a70d-f2623b702c8f
redsun82
force-pushed
the
redsun82-format-macro-flow-recovery
branch
from
August 14, 2026 17:38
da97573 to
7faf81f
Compare
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.
Stacked on #22346 (RA 0.0.347 upgrade). Review/merge that first; this PR targets its branch.
Problem
rust-analyzer0.0.347 only expands the builtinformat_args!machinery against a std that carries the new lowering (roughly Rust >= 1.94). On older toolchains the format-family macros (format!,println!,write!,panic!, ...) fail to expand, soexpand_macro_callreturnsNoneand we get a bare unexpandedMacroCall. That drops:FormatArgsExprnode), andprintln!/eprintln!/panic!(std::io::stdio::_print/_eprint,core::panicking::panic_fmt).Fix
The syntactic lowering of these macros is a pure, sysroot-independent transform, so the extractor rebuilds the same token tree the real (>=1.94) expansion has, parses it, and registers the result as the macro expansion.
The reconstruction is faithful per macro rather than a blanket bare
FormatArgsExpr, so the callee that carries flow and the sink models is preserved:format_args!,const_format_args!,format_args_nl!format_args!(..)format!::std::fmt::format(format_args!(..))print!,println!::std::io::_print(format_args!(..))eprint!,eprintln!::std::io::_eprint(format_args!(..))panic!::core::panicking::panic_fmt(format_args!(..))write!,writeln!<dst>.write_fmt(format_args!(..))format_args_nl!'s trailing newline is dropped: it is irrelevant to flow and to the sinks keyed on the callee.The synthesized-token construction lives in a new
translate/format_args.rsmodule;base.rskeeps only the orchestration (tokenize, reconstruct, parse, emit).Testing
New
library-tests/format-macros-legacy/test, pinned to a pre-1.94 (1.93) toolchain so it actually hits the reconstruction path the default1.95test toolchain never reaches:format!(InlineFlowTest),println!/eprintln!/print!/eprint!(LogInjection.qlref), confirming the sinks survive on<1.94,FormatArgsExprnode presence for the rest of the family.setup.shpre-installs the1.93toolchain so the parallel QL tests do not race onrustupauto-install.Notes
write!/writeln!writer buffer is not recovered, but that matches native>=1.94behavior (there is noWrite::write_fmtcontent-to-self taint model). It is a pre-existing model gap, not a regression from this change, and is left for a follow-up.