Skip to content

Commit 674221a

Browse files
bors[bot]cls
andauthored
Merge #791
791: Replace TyTy::TupleType::iterate_fields with a new function get_fields r=philberty a=cls This PR replaces TyTy::TupleType::iterate_fields with a new function get_fields. In #735, `@philberty` mentions two possible implementations of get_fields, one that returns `std::vector<TyVar>&` and one that returns a new `std::vector<BaseType *>`. I've included two commits, the first doing the former and second going on to do the latter. I'm happy with one or both being merged. This is my first PR, so please let me know if I've missed anything! Thanks. Fixes #735 Co-authored-by: Connor Lane Smith <[email protected]>
2 parents 5f0df48 + c8ee62e commit 674221a

File tree

2 files changed

+6
-13
lines changed

2 files changed

+6
-13
lines changed

gcc/rust/typecheck/rust-tyty.cc

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -788,11 +788,11 @@ std::string
788788
TupleType::as_string () const
789789
{
790790
std::string fields_buffer;
791-
iterate_fields ([&] (BaseType *field) mutable -> bool {
792-
fields_buffer += field->as_string ();
793-
fields_buffer += ", ";
794-
return true;
795-
});
791+
for (const TyVar &field : get_fields ())
792+
{
793+
fields_buffer += field.get_tyty ()->as_string ();
794+
fields_buffer += ", ";
795+
}
796796
return "(" + fields_buffer + ")";
797797
}
798798

gcc/rust/typecheck/rust-tyty.h

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -642,14 +642,7 @@ class TupleType : public BaseType
642642
return true;
643643
}
644644

645-
void iterate_fields (std::function<bool (BaseType *)> cb) const
646-
{
647-
for (size_t i = 0; i < num_fields (); i++)
648-
{
649-
if (!cb (get_field (i)))
650-
return;
651-
}
652-
}
645+
const std::vector<TyVar> &get_fields () const { return fields; }
653646

654647
std::string get_name () const override final { return as_string (); }
655648

0 commit comments

Comments
 (0)