aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMahmoud Mohamed <mahadelr19@gmail.com>2023-03-16 14:53:44 +0300
committerArthur Cohen <arthur.cohen@embecosm.com>2024-01-16 18:21:12 +0100
commitf821a019e624555397b539e864cc145057922a63 (patch)
treed5b27edc330ddae40b5d1003b6a6eee75ed27dab
parentdc92981d06a8695bf589a1fcfda427a38265ebee (diff)
downloadgcc-f821a019e624555397b539e864cc145057922a63.zip
gcc-f821a019e624555397b539e864cc145057922a63.tar.gz
gcc-f821a019e624555397b539e864cc145057922a63.tar.bz2
gccrs: resolve: Fix multiple bindings handling in match
gcc/rust/ChangeLog: * resolve/rust-ast-resolve-expr.cc (ResolveExpr::visit): Push a Product context instead of an Or context. gcc/testsuite/ChangeLog: * rust/compile/multiple_bindings2.rs: New test. Signed-off-by: Mahmoud Mohamed <mahadelr19@gmail.com>
-rw-r--r--gcc/rust/resolve/rust-ast-resolve-expr.cc12
-rw-r--r--gcc/testsuite/rust/compile/multiple_bindings2.rs14
2 files changed, 20 insertions, 6 deletions
diff --git a/gcc/rust/resolve/rust-ast-resolve-expr.cc b/gcc/rust/resolve/rust-ast-resolve-expr.cc
index 6b7782c..a2708f5 100644
--- a/gcc/rust/resolve/rust-ast-resolve-expr.cc
+++ b/gcc/rust/resolve/rust-ast-resolve-expr.cc
@@ -207,10 +207,10 @@ ResolveExpr::visit (AST::IfLetExpr &expr)
resolver->push_new_type_rib (resolver->get_type_scope ().peek ());
resolver->push_new_label_rib (resolver->get_type_scope ().peek ());
- // FIXME: this declaration should be removed after refactoring
- // parse_match_arm_patterns output into an AltPattern
+ // We know expr.get_patterns () has one pattern at most
+ // so there's no reason to handle it like an AltPattern.
std::vector<PatternBinding> bindings
- = {PatternBinding (PatternBoundCtx::Or, std::set<Identifier> ())};
+ = {PatternBinding (PatternBoundCtx::Product, std::set<Identifier> ())};
for (auto &pattern : expr.get_patterns ())
{
@@ -522,10 +522,10 @@ ResolveExpr::visit (AST::MatchExpr &expr)
ResolveExpr::go (arm.get_guard_expr ().get (), prefix,
canonical_prefix);
- // FIXME: this declaration should be removed after refactoring
- // parse_match_arms_patterns output into a single AltPattern
+ // We know expr.get_patterns () has one pattern at most
+ // so there's no reason to handle it like an AltPattern.
std::vector<PatternBinding> bindings
- = {PatternBinding (PatternBoundCtx::Or, std::set<Identifier> ())};
+ = {PatternBinding (PatternBoundCtx::Product, std::set<Identifier> ())};
// insert any possible new patterns
for (auto &pattern : arm.get_patterns ())
diff --git a/gcc/testsuite/rust/compile/multiple_bindings2.rs b/gcc/testsuite/rust/compile/multiple_bindings2.rs
new file mode 100644
index 0000000..e62b18f
--- /dev/null
+++ b/gcc/testsuite/rust/compile/multiple_bindings2.rs
@@ -0,0 +1,14 @@
+fn main()
+{
+ match (1, 2) {
+ (a, a) => {},
+ }
+ // { dg-error "identifier .a. is bound more than once in the same pattern .E0416." "" { target *-*-* } .-2 }
+
+ if let (a, a) = (1, 2) {}
+ // { dg-error "identifier .a. is bound more than once in the same pattern .E0416." "" { target *-*-* } .-1 }
+
+ let (a, a) = (1, 2);
+ // { dg-error "identifier .a. is bound more than once in the same pattern .E0416." "" { target *-*-* } .-1 }
+
+}