Skip to content
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

Handle structs as scrutinee for match expressions #2958

Merged
merged 2 commits into from May 15, 2024

Conversation

nobel-sh
Copy link
Contributor

gcc/rust/ChangeLog:

* backend/rust-compile-expr.cc (check_match_scrutinee): Handle structs

fixes #2906

We should now be able to use struct as scrutinee. I tested the code locally and it ran without issues but I was wondering if this patch also required a test case along with it.

gcc/rust/ChangeLog:

	* backend/rust-compile-expr.cc (check_match_scrutinee): Handle structs

Signed-off-by: Nobel Singh <nobel2073@gmail.com>
@dkm
Copy link
Member

dkm commented Apr 22, 2024

You're right, adding a matching test would be great. Even more if you already have one at hand! Thanks!

Copy link
Member

@CohenArthur CohenArthur left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks correct, thanks! I agree with @dkm that we would require a testcase in that instance, so that we can ensure we don't introduce regressions later on. I'd also like to see an execution testcase to check if we do match properly on structures (let me know if you need help with that)

@nobel-sh
Copy link
Contributor Author

Sure, I'm on it! Also, @CohenArthur, I'm not very familiar with execution test cases (are these supposed to differ from other test cases?). Any help you could offer would be greatly appreciated!

@CohenArthur
Copy link
Member

Sure, I'm on it! Also, @CohenArthur, I'm not very familiar with execution test cases (are these supposed to differ from other test cases?). Any help you could offer would be greatly appreciated!

they differ in that they're in a different folder in the testsuite, and they will usually have an extra dg-output directive to make sure the printed output is correct :) but the best way is to create a main function which returns an i32, and to make it return 0 if the test works and something else if the test fails. check out gcc/testsuite/rust/execute/torture/matches_macro.rs for a good example

gcc/testsuite/ChangeLog:

	* rust/compile/issue-2906.rs: New test.
	* rust/execute/torture/issue-2906.rs: New test.

Signed-off-by: Nobel Singh <nobel2073@gmail.com>
@nobel-sh
Copy link
Contributor Author

@CohenArthur please LMK if these test cases are enough or not.

Also, a question not related to this thread. Have we implemented immutability/mutability for variables yet? because while writing these tests I was able to mutate a variable without declaring it mutable.

Copy link
Member

@P-E-P P-E-P left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@P-E-P P-E-P added this pull request to the merge queue May 15, 2024
Merged via the queue into Rust-GCC:master with commit 154ce77 May 15, 2024
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Rebinding match expressions on structs are unhandled
4 participants