Rust: Update rust-analyzer - #22661
Conversation
| import codeql.files.FileSystem | ||
| import codeql.rust.elements.Abi | ||
| import codeql.rust.elements.Addressable | ||
| import codeql.rust.elements.AnyAttr |
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
e417c3b to
3a7f851
Compare
There was a problem hiding this comment.
CodeQL found more than 20 potential problems in the proposed changes. Check the Files changed tab for more details.
7ab640b to
7321f99
Compare
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 612c2b22-3121-4c83-9656-bb0f4abb2a8a
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: a04d83d9-ceea-4109-8ce1-f420585125d4
ra-ap-rustc_lexer requires unicode-ident and unicode-properties to use matching Unicode tables. ra_ap_parser 0.0.352 also requires winnow 0.7.13 to avoid a panic on Unicode following incomplete frontmatter. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 612c2b22-3121-4c83-9656-bb0f4abb2a8a
7321f99 to
c329d70
Compare
The new rust-analyzer version fixed a bug related to unicode parsing. As at test for this, one of the `ra_ap_parser` crate contain a test fixture with this invalid unicode. The _current_ Rust extractor naturally inherits the parsing bug present in the older rust-analyzer dependency that it uses. When CI does Code Scanning on the _new_ Rust extractor with the _old_ Rust extractor the parsing bug is hit since the beforementioned test fixture is extracted when extracting the Rust extractor through the `ra_ap_parser` dependency. As a temporaty workaroyund, we remove the test fixture from Cargo's downloaded dependency source before extracting. This avoid the old extractor failing in CI. Once the updated extractor is running on CI we should be able to remove this again.
Regenerate line-count expectations now that documentation comments are extracted as grammar nodes. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 612c2b22-3121-4c83-9656-bb0f4abb2a8a
c329d70 to
ffc6ca4
Compare
There was a problem hiding this comment.
Copilot review overview
🟡 Changes recommended
DocComment loses queryable text, and the declared full downgrade drops documentation comments rather than restoring legacy comment facts.
Review effort: Balanced
Findings: 1
Open (2)
What changed in this PR
Updates the Rust extractor to rust-analyzer 0.0.352 and adapts extraction to the new AnyAttr and DocComment AST nodes.
Changes:
- Updates Rust tooling, dependencies, and generated Bazel metadata.
- Regenerates schemas, QL libraries, and extractor tests for
AnyAttr. - Adds migration metadata, diagnostics updates, and CI handling.
| File | Description |
|---|---|
.github/workflows/rust-analysis.yml |
Removes a malformed dependency fixture before analysis. |
Cargo.lock, MODULE.bazel, Cargo manifests |
Update Rust and transitive dependencies. |
misc/bazel/3rdparty/tree_sitter_extractors_deps/** |
Regenerate vendored Bazel dependency metadata. |
rust/ast-generator/** |
Generate AnyAttr extraction via attrs_with_doc. |
rust/extractor/** |
Update toolchain and generated extraction code. |
rust/schema/** |
Model AnyAttr and DocComment. |
rust/ql/lib/codeql/rust/** |
Expose the new AST hierarchy throughout QL. |
rust/ql/lib/upgrades/**, rust/downgrades/** |
Add schema migration metadata. |
rust/ql/test/** |
Regenerate extractor and diagnostic expectations. |
rust/ql/integration-tests/conftest.py, rust/ql/test/setup.sh |
Install Rust 1.98.1 for tests. |
rust/ql/lib/change-notes/** |
Document the rust-analyzer upgrade. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
| fn get_trait_fields(trait_name: &str) -> Vec<FieldInfo> { | ||
| match trait_name { | ||
| "HasAttrs" => vec![FieldInfo::list("attrs", "Attr")], | ||
| "HasAttrs" => vec![FieldInfo::list("attrs", "AnyAttr")], |
| description: Downgrade rust-analyzer to 0.0.347 | ||
| compatibility: full | ||
|
|
||
| doc_comments.rel: delete |
There was a problem hiding this comment.
Fair, but not sure it is worthwhile fixing.
| languages: ${{ matrix.language }} | ||
| config-file: ./.github/codeql/codeql-config.yml | ||
|
|
||
| - name: Remove malformed rust-analyzer parser fixture |
There was a problem hiding this comment.
Perhaps add a TODO comment about removing this again.
There was a problem hiding this comment.
Done and I've added an issue so I don't forget 💪
| @@ -1 +1 @@ | |||
| | 60 | | |||
| | 67 | | |||
There was a problem hiding this comment.
I think it would be better to update File.getNumberOfLinesOfCode to also exclude DocComments.
There was a problem hiding this comment.
Good point. That might actually be why we extract more lines of code in DCA 🫠
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: e18ced25-1ee7-4f49-8f95-38272775c944


This PR updates rust-analyzer for the Rust extractor to version 0.0.352.
The biggest change that affects is is a recent change to
rust.ungramthat introduces a new AST nodeas well as
DocComment. Pretty much everywhere whereAttrwhere previously used the grammar now specifiesAnyAttr. This change is reflected in the dbscheme, QL classes, etc.DCA
The DCA report is fine. "Lines of code in the database" seems to genuinely have improved by a significant amount. For "Missing call targets" a lot of projects have exactly 12 additional missing targets, but "Calls with a call target" only increases, so this is likely because we're extracting something we didn't extract before (maybe something in a common library).