aboutsummaryrefslogtreecommitdiff
path: root/gcc/rust/backend/rust-compile-pattern.cc
diff options
context:
space:
mode:
authorOwen Avery <powerboat9.gamer@gmail.com>2025-04-30 16:20:53 -0400
committerPhilip Herron <philip.herron@embecosm.com>2025-05-07 15:34:59 +0000
commit8592769349a33ff1fca3777021ad6ea8dab56c7d (patch)
tree72e7e491e5b6cebb6ca942587a46d6622f869f0f /gcc/rust/backend/rust-compile-pattern.cc
parent98573bd61ef95e4224bc2d050fa1f47d893f2c31 (diff)
downloadgcc-8592769349a33ff1fca3777021ad6ea8dab56c7d.zip
gcc-8592769349a33ff1fca3777021ad6ea8dab56c7d.tar.gz
gcc-8592769349a33ff1fca3777021ad6ea8dab56c7d.tar.bz2
Revert "backend: Remove checks on StructFieldIdentPattern"
This reverts commit 92323dd3bb16f21194891ce463fc865598c6980f.
Diffstat (limited to 'gcc/rust/backend/rust-compile-pattern.cc')
-rw-r--r--gcc/rust/backend/rust-compile-pattern.cc32
1 files changed, 25 insertions, 7 deletions
diff --git a/gcc/rust/backend/rust-compile-pattern.cc b/gcc/rust/backend/rust-compile-pattern.cc
index 671025a..94844fe 100644
--- a/gcc/rust/backend/rust-compile-pattern.cc
+++ b/gcc/rust/backend/rust-compile-pattern.cc
@@ -259,16 +259,34 @@ CompilePatternCheckExpr::visit (HIR::StructPattern &pattern)
}
break;
- case HIR::StructPatternField::ItemType::IDENT_PAT:
- // we only support rebinding patterns at the moment, which always
- // match - so do nothing
+ case HIR::StructPatternField::ItemType::IDENT_PAT: {
+ HIR::StructPatternFieldIdentPat &ident
+ = static_cast<HIR::StructPatternFieldIdentPat &> (*field.get ());
+
+ size_t offs = 0;
+ ok = variant->lookup_field (ident.get_identifier ().as_string (),
+ nullptr, &offs);
+ rust_assert (ok);
- // this needs to change once we actually check that the field
- // matches a certain value, either a literal value or a const one
+ // we may be offsetting by + 1 here since the first field in the
+ // record is always the discriminator
+ offs += adt->is_enum ();
+ tree field_expr
+ = Backend::struct_field_expression (match_scrutinee_expr, offs,
+ ident.get_locus ());
+
+ tree check_expr_sub
+ = CompilePatternCheckExpr::Compile (ident.get_pattern (),
+ field_expr, ctx);
+ check_expr = Backend::arithmetic_or_logical_expression (
+ ArithmeticOrLogicalOperator::BITWISE_AND, check_expr,
+ check_expr_sub, ident.get_pattern ().get_locus ());
+ }
break;
- case HIR::StructPatternField::ItemType::IDENT:
- // ident pattern always matches - do nothing
+ case HIR::StructPatternField::ItemType::IDENT: {
+ // ident pattern always matches - do nothing
+ }
break;
}
}