-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Rust: Fix type inference for library parameters #19658
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: Fix type inference for library parameters #19658
Conversation
c4d46f2 to
07fe1bf
Compare
There was a problem hiding this 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 fixes type inference for library parameters by switching from pattern-based inference to using explicit type representations, updates related test expectations for Pin methods, and renames a debug helper to match its new signature.
- Replace
inferAnnotatedTypeon parameter patterns withTypeMention.resolveTypeAtfor library parameters - Adjust modeled dataflow tests and expected outputs to account for
into_inner_unchecked - Rename
debugResolveMethodCallExprto acceptMethodCallinstead ofMethodCallExpr
Reviewed Changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| rust/ql/test/library-tests/dataflow/modeled/main.rs | Reorder imports and update test comment for Pin::into_inner_unchecked |
| rust/ql/test/library-tests/dataflow/modeled/inline-flow.expected | Update expected model entries and edge labels |
| rust/ql/lib/codeql/rust/internal/TypeInference.qll | Use TypeMention.resolveTypeAt for parameter types and rename debug function signature |
Comments suppressed due to low confidence (1)
rust/ql/test/library-tests/dataflow/modeled/main.rs:98
- [nitpick] These two imports from
std::pincould be combined into a single statement:use std::pin::{pin, Pin};for clarity and conciseness.
use std::pin::pin;
| Function debugResolveMethodCallExpr(MethodCallExpr mce) { | ||
| mce = getRelevantLocatable() and | ||
| result = resolveMethodCallTarget(mce) | ||
| Function debugResolveMethodCallExpr(MethodCall mc) { |
Copilot
AI
Jun 4, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[nitpick] The debug function signature and parameter name changed from MethodCallExpr/mce to MethodCall/mc. Consider updating any related comments or docs to prevent confusion when maintaining this helper.
| Function debugResolveMethodCallExpr(MethodCall mc) { | |
| Function debugResolveMethodCall(MethodCall mc) { |
4812c40 to
c4966e8
Compare
c4966e8 to
0ccc4ac
Compare
eba3c69 to
4dda16b
Compare
4dda16b to
bcdd6f5
Compare
6595424 to
b753252
Compare
aibaars
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
b753252 to
1d7d45e
Compare
The old logic relied on parameters having a pattern, which is not the case for parameters extracted from library code.
The updated test output reveals that we do not handle operator calls correctly. For example,Now fixed by #19749.i32implements bothAddandAdd<Rhs = &i32>, and currently we resolve1 + 2to bothaddmethods, which means that2will have reverse-propagated type&i32in addition toi32.DCA (finally) looks good; we gain more call targets without sacrificing performance.