public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r14-8859] gccrs: fix bug in pattern check for tuples
@ 2024-02-07 12:44 Arthur Cohen
  0 siblings, 0 replies; only message in thread
From: Arthur Cohen @ 2024-02-07 12:44 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:72a0554c7a269efeb6bb5462c3968f40fdf88fc2

commit r14-8859-g72a0554c7a269efeb6bb5462c3968f40fdf88fc2
Author: Philip Herron <herron.philip@googlemail.com>
Date:   Sun Feb 4 17:07:05 2024 +0000

    gccrs: fix bug in pattern check for tuples
    
    We can point to generic parent types which means we need to do the shallow
    resolve thing that rustc does. We have destructure which is similar to get
    what the parameter type points to.
    
    Fixes #2775
    
    gcc/rust/ChangeLog:
    
            * typecheck/rust-hir-type-check-pattern.cc (TypeCheckPattern::visit): use destructure
    
    gcc/testsuite/ChangeLog:
    
            * rust/compile/issue-2775.rs: New test.
    
    Signed-off-by: Philip Herron <herron.philip@googlemail.com>

Diff:
---
 gcc/rust/typecheck/rust-hir-type-check-pattern.cc |  6 ++++--
 gcc/testsuite/rust/compile/issue-2775.rs          | 11 +++++++++++
 2 files changed, 15 insertions(+), 2 deletions(-)

diff --git a/gcc/rust/typecheck/rust-hir-type-check-pattern.cc b/gcc/rust/typecheck/rust-hir-type-check-pattern.cc
index 19f742f21540..c7f29e28b2de 100644
--- a/gcc/rust/typecheck/rust-hir-type-check-pattern.cc
+++ b/gcc/rust/typecheck/rust-hir-type-check-pattern.cc
@@ -302,7 +302,8 @@ TypeCheckPattern::visit (HIR::TuplePattern &pattern)
 	  = *static_cast<HIR::TuplePatternItemsMultiple *> (
 	    pattern.get_items ().get ());
 
-	if (parent->get_kind () != TyTy::TUPLE)
+	auto resolved_parent = parent->destructure ();
+	if (resolved_parent->get_kind () != TyTy::TUPLE)
 	  {
 	    rust_error_at (pattern.get_locus (), "expected %s, found tuple",
 			   parent->as_string ().c_str ());
@@ -312,7 +313,8 @@ TypeCheckPattern::visit (HIR::TuplePattern &pattern)
 	const auto &patterns = ref.get_patterns ();
 	size_t nitems_to_resolve = patterns.size ();
 
-	TyTy::TupleType &par = *static_cast<TyTy::TupleType *> (parent);
+	TyTy::TupleType &par
+	  = *static_cast<TyTy::TupleType *> (resolved_parent);
 	if (patterns.size () != par.get_fields ().size ())
 	  {
 	    emit_pattern_size_error (pattern, par.get_fields ().size (),
diff --git a/gcc/testsuite/rust/compile/issue-2775.rs b/gcc/testsuite/rust/compile/issue-2775.rs
new file mode 100644
index 000000000000..3ad7085785ea
--- /dev/null
+++ b/gcc/testsuite/rust/compile/issue-2775.rs
@@ -0,0 +1,11 @@
+// { dg-options "-w" }
+#[lang = "sized"]
+pub trait Sized {}
+
+struct Ref<'a, T> {
+    x: &'a T,
+}
+
+pub fn test<'a, 'b, 'c>() {
+    let (_, &&Ref::<(&'_ i32, i32)> { x: &(a, b) }): (i32, &'_ &'b Ref<'b, (&'c i32, i32)>);
+}

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2024-02-07 12:44 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-02-07 12:44 [gcc r14-8859] gccrs: fix bug in pattern check for tuples Arthur Cohen

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).