Rust: Update rust-analyzer to 0.0.347 and pin toolchain - #22493
Rust: Update rust-analyzer to 0.0.347 and pin toolchain#22493paldepind wants to merge 62 commits into
Conversation
Update hand-written library predicates for the 0.0.347 AST changes: - FormatArgsArg.getArgName() -> getName() (the arg name is now a Name, carrying text, instead of the text-less FormatArgsArgName placeholder). - Visibility.getPath()/hasPath() -> getVisibilityInner().getPath(); the path now hangs off an intermediate VisibilityInner node. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: 890cb55d-0437-4bd7-9268-87b8897ada01
The ra_ap 0.0.347 builtin format_args! expander needs a newer std than 0.0.328, so the QL test toolchain is bumped to 1.97 (matching the root dev toolchain). Generated extractor-test expectations are regenerated for the new schema fields (asm attrs, Trait impl_restriction, Struct/TupleField mut_restriction, Visibility visibility_inner, FormatArgsArg name) and for the std sysroot dependency churn that comes with the newer toolchain. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: 890cb55d-0437-4bd7-9268-87b8897ada01
The schema delta for ra_ap 0.0.347 adds the new node kinds DerefPat, ImplRestriction, IncludeBytesExpr, MutRestriction, NotNull, PatternTypeRepr and VisibilityInner, moves a Visibility path onto the new VisibilityInner, replaces the text-less FormatArgsArgName placeholder with a Name, and adds attrs to the inline assembly nodes, mut_restriction to Struct/TupleField and impl_restriction to Trait. The upgrade repurposes the old format-arg placeholder ids as Name ids (avoiding dangling refs) and synthesises a VisibilityInner per visibility with a path. The downgrade rejoins the visibility path, repurposes ids back to the placeholder, and scrubs the locations of the deleted node kinds. compatibility is partial: the new node kinds are empty on old DBs, so a rebuild yields strictly-better results while existing queries keep working. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: 890cb55d-0437-4bd7-9268-87b8897ada01
Regenerate the Rust translator so codegen emits the current Translator<'_> impl signature. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: 890cb55d-0437-4bd7-9268-87b8897ada01 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Rust 1.97 reports redundant formatting borrows and map iteration warnings under -D warnings. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: 890cb55d-0437-4bd7-9268-87b8897ada01 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
A full new->old->new dataset upgrade/downgrade round-trip surfaced dangling references: deleting the new node kinds left `macro_call_macro_call_expansions` rows (and potentially `comments` rows) pointing at now-undefined `@ast_node`s. These are the only two relations with a generic `@ast_node`-typed value column, so the downgrade now drops rows in both that reference a deleted node, alongside the existing `locatable_locations` scrub. `codeql dataset check` is now clean at every stage of the round-trip. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: 890cb55d-0437-4bd7-9268-87b8897ada01
The template emitted `impl Translator<'_>` (one lifetime) while `base.rs` declares `Translator<'a, 'db>`, so regenerating produced a `generated.rs` that did not compile. Update the template to two lifetimes and regenerate. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: 890cb55d-0437-4bd7-9268-87b8897ada01
The `rules_rust` 0.69 -> 0.73 bump changes the vendored file format and repo layout, invalidating the previously vendored files. Regenerate them all via the umbrella `update_cargo_deps.sh` (py_deps + tree_sitter_extractors_deps). Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: 890cb55d-0437-4bd7-9268-87b8897ada01
`rules_rust` 0.73 vendors crates as subpackages of a single `@vendor_ts` repo (a per-crate alias) rather than one repo per crate. `rust.ungram` is only exported from the crate's own vendored repo, so derive that repo from the crate label instead of assuming the crate sits at a repo root. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: 890cb55d-0437-4bd7-9268-87b8897ada01
Add QLDoc annotations for the AST nodes introduced by ra_ap 0.0.347 (`DerefPat`, `ImplRestriction`, `IncludeBytesExpr`, `MutRestriction`, `NotNull`, `PatternTypeRepr`, `VisibilityInner`). `DerefPat`, `IncludeBytesExpr` and `NotNull` keep `cfg=True` so annotating them does not drop their CFG nodes. The example snippets double as generated extractor tests. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: 890cb55d-0437-4bd7-9268-87b8897ada01
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: 890cb55d-0437-4bd7-9268-87b8897ada01
…ernTypeRepr` These nodes represent experimental, mostly compiler-internal Rust features that cannot be written directly in stable Rust. The docs now say so and note that the examples use rust-analyzer's canonical `builtin#` syntax. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: 890cb55d-0437-4bd7-9268-87b8897ada01
The new nightly toolchain rejects let-chains in edition 2021 and enables deny-by-default lints (e.g. `dangerous_implicit_autorefs`) that fail extraction of valid test sources. Add a `qltest_edition` option so individual tests can opt into a newer edition, and pass `--cap-lints=allow` to the qltest cargo check. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: 890cb55d-0437-4bd7-9268-87b8897ada01
Use edition 2024 for the let-chain fixtures (`dataflow/local`, `variables`, `unusedentities`). Drop stale `MISSING` markers in `type-inference` where the new inference now resolves the types, and mark the `System` `alloc`/`alloc_zeroed`/`realloc` alerts in CWE-770 as `MISSING` since rust-analyzer 0.0.347 no longer resolves those `GlobalAlloc` sinks. The regression is called out with inline comments in the fixture. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: 890cb55d-0437-4bd7-9268-87b8897ada01
Resolve MODULE.bazel conflict: keep `rules_rust` 0.73.0 (this branch) and `rules_swift` 4.0.0-rc5-codeql.1 plus the `apple_support` removal (main). Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: 890cb55d-0437-4bd7-9268-87b8897ada01
1.96 turned `use SomeStruct::{self};` into a hard error (E0432), which broke
the path-resolution test. 1.95 is the newest stable that still accepts it while
also expanding the builtin `format_args!` macro against std. Re-accept the
std-snapshot and format-arg/panic expansion changes that follow from the
ra_ap 0.0.347 upgrade at this toolchain.
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 890cb55d-0437-4bd7-9268-87b8897ada01
The new `DerefPat` node from ra_ap 0.0.347 had no case in the pattern CFG builder, leaving the enclosing function's CFG disconnected and tripping `CfgConsistency` (a `deadEnd`). Wire it like `BoxPat`, since it wraps a single inner pattern via `getPat()`. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: 890cb55d-0437-4bd7-9268-87b8897ada01
`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
…very Rust: reconstruct format-macro expansions on pre-1.94 toolchains
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: 890cb55d-0437-4bd7-9268-87b8897ada01
Regenerate CWE-770 UncontrolledAllocationSize.expected against the merged dataflow library (alert source/sink nodes relabelled upstream); inline expectations unchanged. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: 890cb55d-0437-4bd7-9268-87b8897ada01
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: 890cb55d-0437-4bd7-9268-87b8897ada01
The `System.alloc`/`alloc_zeroed`/`realloc` sinks stopped matching because the standard library made `GlobalAlloc` a legacy trait blanket-implemented for `GlobalAllocator` types. These calls now resolve to the blanket-impl methods, which have no canonical path, so the `GlobalAlloc::*` sink models miss them. This is a QL/model matching gap, not a rust-analyzer resolution failure.
02d17ca to
04d40b2
Compare
27ec762 to
aed695e
Compare
|
There is a large increase in extraction warnings for |
That's covered in a recent edit to the PR description :) |
There was a problem hiding this comment.
Copilot review overview
🟡 Changes recommended
Fixed toolchain selection bypasses the legacy test pins, while unresolved qualified macros can receive fabricated standard-library expansions.
Once you've addressed the issues Copilot identified, you can request another Copilot review.
Review tier: Balanced
Findings: 1
New issues introduced by this change (8)
| Severity | Finding |
|---|---|
rust/extractor/src/translate/base.rs — Only the final path segment is checked, so an unresolved qualified macro such as… |
|
rust/extractor/src/config.rs — This unconditional override makes every stable test-local toolchain ineffective. The new… |
|
rust/extractor/src/translate/format_args.rs — The new panic reconstruction is not exercised by the pre-1.94 fixture, even though it has a… |
|
rust/ql/lib/codeql/rust/frameworks/stdlib/core.model.yml — The companion legacy format-macro test covers write_fmt, write_str, and core::fmt::write, but… |
|
rust/extractor/src/toolchain.rs — Remove the duplicated “not”. |
|
rust/extractor/src/toolchain.rs — Correct “know” to “known”. |
|
rust/extractor/src/toolchain.rs — Correct the spelling of “precedes”. |
|
rust/extractor/src/toolchain.rs — This function has no dir argument and resolves the toolchain from the process working directory,… |
What changed in this PR
Finalizes the Rust analyzer 0.0.347 upgrade, including schema compatibility, toolchain pinning, and legacy format-macro extraction.
Changes:
- Updates Rust dependencies, toolchains, and vendored Bazel metadata.
- Adapts extractor and QL libraries to the revised AST schema.
- Adds pre-1.94 format-macro reconstruction, flow models, migrations, and tests.
| File | Description |
|---|---|
MODULE.bazel, rust-toolchain.toml |
Update build toolchains and rules. |
rust/extractor/** |
Update rust-analyzer integration, toolchain selection, and macro reconstruction. |
rust/schema/** |
Define the updated Rust AST schema. |
rust/ast-generator/** |
Update schema generation dependencies and Bazel wiring. |
rust/ql/lib/codeql/rust/elements/** |
Regenerate and expose revised AST classes. |
rust/ql/lib/codeql/rust/internal/** |
Adapt definitions and path resolution. |
rust/ql/lib/codeql/rust/controlflow/** |
Add dereference-pattern CFG handling. |
rust/ql/lib/codeql/rust/frameworks/stdlib/core.model.yml |
Model formatted writer flows. |
rust/ql/lib/upgrades/**, rust/downgrades/** |
Provide schema migration recipes. |
rust/ql/lib/change-notes/** |
Document analysis and API changes. |
rust/ql/test/** |
Update toolchains, fixtures, options, and expectations. |
rust/ql/integration-tests/conftest.py |
Preinstall the fixed integration-test toolchain. |
rust/README.md |
Document dependency regeneration steps. |
shared/**, ruby/extractor/Cargo.toml, unified/extractor/Cargo.toml |
Refresh shared Rust dependencies and compatibility edits. |
misc/bazel/3rdparty/** |
Regenerate vendored Cargo and Python Bazel aliases. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Install the fixed toolchain used by the extractor before parallel integration and QL tests start. This avoids concurrent rustup auto-installation races.
aed695e to
de23906
Compare
de23906 to
f4147b7
Compare
Rerun has been triggered: 2 restarted 🚀 |
|
This is ready for re-review. I've also started a new QA run, as the old one showed alert differences that I could not reproduce locally (maybe because the nightly selected for baseline had changes that where in |



This PR builds on top of #22346 to finalize the rust-analyzer update. The commits lifted over from #22346 can be considered already reviewed.
This PR adresses backwards compatibility issues in rust-analyzer by pinning to a specific Rust toolchain version that rust-analyzer is know to work with. I think it's important to have the rationale for this decision documented in code, so that's done in the
toolchain.rsmodule. Starting the review with that file is advised.DCA
The DCA report for this PR is much improved compared to the DCA report for #22346.
The number of extraction warnings went from almost doubling to a 15% increase. The largest increase in extraction warnings are for Databend and Rendiation. In both cases the versions on DCA use an old nightly toolchain and the breakage is due to the new rust-analyzer not being compatible with toolchains of that age. This is not something we can easily fix, and I don't think ancient nightly toolchains are something we should focus our efforts on.
Missing call targets and unknown types went dramatically up for Diem. However, extraction errors shrank from 1599 to 18 and calls with a call target increased. So it seems that we're just extracting more code overall. Copilot claims that it's because we're now able to extract more macros.
In conclusion, if adjusting for these outliers, the numbers seem perfectly fine.
Follow up work
There's some cleanup we should do related to this. For instance, some of the backwards compatibility workarounds should no longer be needed and we should adjust the rust-analyzer update documentation. However, I'd prefer to do that follow up, in the interest of getting this (already large change) merged.