Skip to content

Commit 1be610a

Browse files
bors[bot]diohabara
andauthored
Merge #783
783: Get rid of lambda within `AST::TypePath` and provide a method to return a reference r=philberty a=diohabara ## Related issue This PR will fix <#718> - \[x] GCC development requires copyright assignment or the Developer's Certificate of Origin sign-off, see https://gcc.gnu.org/contribute.html or https://gcc.gnu.org/dco.html - \[x] Read contributing guidlines - \[x] `make check-rust` passes locally - \[x] Run `clang-format` - \[x] Added any relevant test cases to `gcc/testsuite/rust/` Note that you can skip the above if you are just opening a WIP PR in order to get feedback. Co-authored-by: Kadoi Takemaru <[email protected]>
2 parents ca0b06f + 66832f3 commit 1be610a

File tree

3 files changed

+24
-46
lines changed

3 files changed

+24
-46
lines changed

gcc/rust/ast/rust-path.h

-18
Original file line numberDiff line numberDiff line change
@@ -754,15 +754,6 @@ class TypePath : public TypeNoBounds
754754
}
755755

756756
size_t get_num_segments () const { return segments.size (); }
757-
758-
void iterate_segments (std::function<bool (TypePathSegment *)> cb)
759-
{
760-
for (auto it = segments.begin (); it != segments.end (); it++)
761-
{
762-
if (!cb ((*it).get ()))
763-
return;
764-
}
765-
}
766757
};
767758

768759
struct QualifiedPathType
@@ -1029,15 +1020,6 @@ class QualifiedPathInType : public TypeNoBounds
10291020
}
10301021

10311022
Location get_locus () const override final { return locus; }
1032-
1033-
void iterate_segments (std::function<bool (TypePathSegment *)> cb)
1034-
{
1035-
for (auto it = segments.begin (); it != segments.end (); it++)
1036-
{
1037-
if (!cb ((*it).get ()))
1038-
return;
1039-
}
1040-
}
10411023
};
10421024
} // namespace AST
10431025
} // namespace Rust

gcc/rust/hir/rust-ast-lower-type.h

+12-14
Original file line numberDiff line numberDiff line change
@@ -62,20 +62,18 @@ class ASTLowerTypePath : public ASTLoweringBase
6262
{
6363
std::vector<std::unique_ptr<HIR::TypePathSegment>> translated_segments;
6464

65-
path.iterate_segments ([&] (AST::TypePathSegment *seg) mutable -> bool {
66-
translated_segment = nullptr;
67-
seg->accept_vis (*this);
68-
if (translated_segment == nullptr)
69-
{
70-
rust_fatal_error (seg->get_locus (),
71-
"failed to translate AST TypePathSegment");
72-
return false;
73-
}
74-
75-
translated_segments.push_back (
76-
std::unique_ptr<HIR::TypePathSegment> (translated_segment));
77-
return true;
78-
});
65+
for (auto &seg : path.get_segments ())
66+
{
67+
translated_segment = nullptr;
68+
seg->accept_vis (*this);
69+
if (translated_segment == nullptr)
70+
{
71+
rust_fatal_error (seg->get_locus (),
72+
"failed to translate AST TypePathSegment");
73+
}
74+
translated_segments.push_back (
75+
std::unique_ptr<HIR::TypePathSegment> (translated_segment));
76+
}
7977

8078
auto crate_num = mappings->get_current_crate ();
8179
auto hirid = mappings->get_next_hir_id (crate_num);

gcc/rust/hir/rust-ast-lower.cc

+12-14
Original file line numberDiff line numberDiff line change
@@ -490,20 +490,18 @@ ASTLowerQualifiedPathInType::visit (AST::QualifiedPathInType &path)
490490
std::unique_ptr<HIR::TypePathSegment> associated_segment (translated_segment);
491491

492492
std::vector<std::unique_ptr<HIR::TypePathSegment> > translated_segments;
493-
path.iterate_segments ([&] (AST::TypePathSegment *seg) mutable -> bool {
494-
translated_segment = nullptr;
495-
seg->accept_vis (*this);
496-
if (translated_segment == nullptr)
497-
{
498-
rust_fatal_error (seg->get_locus (),
499-
"failed to translate AST TypePathSegment");
500-
return false;
501-
}
502-
503-
translated_segments.push_back (
504-
std::unique_ptr<HIR::TypePathSegment> (translated_segment));
505-
return true;
506-
});
493+
for (auto &seg : path.get_segments ())
494+
{
495+
translated_segment = nullptr;
496+
seg->accept_vis (*this);
497+
if (translated_segment == nullptr)
498+
{
499+
rust_fatal_error (seg->get_locus (),
500+
"failed to translte AST TypePathSegment");
501+
}
502+
translated_segments.push_back (
503+
std::unique_ptr<HIR::TypePathSegment> (translated_segment));
504+
}
507505

508506
Analysis::NodeMapping mapping (crate_num, path.get_node_id (), hirid,
509507
mappings->get_next_localdef_id (crate_num));

0 commit comments

Comments
 (0)