aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorYap Zhi Heng <yapzhhg@gmail.com>2025-07-20 15:55:51 +0800
committerArthur Cohen <arthur.cohen@embecosm.com>2025-08-05 16:36:58 +0200
commit495765758a3c434c6767610f377cace4bba8ff1c (patch)
treea428668cc1e295fe303e6133331e41da89fe2609 /gcc
parent499a70699bcaff13998fa8eb6136c15dfa0b7f41 (diff)
downloadgcc-495765758a3c434c6767610f377cace4bba8ff1c.zip
gcc-495765758a3c434c6767610f377cace4bba8ff1c.tar.gz
gcc-495765758a3c434c6767610f377cace4bba8ff1c.tar.bz2
gccrs: Update SlicePattern typechecking against slice reference parents
gcc/rust/ChangeLog: * typecheck/rust-hir-type-check-pattern.cc (TypeCheckPattern::visit(SlicePattern)): Add new type check case for SliceType wrapped in ReferenceType. * backend/rust-compile-pattern.cc: Adjusted the asserts accordingly for CompilePatternCheckExpr(SlicePattern) & CompilePatternBindings(SlicePattern). Signed-off-by: Yap Zhi Heng <yapzhhg@gmail.com>
Diffstat (limited to 'gcc')
-rw-r--r--gcc/rust/backend/rust-compile-pattern.cc6
-rw-r--r--gcc/rust/typecheck/rust-hir-type-check-pattern.cc17
2 files changed, 19 insertions, 4 deletions
diff --git a/gcc/rust/backend/rust-compile-pattern.cc b/gcc/rust/backend/rust-compile-pattern.cc
index 6d889ba..e00de4f 100644
--- a/gcc/rust/backend/rust-compile-pattern.cc
+++ b/gcc/rust/backend/rust-compile-pattern.cc
@@ -529,7 +529,8 @@ CompilePatternCheckExpr::visit (HIR::SlicePattern &pattern)
// pattern must either be ArrayType or SliceType, should be already confirmed
// by type checking
rust_assert (lookup->get_kind () == TyTy::TypeKind::ARRAY
- || lookup->get_kind () == TyTy::TypeKind::SLICE);
+ || lookup->get_kind () == TyTy::TypeKind::SLICE
+ || lookup->get_kind () == TyTy::REF);
size_t array_element_index = 0;
switch (lookup->get_kind ())
@@ -895,7 +896,8 @@ CompilePatternBindings::visit (HIR::SlicePattern &pattern)
rust_assert (ok);
rust_assert (lookup->get_kind () == TyTy::TypeKind::ARRAY
- || lookup->get_kind () == TyTy::TypeKind::SLICE);
+ || lookup->get_kind () == TyTy::TypeKind::SLICE
+ || lookup->get_kind () == TyTy::REF);
size_t array_element_index = 0;
switch (lookup->get_kind ())
diff --git a/gcc/rust/typecheck/rust-hir-type-check-pattern.cc b/gcc/rust/typecheck/rust-hir-type-check-pattern.cc
index bb0e27b..13fc9c8 100644
--- a/gcc/rust/typecheck/rust-hir-type-check-pattern.cc
+++ b/gcc/rust/typecheck/rust-hir-type-check-pattern.cc
@@ -675,8 +675,21 @@ TypeCheckPattern::visit (HIR::SlicePattern &pattern)
}
case TyTy::SLICE:
{
- auto &array_ty_ty = static_cast<TyTy::SliceType &> (*parent);
- parent_element_ty = array_ty_ty.get_element_type ();
+ auto &slice_ty_ty = static_cast<TyTy::SliceType &> (*parent);
+ parent_element_ty = slice_ty_ty.get_element_type ();
+ break;
+ }
+ case TyTy::REF:
+ {
+ auto &ref_ty_ty = static_cast<TyTy::ReferenceType &> (*parent);
+ const TyTy::SliceType *slice = nullptr;
+ if (!ref_ty_ty.is_dyn_slice_type (&slice))
+ {
+ rust_error_at (pattern.get_locus (), "expected %s, found slice",
+ parent->as_string ().c_str ());
+ return;
+ }
+ parent_element_ty = slice->get_element_type ();
break;
}
default: