From 15648d5b8dc5a8cab1b11e14e5e5c178e32ed366 Mon Sep 17 00:00:00 2001 From: Dave Evans Date: Thu, 24 Aug 2023 14:10:42 -0500 Subject: gccrs: Fix typechecking (and compilation) error for alt patterns in match expressions. gcc/rust/ChangeLog: * backend/rust-compile-pattern.cc (CompilePatternCaseLabelExpr::visit): Add AltPattern visitor function * backend/rust-compile-pattern.h: Update CompilePatternCaseLabelExpr::visit(AltPattern&). * typecheck/rust-hir-type-check-pattern.cc (TypeCheckPattern::visit): Update AltPattern visitor gcc/testsuite/ChangeLog: * rust/compile/issue-2431.rs: New test. Signed-off-by: Dave Evans --- gcc/rust/backend/rust-compile-pattern.cc | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'gcc/rust/backend/rust-compile-pattern.cc') diff --git a/gcc/rust/backend/rust-compile-pattern.cc b/gcc/rust/backend/rust-compile-pattern.cc index 38fcedb..66726d2 100644 --- a/gcc/rust/backend/rust-compile-pattern.cc +++ b/gcc/rust/backend/rust-compile-pattern.cc @@ -104,6 +104,17 @@ CompilePatternCaseLabelExpr::visit (HIR::LiteralPattern &pattern) case_label_expr = build_case_label (lit, NULL_TREE, associated_case_label); } +void +CompilePatternCaseLabelExpr::visit (HIR::AltPattern &pattern) +{ + const auto &alts = pattern.get_alts (); + for (auto &alt_pattern : alts) + { + CompilePatternCaseLabelExpr::Compile (alt_pattern.get (), + associated_case_label, ctx); + } +} + static tree compile_range_pattern_bound (HIR::RangePatternBound *bound, Analysis::NodeMapping mappings, location_t locus, -- cgit v1.1