Skip to content

Rust: Upgrade to rust-analyzer 0.328#21714

Open
tausbn wants to merge 26 commits into
mainfrom
tausbn/rust-upgrade-to-rust-analyzer-0.0.328
Open

Rust: Upgrade to rust-analyzer 0.328#21714
tausbn wants to merge 26 commits into
mainfrom
tausbn/rust-upgrade-to-rust-analyzer-0.0.328

Conversation

@tausbn

@tausbn tausbn commented Apr 15, 2026

Copy link
Copy Markdown
Contributor

WIP. Let's see what the CI thinks of this. (For the avoidance of doubt, Copilot wrote all of the code, and I'm still working my way through the changes themselves.)

tausbn and others added 6 commits April 15, 2026 12:54
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…scripts

- Fix Meta usage: Meta is now abstract with subtypes (PathMeta, KeyValueMeta, TokenTreeMeta, etc.)
- Fix FormatArgsArg: getName() replaced by getArgName() returning FormatArgsArgName
- Add upgrade script (old → new) and downgrade script (new → old)
- Update Definitions.qll, PathResolution.qll, BadCtorInitialization.ql, FormatTemplateVariableAccessConstructor.qll

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@github-actions github-actions Bot added Ruby Rust Pull requests that update Rust code labels Apr 15, 2026
@tausbn tausbn changed the title Rust: Upgrade to rusts-analyzer 0.328 Rust: Upgrade to rust-analyzer 0.328 Apr 15, 2026
Comment thread rust/ql/lib/codeql/rust/elements.qll Dismissed
Comment thread rust/ql/lib/codeql/rust/elements.qll Dismissed
Comment thread rust/ql/lib/codeql/rust/elements.qll Dismissed
Comment thread rust/ql/lib/codeql/rust/elements/TryBlockModifier.qll Dismissed
Comment thread rust/ql/lib/codeql/rust/internal/Definitions.qll Dismissed
Comment thread rust/ql/test/extractor-tests/generated/BlockExpr/BlockExpr.ql Dismissed
Comment thread rust/ql/test/extractor-tests/generated/FormatArgsExpr/FormatArgsArg.ql Dismissed
Comment thread rust/ql/test/extractor-tests/generated/FormatArgsExpr/FormatArgsArg.ql Dismissed
Comment thread rust/ql/test/extractor-tests/generated/StructField/StructField.ql Dismissed
Comment thread rust/ql/test/extractor-tests/generated/Variant/Variant.ql Dismissed
tausbn and others added 5 commits April 15, 2026 15:12
Re-run cargo fmt after clippy --fix to ensure consistent formatting.
Re-run codegen to update generated file tracking for MetaImpl.qll.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Setting proc_macro_processes to 0 causes an index-out-of-bounds panic
in ProcMacroServerPool::new when the proc macro server is enabled.
Use the same defaults as rust-analyzer itself (1 each).

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
- Remove format_args_arg_names from upgrade delete list (table exists in both schemas with different columns)
- Accept updated .expected files for schema changes

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
- Exclude macro-expanded and attribute paths from PathResolutionConsistency
  (tokio::main and similar attribute macros resolve to multiple proc macro fns)
- Exclude "macro expansion failed" warnings from ExtractionConsistency
  (compile_error! and undefined macros are expected to fail expansion)
- Update pre-existing consistency expectations (net multipleResolvedTargets)
- Update type-inference.expected for new RA results

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@tausbn tausbn force-pushed the tausbn/rust-upgrade-to-rust-analyzer-0.0.328 branch from c990d17 to ac27c20 Compare April 16, 2026 14:15
tausbn and others added 2 commits April 16, 2026 20:31
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Comment thread rust/ql/lib/codeql/rust/elements.qll Dismissed
Comment thread rust/ql/lib/codeql/rust/elements.qll Dismissed
Comment thread rust/ql/lib/codeql/rust/elements.qll Dismissed
Comment thread rust/ql/lib/codeql/rust/elements.qll Dismissed
@redsun82 redsun82 marked this pull request as ready for review May 22, 2026 15:35
Copilot AI review requested due to automatic review settings May 22, 2026 15:35
@redsun82 redsun82 requested review from a team as code owners May 22, 2026 15:35

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.

@redsun82 redsun82 requested a review from geoffw0 May 22, 2026 15:58

@geoffw0 geoffw0 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).

Yeah, I feel that, though I suspect some of these files visible in the diff are generated code not marked as such. I've skimmed through all the changes anyway, but I'll have to rely mostly on testing (automated and manual) to build confidence here.

Can I get confirmation:

  • that the Copilot-written changes have been reviewed by the author?
  • that the upgrade / downgrade scripts have been tested?

Comment thread rust/ast-generator/patches/rust-analyzer.patch
Comment thread rust/ql/consistency-queries/ExtractionConsistency.ql Outdated
Comment thread rust/ql/lib/codeql/rust/internal/PathResolutionConsistency.qll Outdated
Comment thread ruby/extractor/Cargo.toml
redsun82 and others added 5 commits May 26, 2026 15:06
Adds upgrade.ql with transformations for all schema changes from
rust-analyzer 0.0.301 to 0.0.328:
- Meta split into PathMeta/KeyValueMeta/TokenTreeMeta/UnsafeMeta
- TraitAlias merged into Trait
- BlockExpr.isTry() -> TryBlockModifier
- StructField.getDefault() -> getDefaultVal() returning ConstArg
- Variant.getDiscriminant() -> getConstArg() returning ConstArg
- FormatArgsArg.getName() -> getArgName() returning FormatArgsArgName

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@redsun82

redsun82 commented May 27, 2026

Copy link
Copy Markdown
Contributor

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

@geoffw0 geoffw0 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.

New commits (the full upgrade / downgrade scripts) LGTM, though it's fiddly code - I'm glad you created tests for them.

I've made a couple of new comments, and there are still some incomplete discussions above I think.

@@ -15855,3 +15847,18 @@ inferType
| regressions.rs:179:24:179:27 | S(...) | T | {EXTERNAL LOCATION} | i32 |
| regressions.rs:179:26:179:26 | 1 | | {EXTERNAL LOCATION} | i32 |
testFailures
| main.rs:1308:44:1308:62 | //... | Missing result: target=default |

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.

We lose a bunch of results for this type inference test. Whether or not they're important results (@hvitved), we should update the expectation comments to MISSING:.

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.

I believe this is because derive macros are not properly expanded; should definitely be fixed before merging.

subpaths
testFailures
| main.rs:58:47:58:57 | //... | Missing result: Source |
| main.rs:59:25:59:56 | //... | Missing result: Alert[rust/insecure-cookie] |

@geoffw0 geoffw0 Jun 1, 2026

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.

We appear to be losing all many query results for this query. Unless you already have an intuition what's wrong here, I should probably look into it.

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.

... I got as far as determining that the source and sinks are recognized, but flow is lost because we're missing some calls to clone() in the database ...

@hvitved hvitved 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.

It appears there are various macro expansion issues that need to be resolved.

@@ -4,9 +4,6 @@
| lib.rs:1:1:1:18 | mod anonymous | test::anonymous |
| lib.rs:2:1:2:16 | mod regular | test::regular |
| regular.rs:1:1:2:18 | struct Struct | test::regular::Struct |
| regular.rs:2:12:2:17 | fn eq | <test::regular::Struct as core::cmp::PartialEq>::eq |
| regular.rs:2:12:2:17 | impl ...::Eq for Struct::<...> { ... } | <test::regular::Struct as core::cmp::Eq> |
| regular.rs:2:12:2:17 | impl ...::PartialEq for Struct::<...> { ... } | <test::regular::Struct as core::cmp::PartialEq> |

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.

It looks like derive macros are no longer expanded; getDeriveMacroExpansion does not have any results on this test case.

@@ -15855,3 +15847,18 @@ inferType
| regressions.rs:179:24:179:27 | S(...) | T | {EXTERNAL LOCATION} | i32 |
| regressions.rs:179:26:179:26 | 1 | | {EXTERNAL LOCATION} | i32 |
testFailures
| main.rs:1308:44:1308:62 | //... | Missing result: target=default |

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.

I believe this is because derive macros are not properly expanded; should definitely be fixed before merging.

@redsun82

Copy link
Copy Markdown
Contributor

I dug a bit more into this, and I think the missing derive expansions are actually expected with this rust-analyzer version (although it is a bit unfortunate for our current extraction model).

The relevant bit seems to be the new built-in derive fast path. In ra_ap_hir_def::builtin_derive rust-analyzer explicitly says that built-in derives are not really expanded anymore, to save time and memory. Instead, nameres/collector.rs records a BuiltinDeriveImplId, and hir-ty then teaches trait solving and method resolution about those synthetic impls directly.

That also explains the exact shape of the diff here: custom proc-macro derives still go through a real MacroCallId, so MyTrait is still emitted. But built-ins like Debug, PartialEq, and Eq become Either::Right(BuiltinDeriveImplId), and Semantics::expand_derive_macro only keeps the Either::Left(MacroCallId) case.

There is semantic information available for these impls through hir::Impl (trait_, trait_ref, self_ty, items, etc.), but there is no ast::Impl source for them (HasSource::source returns None, and source_with_range only points back to the derive range). For our current type_item_derive_macro_expansions relation, I guess the options are either:

  1. accept this expectation change for built-in derives, and make sure the QL library works with that (@hvitved, any insight on what would it take?) or
  2. ask rust-analyzer for a supported API to expose the synthetic built-in derive syntax again,
  3. ship this as is now, track 1. or 2. as follow ups.

Trying to recreate the old AST expansion in the extractor looks possible in theory, but pretty risky in practice, since we would be duplicating rust-analyzer's built-in derive expansion/token-tree setup and could easily drift from it.

cc @geoffw0

@hvitved

hvitved commented Jun 10, 2026

Copy link
Copy Markdown
Contributor

I dug a bit more into this, and I think the missing derive expansions are actually expected with this rust-analyzer version (although it is a bit unfortunate for our current extraction model).

Thanks for investigating, Paolo.

We don't really need the bodies of the derived impl blocks, we only need the signatures; is there any hope we could perhaps still get that?

@redsun82

Copy link
Copy Markdown
Contributor

@hvitved: derive impls always have the signature from the trait definition. We should see if we can have a fallback to that in QL, and failing that in the extractor. As there's no overloading, a simple name search in the trait should do, so I have the feeling a simple QL fallback (impl has no signature -> get signature from implemented trait looking up the method by name). Wdyt?

@hvitved

hvitved commented Jun 10, 2026

Copy link
Copy Markdown
Contributor

@hvitved: derive impls always have the signature from the trait definition. We should see if we can have a fallback to that in QL, and failing that in the extractor. As there's no overloading, a simple name search in the trait should do, so I have the feeling a simple QL fallback (impl has no signature -> get signature from implemented trait looking up the method by name). Wdyt?

While we can certainly do it in QL, it would complicate things quite a lot; so far we have relied on everything being AstNodes, but we would then have to synthesize nodes on top.

@redsun82

Copy link
Copy Markdown
Contributor

hmm, two options then I think:

  • we add synth nodes in the codegen layer (so in QL, but generated)
  • we synthesize thse in the extractor, a bit like we synthesize library stubs for dependencies already

I'll mull this over

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Ruby Rust Pull requests that update Rust code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants