gccrs icon indicating copy to clipboard operation
gccrs copied to clipboard

Handle structs as scrutinee for match expressions

Open nobel-sh opened this issue 1 year ago • 4 comments

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.

nobel-sh avatar Apr 21 '24 19:04 nobel-sh

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

dkm avatar Apr 22 '24 08:04 dkm

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!

nobel-sh avatar Apr 22 '24 20:04 nobel-sh

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

CohenArthur avatar Apr 22 '24 20:04 CohenArthur

@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.

nobel-sh avatar Apr 23 '24 21:04 nobel-sh