aboutsummaryrefslogtreecommitdiff
path: root/gcc/rust/backend/rust-compile-pattern.h
diff options
context:
space:
mode:
authorPhilip Herron <herron.philip@googlemail.com>2024-12-13 15:51:55 +0000
committerPhilip Herron <philip.herron@embecosm.com>2024-12-13 16:55:07 +0000
commitdaa2977f3d52968506a396523f47ab52e0e3a90a (patch)
tree6f6636c8c895f9aed3ca71211844a6ab5655f3af /gcc/rust/backend/rust-compile-pattern.h
parentcc2445cd799fb5a88011ce9945afcdb9d2ca3219 (diff)
downloadgcc-daa2977f3d52968506a396523f47ab52e0e3a90a.zip
gcc-daa2977f3d52968506a396523f47ab52e0e3a90a.tar.gz
gcc-daa2977f3d52968506a396523f47ab52e0e3a90a.tar.bz2
gccrs: implement the TuplePattern and use it for function patterns
In order to handle the tuple pattern of: fn test ((x _) : (i32, i32)) -> i32 { x } we need to recognize that ABI wise this function still takes a tuple as the parameter to this function its just how we can address the "pattern" of the tuple changes. So reall if this was C it would look like: void test (struct tuple_type __prameter) { return __parameter.0 } The code here reuses our existing pattern code so that we generate these implicit bindings of the paramter with a field access so any time x is referenced it's really just emplacing __parameter.0 for the field access into the struct which is a tuple. Fixes Rust-GCC#2847 gcc/rust/ChangeLog: * backend/rust-compile-fnparam.cc (CompileFnParam::visit): compile tuple patterns (CompileSelfParam::compile): update return type (CompileFnParam::create_tmp_param_var): return Bvariable not tree to stop ICE * backend/rust-compile-fnparam.h: update prototype * backend/rust-compile-pattern.cc (CompilePatternBindings::visit): implement TuplePattern * backend/rust-compile-pattern.h: update prototype gcc/testsuite/ChangeLog: * rust/compile/issue-2847.rs: New test. Signed-off-by: Philip Herron <herron.philip@googlemail.com>
Diffstat (limited to 'gcc/rust/backend/rust-compile-pattern.h')
-rw-r--r--gcc/rust/backend/rust-compile-pattern.h2
1 files changed, 1 insertions, 1 deletions
diff --git a/gcc/rust/backend/rust-compile-pattern.h b/gcc/rust/backend/rust-compile-pattern.h
index 01fd097..fc12859 100644
--- a/gcc/rust/backend/rust-compile-pattern.h
+++ b/gcc/rust/backend/rust-compile-pattern.h
@@ -82,6 +82,7 @@ public:
void visit (HIR::TupleStructPattern &pattern) override;
void visit (HIR::ReferencePattern &pattern) override;
void visit (HIR::IdentifierPattern &) override;
+ void visit (HIR::TuplePattern &pattern) override;
// Empty visit for unused Pattern HIR nodes.
void visit (HIR::AltPattern &) override {}
@@ -90,7 +91,6 @@ public:
void visit (HIR::QualifiedPathInExpression &) override {}
void visit (HIR::RangePattern &) override {}
void visit (HIR::SlicePattern &) override {}
- void visit (HIR::TuplePattern &) override {}
void visit (HIR::WildcardPattern &) override {}
protected: