Rust: add more type inference tests for patterns and a simple one for a closure call#20029
Merged
Rust: add more type inference tests for patterns and a simple one for a closure call#20029
Conversation
Contributor
There was a problem hiding this comment.
Pull Request Overview
This PR adds comprehensive test cases for Rust pattern matching and a simple closure test for type inference. The purpose is to expand test coverage for pattern inference across all pattern types supported by Rust's grammar.
- Adds comprehensive pattern matching test cases covering all major pattern types (literal, identifier, wildcard, range, reference, record, tuple struct, tuple, slice, path, or, box, rest, macro patterns, etc.)
- Adds a simple closure test to verify type inference in closure parameters
- Enables the
box_patternsfeature flag to support box pattern testing
Reviewed Changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| rust/ql/test/library-tests/type-inference/type-inference.expected | Updates expected test output with new type inference results from the expanded test cases |
| rust/ql/test/library-tests/type-inference/main.rs | Adds comprehensive pattern matching examples and a closure test, enabling box_patterns feature |
hvitved
requested changes
Jul 11, 2025
Contributor
hvitved
left a comment
There was a problem hiding this comment.
LGTM, but I think we should move the entire pattern_matching module into a separate pattern_matching.rs file (just like we already have a dereferences.rs file).
hvitved
reviewed
Jul 11, 2025
| } | ||
| // Catch-all with identifier pattern | ||
| other => { | ||
| let other_complex = other; // $ MISSING: type=other_complex:? |
Contributor
There was a problem hiding this comment.
I'm surprised that this doesn't work.
Contributor
Author
There was a problem hiding this comment.
complex_data has a tuple type.
Thanks to co-pilot for generating the examples
4d1691f to
519905e
Compare
hvitved
approved these changes
Jul 11, 2025
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.
I just asked co-pilot to generate sample test code that covers all the cases for Pat from the ungrammar.
I had to drop the sample code about "const block patterns" because that rust-lang/rust#138492 has been removed from Rust.