diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2021-11-03 15:54:51 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-11-03 15:54:51 +0000 |
commit | 674221a3b27f5455fddc793ec9aaf30a4d858ecb (patch) | |
tree | a2e847b9bedd6b3e46550d1b0c370092f28547e0 /gcc | |
parent | 5f0df4812c37fc428b5508e019e9fb7f8a7b77b1 (diff) | |
parent | c8ee62ed4535cfa314f12535a3cbbe3cc135872d (diff) | |
download | gcc-674221a3b27f5455fddc793ec9aaf30a4d858ecb.zip gcc-674221a3b27f5455fddc793ec9aaf30a4d858ecb.tar.gz gcc-674221a3b27f5455fddc793ec9aaf30a4d858ecb.tar.bz2 |
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 <cls@lubutu.com>
Diffstat (limited to 'gcc')
-rw-r--r-- | gcc/rust/typecheck/rust-tyty.cc | 10 | ||||
-rw-r--r-- | gcc/rust/typecheck/rust-tyty.h | 9 |
2 files changed, 6 insertions, 13 deletions
diff --git a/gcc/rust/typecheck/rust-tyty.cc b/gcc/rust/typecheck/rust-tyty.cc index 16cabc8..b3ceb06 100644 --- a/gcc/rust/typecheck/rust-tyty.cc +++ b/gcc/rust/typecheck/rust-tyty.cc @@ -788,11 +788,11 @@ std::string TupleType::as_string () const { std::string fields_buffer; - iterate_fields ([&] (BaseType *field) mutable -> bool { - fields_buffer += field->as_string (); - fields_buffer += ", "; - return true; - }); + for (const TyVar &field : get_fields ()) + { + fields_buffer += field.get_tyty ()->as_string (); + fields_buffer += ", "; + } return "(" + fields_buffer + ")"; } diff --git a/gcc/rust/typecheck/rust-tyty.h b/gcc/rust/typecheck/rust-tyty.h index 5ffd95c..c26e193 100644 --- a/gcc/rust/typecheck/rust-tyty.h +++ b/gcc/rust/typecheck/rust-tyty.h @@ -642,14 +642,7 @@ public: return true; } - void iterate_fields (std::function<bool (BaseType *)> cb) const - { - for (size_t i = 0; i < num_fields (); i++) - { - if (!cb (get_field (i))) - return; - } - } + const std::vector<TyVar> &get_fields () const { return fields; } std::string get_name () const override final { return as_string (); } |