Rust: Implement support for inference of type aliases#19146
Merged
paldepind merged 3 commits intogithub:mainfrom Apr 7, 2025
Merged
Rust: Implement support for inference of type aliases#19146paldepind merged 3 commits intogithub:mainfrom
paldepind merged 3 commits intogithub:mainfrom
Conversation
Contributor
There was a problem hiding this comment.
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.
Typo in comment: 'withing' should be corrected to 'within'.
09fa787 to
e212af1
Compare
hvitved
previously approved these changes
Apr 7, 2025
Contributor
hvitved
left a comment
There was a problem hiding this comment.
Very nice, one suggestion.
hvitved
approved these changes
Apr 7, 2025
Contributor
Author
|
Thanks for reviewing :) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 }whereAlias1andAlias2refer to the same type, immediately unfolding the alias means that the entireifexpression only gets one inferred type, and not both (identical) type aliases.