Skip to content

Commit 425905b

Browse files
bors[bot]mvvsmk
andauthored
Merge #942
942: Removed Lambda Function within AST::PathPattern r=philberty a=mvvsmk Addresses issue #717 1) Changed the rust-path.h and removed the iterate_path_segments fuction. 2) Removed the lambda fuction form rust-ast-lower.cc and replaced it with a for loop. Do let me know if I missed anything or could improve on something. Signed-off-by : M V V S Manoj Kumar <[email protected]> Co-authored-by: M V V S Manoj Kumar <[email protected]>
2 parents fbe22e8 + ee41313 commit 425905b

File tree

2 files changed

+21
-29
lines changed

2 files changed

+21
-29
lines changed

gcc/rust/ast/rust-path.h

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -305,15 +305,6 @@ class PathPattern : public Pattern
305305
// TODO: this seems kinda dodgy
306306
std::vector<PathExprSegment> &get_segments () { return segments; }
307307
const std::vector<PathExprSegment> &get_segments () const { return segments; }
308-
309-
void iterate_path_segments (std::function<bool (PathExprSegment &)> cb)
310-
{
311-
for (auto it = segments.begin (); it != segments.end (); it++)
312-
{
313-
if (!cb (*it))
314-
return;
315-
}
316-
}
317308
};
318309

319310
/* AST node representing a path-in-expression pattern (path that allows generic

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

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -263,17 +263,17 @@ void
263263
ASTLowerPathInExpression::visit (AST::PathInExpression &expr)
264264
{
265265
std::vector<HIR::PathExprSegment> path_segments;
266-
expr.iterate_path_segments ([&] (AST::PathExprSegment &s) mutable -> bool {
267-
path_segments.push_back (lower_path_expr_seg (s));
268-
269-
// insert the mappings for the segment
270-
HIR::PathExprSegment *lowered_seg = &path_segments.back ();
271-
mappings->insert_hir_path_expr_seg (
272-
lowered_seg->get_mappings ().get_crate_num (),
273-
lowered_seg->get_mappings ().get_hirid (), lowered_seg);
274-
return true;
275-
});
266+
auto &segments = expr.get_segments ();
267+
for (auto &s : segments)
268+
{
269+
path_segments.push_back (lower_path_expr_seg ((s)));
276270

271+
// insert the mappings for the segment
272+
HIR::PathExprSegment *lowered_seg = &path_segments.back ();
273+
mappings->insert_hir_path_expr_seg (
274+
lowered_seg->get_mappings ().get_crate_num (),
275+
lowered_seg->get_mappings ().get_hirid (), lowered_seg);
276+
}
277277
auto crate_num = mappings->get_current_crate ();
278278
Analysis::NodeMapping mapping (crate_num, expr.get_node_id (),
279279
mappings->get_next_hir_id (crate_num),
@@ -311,16 +311,17 @@ ASTLowerQualPathInExpression::visit (AST::QualifiedPathInExpression &expr)
311311
= lower_qual_path_type (expr.get_qualified_path_type ());
312312

313313
std::vector<HIR::PathExprSegment> path_segments;
314-
expr.iterate_path_segments ([&] (AST::PathExprSegment &s) mutable -> bool {
315-
path_segments.push_back (lower_path_expr_seg (s));
316-
317-
// insert the mappings for the segment
318-
HIR::PathExprSegment *lowered_seg = &path_segments.back ();
319-
mappings->insert_hir_path_expr_seg (
320-
lowered_seg->get_mappings ().get_crate_num (),
321-
lowered_seg->get_mappings ().get_hirid (), lowered_seg);
322-
return true;
323-
});
314+
auto &segments = expr.get_segments ();
315+
for (auto &s : segments)
316+
{
317+
path_segments.push_back (lower_path_expr_seg ((s)));
318+
319+
// insert the mappings for the segment
320+
HIR::PathExprSegment *lowered_seg = &path_segments.back ();
321+
mappings->insert_hir_path_expr_seg (
322+
lowered_seg->get_mappings ().get_crate_num (),
323+
lowered_seg->get_mappings ().get_hirid (), lowered_seg);
324+
}
324325

325326
auto crate_num = mappings->get_current_crate ();
326327
Analysis::NodeMapping mapping (crate_num, expr.get_node_id (),

0 commit comments

Comments
 (0)