Skip to content
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

Rust: extract generic parameters, arguments and resolve bound type variables #19237

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

Conversation

aibaars
Copy link
Contributor

@aibaars aibaars commented Apr 7, 2025

No description provided.

@Copilot Copilot bot review requested due to automatic review settings April 7, 2025 19:31
@github-actions github-actions bot added the Rust Pull requests that update Rust code label Apr 7, 2025
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 aims to support the extraction of generic parameters, arguments, and the resolution of bound type variables in Rust. It introduces two new generic structs (LocalKey and Thing) and implements a From trait conversion for Thing instantiated with type X.

Files not reviewed (3)
  • rust/ql/lib/codeql/rust/elements/internal/LifetimeImpl.qll: Language not supported
  • rust/ql/test/extractor-tests/crate_graph/modules.expected: Language not supported
  • rust/ql/test/extractor-tests/crate_graph/modules.ql: Language not supported
Comments suppressed due to low confidence (2)

rust/ql/test/extractor-tests/crate_graph/module.rs:47

  • [nitpick] The struct name 'LocalKey' is ambiguous; consider renaming it or adding a doc comment to clarify its purpose.
pub struct LocalKey<T: 'static> {

rust/ql/test/extractor-tests/crate_graph/module.rs:48

  • [nitpick] Consider renaming the field 'inner' to a more descriptive name that reflects its functionality to improve code readability.
    inner: fn(Option<&mut Option<T>>) -> *const T,

@aibaars aibaars force-pushed the aibaars/crate-graph-type-variables branch 2 times, most recently from cb7b4a6 to 5178925 Compare April 10, 2025 11:22
@aibaars aibaars force-pushed the aibaars/crate-graph-type-variables branch from 70e9c22 to 5c67429 Compare April 10, 2025 19:42
@aibaars aibaars force-pushed the aibaars/crate-graph-type-variables branch from 5c67429 to df5f003 Compare April 10, 2025 20:36
@@ -319,6 +319,13 @@ resolvePath
| my.rs:18:9:18:11 | my4 | my.rs:14:1:16:1 | mod my4 |
| my.rs:18:9:18:16 | ...::my5 | my.rs:15:5:15:16 | mod my5 |
| my.rs:18:9:18:19 | ...::f | my/my4/my5/mod.rs:1:1:3:1 | fn f |
| my.rs:22:5:22:9 | std | file:///Users/arthur/.rustup/toolchains/1.85-aarch64-apple-darwin/lib/rustlib/src/rust/library/std/src/lib.rs:0:0:0:0 | Crate(std@0.0.0) |
Copy link
Contributor

Choose a reason for hiding this comment

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

Looks like we should add an i.fromSource() conjunct to query predicate resolvePath.

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 took the following approach a2844cc . Just dropping the results by filtering with i.fromSource() also works. Or perhaps simply set the location to "no location" for things that are not from source. I think it would still be useful to record that std was resolved to Crate(std), though the file path is not too relevant.

@@ -178,7 +178,7 @@ abstract class ItemNode extends Locatable {
Stages::PathResolutionStage::ref() and
result = this.getASuccessorRec(name)
or
preludeEdge(this, name, result)
preludeEdge(this, name, result) and not declares(this, _, name)
Copy link
Contributor

Choose a reason for hiding this comment

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

LGTM, but let's do it in its own PR (as you suggested offline).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Rust Pull requests that update Rust code
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants