-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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: Implement support for inference of type aliases #19146
Conversation
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 implements support for type alias inference in Rust by inlining alias definitions to normalize types. Key changes include the addition of a new helper method (unwrapSnd) for the PairOption type, updates to type alias definitions (including nested aliases), and adjustments to test cases to reflect these changes.
Files not reviewed (1)
- rust/ql/lib/codeql/rust/internal/TypeMention.qll: Language not supported
Comments suppressed due to low confidence (1)
rust/ql/test/library-tests/type-inference/main.rs:541
- [nitpick] The generic parameter 'A3' is not very descriptive. Consider using a more meaningful name to improve code clarity.
type AnotherPair<A3> = PairOption<S2, A3>;
Tip: Copilot code review supports C#, Go, Java, JavaScript, Markdown, Python, Ruby and TypeScript, with more languages coming soon. Learn more
// Alias to another alias | ||
type AliasToAlias<A4> = AnotherPair<A4>; | ||
|
||
// Alias that appears nested withing another alias |
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.
Typo in comment: 'withing' should be corrected to 'within'.
Copilot is powered by AI, so mistakes are possible. Review output carefully before use.
09fa787
to
e212af1
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.
Very nice, one suggestion.
Thanks for reviewing :) |
This PR implements support for type aliases. I can think of two ways to implement type aliases:
getABaseTypeMention
.resolveTypeAt
.This PR does the latter, for a few reasons:
if b { let x: Alias1 = ...; x } else { let y: Alias2 = ...; y }
whereAlias1
andAlias2
refer to the same type, immediately unfolding the alias means that the entireif
expression only gets one inferred type, and not both (identical) type aliases.