-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Rust: Infer certain type information for struct expressions #20403
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
Conversation
3da56ad
to
eea7006
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 adds type inference for struct expressions in Rust's type inference system. The changes improve the certainty of type information for struct expressions by allowing the system to infer types directly from struct constructors.
Key changes:
- Added type inference capability for struct expressions that resolves types from their paths
- Enhanced struct expression handling to provide type arguments from inferred types
- Updated test expectations to reflect improved certainty levels for struct-related type inference
Reviewed Changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.
File | Description |
---|---|
rust/ql/test/library-tests/type-inference/type-inference.expected | Test expectation updates reflecting removed type information entries for struct expressions |
rust/ql/test/library-tests/type-inference/pattern_matching.rs | Test comment updates changing from type= to certainType= annotations for variables |
rust/ql/test/library-tests/type-inference/main.rs | Test comment updates changing from type= to certainType= annotations for struct-related variables |
rust/ql/lib/codeql/rust/internal/TypeInference.qll | Core implementation adding struct expression type inference functionality |
exists(TypePath suffix | | ||
suffix.isCons(TTypeParamTypeParameter(apos.asTypeParam()), path) and | ||
result = CertainTypeInference::inferCertainType(this, suffix) | ||
) |
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.
Implementing this should prune some predicates thanks to the not exists(getTypeArgument(a, target, tp, _))
checks in the shared library. Using inferCertainType
will include both explicit types in the path to the struct as well as other certain ways to infer the type parameter.
| dereference.rs:122:23:122:29 | &... | &T.&T | dereference.rs:99:5:100:21 | Key | | ||
| dereference.rs:122:24:122:29 | Key {...} | | dereference.rs:99:5:100:21 | Key | | ||
| dereference.rs:122:24:122:29 | Key {...} | | file://:0:0:0:0 | & | | ||
| dereference.rs:122:24:122:29 | Key {...} | &T | dereference.rs:99:5:100:21 | Key | |
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.
These and the removed types below are spurious, so this is an improvement.
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.
Would it make sense to do this for struct patterns on this PR as well?
Yes, that makes sense. I've done that and kicked off another DCA run. |
Adds certain type information for struct expressions.
DCA seems fine.