Skip to content

Rust: upgrade to rust-analyzer 0.0.300 #20055

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 28 commits into
base: main
Choose a base branch
from
Open

Conversation

redsun82
Copy link
Contributor

@redsun82 redsun82 commented Jul 15, 2025

The upgrade script is particularly complex. To test it out, I have:

  • compiled the extractor on main
  • run the ForTypeRepr, WherePred and TypeBound tests. The only change I observed were locations (for ForBinder instances reconstructed with the upgrade script, the location does not include the for keyword).

@github-actions github-actions bot added the Rust Pull requests that update Rust code label Jul 15, 2025
toBeTested(x) and not x.isUnknown() and getExtendedCanonicalPath = x.getExtendedCanonicalPath()
}

query predicate getCrateOrigin(AsmExpr x, string getCrateOrigin) {

Check warning

Code scanning / CodeQL

Predicates starting with "get" or "as" should return a value Warning generated test

This predicate starts with 'get' but does not return a value.
@redsun82 redsun82 added the depends on internal PR This PR should only be merged in sync with an internal Semmle PR label Aug 5, 2025
@redsun82 redsun82 changed the title Rust: upgrade to rust 1.88 and rust-analyzer 0.0.294 Rust: upgrade to rust-analyzer 0.0.294 Aug 12, 2025
@github-actions github-actions bot added the Ruby label Aug 12, 2025
@redsun82 redsun82 changed the title Rust: upgrade to rust-analyzer 0.0.294 Rust: upgrade to rust-analyzer 0.0.300 Aug 12, 2025
import codeql.rust.elements.FieldExpr
import codeql.rust.elements.FieldList
import codeql.rust.elements.FnPtrTypeRepr
import codeql.rust.elements.ForBinder

Check warning

Code scanning / CodeQL

Redundant import Warning

Redundant import, the module is already imported inside
codeql.rust.elements.ClosureExpr
.
Redundant import, the module is already imported inside
codeql.rust.elements.ForTypeRepr
.
Redundant import, the module is already imported inside
codeql.rust.elements.TypeBound
.
Redundant import, the module is already imported inside
codeql.rust.elements.WherePred
.
@@ -4,6 +4,20 @@

query predicate instances(AsmExpr x) { toBeTested(x) and not x.isUnknown() }

query predicate getExtendedCanonicalPath(AsmExpr x, string getExtendedCanonicalPath) {

Check warning

Code scanning / CodeQL

Predicates starting with "get" or "as" should return a value Warning generated test

This predicate starts with 'get' but does not return a value.
toBeTested(x) and not x.isUnknown() and getExtendedCanonicalPath = x.getExtendedCanonicalPath()
}

query predicate getCrateOrigin(AsmExpr x, string getCrateOrigin) {

Check warning

Code scanning / CodeQL

Predicates starting with "get" or "as" should return a value Warning generated test

This predicate starts with 'get' but does not return a value.
toBeTested(x) and not x.isUnknown() and getCrateOrigin = x.getCrateOrigin()
}

query predicate getAttributeMacroExpansion(AsmExpr x, MacroItems getAttributeMacroExpansion) {

Check warning

Code scanning / CodeQL

Predicates starting with "get" or "as" should return a value Warning generated test

This predicate starts with 'get' but does not return a value.
@@ -37,8 +37,8 @@
toBeTested(x) and not x.isUnknown() and getBody = x.getBody()
}

query predicate getClosureBinder(ClosureExpr x, ClosureBinder getClosureBinder) {
toBeTested(x) and not x.isUnknown() and getClosureBinder = x.getClosureBinder()
query predicate getForBinder(ClosureExpr x, ForBinder getForBinder) {

Check warning

Code scanning / CodeQL

Predicates starting with "get" or "as" should return a value Warning generated test

This predicate starts with 'get' but does not return a value.

query predicate instances(ForBinder x) { toBeTested(x) and not x.isUnknown() }

query predicate getGenericParamList(ForBinder x, GenericParamList getGenericParamList) {

Check warning

Code scanning / CodeQL

Predicates starting with "get" or "as" should return a value Warning generated test

This predicate starts with 'get' but does not return a value.
@@ -4,8 +4,8 @@

query predicate instances(ForTypeRepr x) { toBeTested(x) and not x.isUnknown() }

query predicate getGenericParamList(ForTypeRepr x, GenericParamList getGenericParamList) {
toBeTested(x) and not x.isUnknown() and getGenericParamList = x.getGenericParamList()
query predicate getForBinder(ForTypeRepr x, ForBinder getForBinder) {

Check warning

Code scanning / CodeQL

Predicates starting with "get" or "as" should return a value Warning generated test

This predicate starts with 'get' but does not return a value.
@@ -13,6 +13,10 @@
if x.isConst() then isConst = "yes" else isConst = "no"
}

query predicate getForBinder(TypeBound x, ForBinder getForBinder) {

Check warning

Code scanning / CodeQL

Predicates starting with "get" or "as" should return a value Warning generated test

This predicate starts with 'get' but does not return a value.
@@ -4,8 +4,8 @@

query predicate instances(WherePred x) { toBeTested(x) and not x.isUnknown() }

query predicate getGenericParamList(WherePred x, GenericParamList getGenericParamList) {
toBeTested(x) and not x.isUnknown() and getGenericParamList = x.getGenericParamList()
query predicate getForBinder(WherePred x, ForBinder getForBinder) {

Check warning

Code scanning / CodeQL

Predicates starting with "get" or "as" should return a value Warning generated test

This predicate starts with 'get' but does not return a value.
@redsun82 redsun82 removed the depends on internal PR This PR should only be merged in sync with an internal Semmle PR label Aug 15, 2025
@redsun82 redsun82 marked this pull request as ready for review August 15, 2025 08:20
@redsun82 redsun82 requested review from a team as code owners August 15, 2025 08:20
@Copilot Copilot AI review requested due to automatic review settings August 15, 2025 08:20
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR upgrades the rust-analyzer version from 0.0.299 to 0.0.300 as indicated by the title. The upgrade brings updates to the Rust AST schema and affects test expectations across various CodeQL test suites due to improved location precision and renamed AST nodes.

  • Updates the Rust AST schema with structural changes including renaming ClosureBinder to ForBinder
  • Introduces the ForBinder as a more general construct for closure and type parameter bindings
  • Updates dependency versions and test expectations to match the improved rust-analyzer output

Reviewed Changes

Copilot reviewed 204 out of 251 changed files in this pull request and generated no comments.

File Description
shared/tree-sitter-extractor/Cargo.toml Updates the rand dependency from version 0.9.1 to 0.9.2
rust/schema/ast.py Major AST schema changes: renames ClosureBinder to ForBinder, adds Item inheritance to AsmExpr, and updates field references
rust/schema/annotations.py Updates documentation and annotations to reflect the renaming from ClosureBinder to ForBinder
Multiple .expected files Updates test expectations to reflect improved location precision from the rust-analyzer upgrade

You can also share your feedback on Copilot code review for a chance to win a $100 gift card. Take the survey.

@@ -1 +1,2 @@
| gen_asm_clobber_abi.rs:8:14:8:29 | AsmClobberAbi |
| gen_asm_clobber_abi.rs:8:14:8:29 | AsmClobberAbi |
Copy link
Contributor

Choose a reason for hiding this comment

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

This looks like a duplicate database element. Any idea what this is about?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think it has to do with how the asm! macro is expanded. Might be good to have a look at the AST

Copy link
Contributor Author

Choose a reason for hiding this comment

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

seems like asm! expands to a MacroBlockExpr that has both its TailExpr and its Statement populated with a copy of the AsmExpr each 😕

Copy link
Contributor

Choose a reason for hiding this comment

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

That sounds like a potential bug. The parser is implemented by hand, so it is possible they made a mistake.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

well, it's not the parser populating that, but the asm! special case of macro expansion (so even more ripe for possible errors)

Copy link
Contributor

@aibaars aibaars Aug 19, 2025

Choose a reason for hiding this comment

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

Or more likely the tail_expr() and statements() methods are wrong. These are typically implemented as "find first child with matching type" and because AsmExpr is now also an Item the statements() method will pick it up too. See also:

https://github.com/rust-lang/rust-analyzer/blob/58bbdec73138b978dd91f1082110168fcdeb4669/crates/syntax/src/ast/generated/nodes.rs#L1561-L1565

https://github.com/rust-lang/rust-analyzer/blob/58bbdec73138b978dd91f1082110168fcdeb4669/crates/syntax/src/ast/generated/nodes.rs#L949-L954

Not sure if you want to file a bug report, a PR to fix it, or whether to patch things up in the extractor or in QL.

Having duplicated nodes is not great, but asm stuff is fairly rare and we don't do much with it so having a bad AST temporarily shouldn't be too much of a problem.

Copy link
Contributor Author

@redsun82 redsun82 Aug 19, 2025

Choose a reason for hiding this comment

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

uh, I think I see what's happening. This is equivalent to that weird situation we have for path segments, where there's a roundabout way of getting the types from it.

When asking for the repeated Stmt children of a MacroBlock, the library just looks at the children for a matching type. Now, because AsmExpr now are also Items, and Items are Stmts, an AsmExpr will match both as the Stmt* children and as the Expr? one. So this stems from a limitation of the ast library in rust-analyzer...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

:jinx-coke:

Copy link
Contributor Author

Choose a reason for hiding this comment

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

can fix that in the extractor

Copy link
Contributor Author

Choose a reason for hiding this comment

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

filed an issue in rust-lang/rust-analyzer#20485

@redsun82 redsun82 added the no-change-note-required This PR does not need a change note label Aug 18, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
no-change-note-required This PR does not need a change note Ruby Rust Pull requests that update Rust code
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants