aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorPhilip Herron <philip.herron@embecosm.com>2021-04-28 12:46:21 +0100
committerPhilip Herron <philip.herron@embecosm.com>2021-04-28 12:49:41 +0100
commite547f7da588f596bf26923b12ba873878e05d51c (patch)
treee8e59b34c0c4bba0c932b172b6adc76d557f3b6b /gcc
parentff1676e277af52b6aa19e45494d91a810a1c2070 (diff)
downloadgcc-e547f7da588f596bf26923b12ba873878e05d51c.zip
gcc-e547f7da588f596bf26923b12ba873878e05d51c.tar.gz
gcc-e547f7da588f596bf26923b12ba873878e05d51c.tar.bz2
Tuples can contain TypeParameters
TypeParameters can be behind held within Tuples which need substitution but these types cannot hold substitution mappings. Fixes #396
Diffstat (limited to 'gcc')
-rw-r--r--gcc/rust/typecheck/rust-substitution-mapper.h5
-rw-r--r--gcc/rust/typecheck/rust-tyty.cc23
-rw-r--r--gcc/rust/typecheck/rust-tyty.h12
-rw-r--r--gcc/testsuite/rust.test/compile/generics22.rs13
4 files changed, 52 insertions, 1 deletions
diff --git a/gcc/rust/typecheck/rust-substitution-mapper.h b/gcc/rust/typecheck/rust-substitution-mapper.h
index 23105d6..739f1b5 100644
--- a/gcc/rust/typecheck/rust-substitution-mapper.h
+++ b/gcc/rust/typecheck/rust-substitution-mapper.h
@@ -154,7 +154,10 @@ public:
}
// these don't support generic arguments but might contain a type param
- void visit (TyTy::TupleType &) override { gcc_unreachable (); }
+ void visit (TyTy::TupleType &type) override
+ {
+ resolved = type.handle_substitions (mappings);
+ }
void visit (TyTy::ReferenceType &type) override
{
diff --git a/gcc/rust/typecheck/rust-tyty.cc b/gcc/rust/typecheck/rust-tyty.cc
index cc6c2f8..b75c139 100644
--- a/gcc/rust/typecheck/rust-tyty.cc
+++ b/gcc/rust/typecheck/rust-tyty.cc
@@ -540,6 +540,29 @@ TupleType::clone ()
get_combined_refs ());
}
+TupleType *
+TupleType::handle_substitions (SubstitutionArgumentMappings mappings)
+{
+ auto mappings_table = Analysis::Mappings::get ();
+
+ TupleType *tuple = static_cast<TupleType *> (clone ());
+ tuple->set_ty_ref (mappings_table->get_next_hir_id ());
+
+ for (size_t i = 0; i < tuple->fields.size (); i++)
+ {
+ TyVar &field = fields.at (i);
+ if (field.get_tyty ()->contains_type_parameters ())
+ {
+ BaseType *concrete
+ = Resolver::SubstMapperInternal::Resolve (field.get_tyty (),
+ mappings);
+ tuple->fields[i] = TyVar (concrete->get_ty_ref ());
+ }
+ }
+
+ return tuple;
+}
+
void
FnType::accept_vis (TyVisitor &vis)
{
diff --git a/gcc/rust/typecheck/rust-tyty.h b/gcc/rust/typecheck/rust-tyty.h
index 0c8168d..bcc694b 100644
--- a/gcc/rust/typecheck/rust-tyty.h
+++ b/gcc/rust/typecheck/rust-tyty.h
@@ -379,6 +379,18 @@ public:
std::string get_name () const override final { return as_string (); }
+ bool contains_type_parameters () const override final
+ {
+ for (auto &f : fields)
+ {
+ if (f.get_tyty ()->contains_type_parameters ())
+ return true;
+ }
+ return false;
+ }
+
+ TupleType *handle_substitions (SubstitutionArgumentMappings mappings);
+
private:
std::vector<TyVar> fields;
};
diff --git a/gcc/testsuite/rust.test/compile/generics22.rs b/gcc/testsuite/rust.test/compile/generics22.rs
new file mode 100644
index 0000000..465ebb0
--- /dev/null
+++ b/gcc/testsuite/rust.test/compile/generics22.rs
@@ -0,0 +1,13 @@
+fn callee<T>(t: (T, bool)) -> i32 {
+ // { dg-warning "unused name" "" { target *-*-* } .-1 }
+ 32
+}
+
+fn caller(t: i32) -> i32 {
+ callee((t, false))
+}
+
+fn main() {
+ let a;
+ a = caller(123);
+}