Skip to content

Rust: update rust-analyzer to 0.0.347 - #22346

Open
redsun82 wants to merge 22 commits into
mainfrom
redsun82-rust-analyzer-update
Open

Rust: update rust-analyzer to 0.0.347#22346
redsun82 wants to merge 22 commits into
mainfrom
redsun82-rust-analyzer-update

Conversation

@redsun82

@redsun82 redsun82 commented Aug 14, 2026

Copy link
Copy Markdown
Contributor

Updates the Rust extractor's rust-analyzer (ra_ap_*) dependencies from 0.0.328 to 0.0.347, following rust/README.md → "Updating rust-analyzer".

What's in here

  • Cargo: cargo upgrade --incompatible --pinned; all ra_ap_* crates landed on 0.0.347.
  • Bazel: regenerated vendored cargo dependencies.
  • Codegen: bazel run //rust/codegen. rust/schema/ast.py changed, so this also includes the schema/library follow-up below.
  • Toolchain: bumped to nightly/2026-07-15 and rules_rust 0.73.0 in MODULE.bazel (with regenerated sha256s); root rust-toolchain.toml to 1.97.
  • Extractor: adapted to the 0.0.347 API.
  • QL library: adapted to the new AST schema (Visibility path now via VisibilityInner, FormatArgsArg.getName() returns a Name, etc.).
  • DB upgrade/downgrade scripts + change note for the schema delta.
  • Test toolchain bumped to 1.97 and generated extractor-test expectations regenerated.

Schema delta (0.0.328 → 0.0.347)

  • New node kinds: DerefPat, ImplRestriction, IncludeBytesExpr, MutRestriction, NotNull, PatternTypeRepr, VisibilityInner.
  • FormatArgsArgName removed in favour of FormatArgsArg.getName() (now a Name carrying the identifier text — the old placeholder was text-less, so this is strictly more information).
  • Visibility.getPath() moved onto the new VisibilityInner (Visibility.getVisibilityInner()).
  • New fields: attrs on the inline-assembly nodes, getMutRestriction() on StructField/TupleField, getImplRestriction() on Trait.

The upgrade/downgrade scripts are compatibility: partial: the new node kinds are empty on databases built with the old extractor, so a rebuild yields strictly-better results while existing queries keep working.

Testing

Extractor + QL tests. Local codeql test run over rust/ql/test/extractor-tests/: 312 passed; the 10 .expected updates in this PR are the benign consequences of the new schema fields plus the std-sysroot dependency churn from the newer toolchain (no logic regressions). All 27 nightly qltests pass with zero failure rows in every changed .expected.

DB upgrade/downgrade round-trip. Validated the schema-migration scripts end to end on a real database, not just by inspection. Built a Rust DB exercising the affected relations (pub(crate) visibility paths, named format args, struct fields) and ran the full new → downgrade → old → upgrade → new cycle with codeql dataset check at each stage — 0 consistency violations throughout. Confirmed the recoverable data survives the round-trip byte-for-byte (visibility_inners, visibility_inner_paths, and the format-arg names all identical before and after), while the genuinely-new node kinds are dropped on downgrade as the partial contract intends.

That round-trip surfaced and fixed two real bugs the scripts would otherwise have shipped:

  • Upgrade dangling @name refs. The first upgrade synthesised fresh @name entities for format-arg names but never added them to the names entity-defining table, leaving dangling references. Fixed by repurposing the old text-less @format_args_arg_name ids into @name (the precedent idiom) instead of minting new ones.
  • Downgrade dangling @ast_node refs. Deleting the new node kinds (which are members of the polymorphic @ast_node union) left dangling references in the two relations with a generic @ast_node value column — macro_call_macro_call_expansions (30 dangling values on the test DB) and comments. Fixed by scrubbing both relations, plus locatable_locations, for deleted nodes.

Toolchain-window note. 0.0.347 drops support for sysroots older than Rust 1.94.0, so format-macro (format_args!/println!/…) resolution requires Rust ≥ 1.94 (hence the test-toolchain bump 1.90 → 1.97). Two coupled upstream changes cause this: rust-analyzer #22784 (first in ra_ap 0.0.343) stopped injecting #[macro_use] on the sysroot crates, following rust-lang/rust #139493 which moved the std macros to the prelude in 1.94.0; and rust-analyzer 363940dc ("Remove format_args lowering for toolchains prior to 1.94.0", first in 0.0.344) removed the old format_args! compat lowering, leaving only the Rust 1.93+ bytecode form (rust-lang/rust #148789). Three System GlobalAlloc sinks (alloc/alloc_zeroed/realloc) are no longer resolved by 0.0.347's std resolution and are tracked as MISSING in the CWE-770 fixture with an inline comment, so the regression is an explicit, reviewable decision rather than a buried .expected diff.

redsun82 and others added 8 commits August 14, 2026 09:21
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
@github-actions github-actions Bot added documentation Ruby Rust Pull requests that update Rust code labels Aug 14, 2026
Comment thread rust/ql/lib/codeql/rust/controlflow/internal/generated/CfgNodes.qll Fixed
Comment thread rust/ql/lib/codeql/rust/controlflow/internal/generated/CfgNodes.qll Fixed
Comment thread rust/ql/lib/codeql/rust/controlflow/internal/generated/CfgNodes.qll Fixed
Comment thread rust/ql/lib/codeql/rust/elements.qll
Comment thread rust/ql/lib/codeql/rust/elements.qll
Comment thread rust/ql/test/extractor-tests/generated/StructField/StructField.ql
Comment thread rust/ql/test/extractor-tests/generated/Trait/Trait.ql
Comment thread rust/ql/test/extractor-tests/generated/TupleField/TupleField.ql
Comment thread rust/ql/test/extractor-tests/generated/Visibility/Visibility.ql
redsun82 and others added 8 commits August 14, 2026 12:22
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
Comment thread rust/ql/lib/codeql/rust/elements/ImplRestriction.qll
Comment thread rust/ql/lib/codeql/rust/elements/MutRestriction.qll
Comment thread rust/ql/lib/codeql/rust/elements/VisibilityInner.qll
Comment thread rust/ql/test/extractor-tests/generated/DerefPat/DerefPat.ql
redsun82 and others added 5 commits August 14, 2026 14:26
…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
@redsun82
redsun82 marked this pull request as ready for review August 14, 2026 14:09
@redsun82
redsun82 requested review from a team as code owners August 14, 2026 14:09
Copilot AI balanced review requested due to automatic review settings August 14, 2026 14:09
@redsun82
redsun82 requested review from a team as code owners August 14, 2026 14:09

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot wasn't able to review this pull request because it exceeds the maximum number of files (300). Try reducing the number of changed files and requesting a review from Copilot again.

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

Labels

documentation Ruby Rust Pull requests that update Rust code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants