Skip to content

Commit 086b7f9

Browse files
dkmphilberty
authored andcommitted
gccrs: Cleanup HIR dump
visit_field() correctly handles empty unique_ptr<> and displays "none". gcc/rust/ChangeLog: * hir/rust-hir-dump.cc (Dump::visit): Remove useless if/else already handled by visit_field. Signed-off-by: Marc Poulhiès <[email protected]>
1 parent c10d668 commit 086b7f9

File tree

1 file changed

+10
-37
lines changed

1 file changed

+10
-37
lines changed

gcc/rust/hir/rust-hir-dump.cc

Lines changed: 10 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ namespace HIR {
3535
// field: ...
3636
// ]
3737
//
38-
// When a field is a collection of other HIR object:
38+
// When a field is a collection of other HIR objects:
3939
// field {
4040
// SomeHIRNode [ ... ]
4141
// SomeOtherHIRNode [ ... ]
@@ -1214,19 +1214,13 @@ Dump::visit (ClosureExpr &e)
12141214
auto oa = param.get_outer_attrs ();
12151215
do_outer_attrs (oa);
12161216
visit_field ("pattern", param.get_pattern ());
1217-
if (param.has_type_given ())
1218-
visit_field ("type", param.get_type ());
1219-
else
1220-
put_field ("type", "none");
1217+
visit_field ("type", param.get_type ());
12211218
end ("ClosureParam");
12221219
}
12231220
end_field ("params");
12241221
}
12251222

1226-
if (e.has_return_type ())
1227-
visit_field ("return_type", *e.get_return_type ());
1228-
else
1229-
put_field ("return_type", "none");
1223+
visit_field ("return_type", e.get_return_type ());
12301224

12311225
visit_field ("expr", e.get_expr ());
12321226
end ("ClosureExpr");
@@ -1241,10 +1235,7 @@ Dump::visit (BlockExpr &e)
12411235

12421236
visit_collection ("statements", e.get_statements ());
12431237

1244-
if (e.has_expr ())
1245-
visit_field ("expr", e.get_final_expr ());
1246-
else
1247-
put_field ("expr", "none");
1238+
visit_field ("expr", e.get_final_expr ());
12481239

12491240
end ("BlockExpr");
12501241
}
@@ -1273,10 +1264,7 @@ Dump::visit (BreakExpr &e)
12731264
else
12741265
put_field ("label", "none");
12751266

1276-
if (e.has_break_expr ())
1277-
visit_field ("break_expr ", e.get_expr ());
1278-
else
1279-
put_field ("break_expr ", "none");
1267+
visit_field ("break_expr ", e.get_expr ());
12801268

12811269
end ("BreakExpr");
12821270
}
@@ -1346,10 +1334,7 @@ Dump::visit (ReturnExpr &e)
13461334
begin ("ReturnExpr");
13471335
do_mappings (e.get_mappings ());
13481336

1349-
if (e.has_return_expr ())
1350-
visit_field ("return_expr", e.get_expr ());
1351-
else
1352-
put_field ("return_expr", "none");
1337+
visit_field ("return_expr", e.get_expr ());
13531338

13541339
end ("ReturnExpr");
13551340
}
@@ -1496,10 +1481,7 @@ Dump::visit (TypeParam &e)
14961481

14971482
visit_collection ("type_param_bounds", e.get_type_param_bounds ());
14981483

1499-
if (e.has_type ())
1500-
visit_field ("type", e.get_type ());
1501-
else
1502-
put_field ("type", "none");
1484+
visit_field ("type", e.get_type ());
15031485

15041486
end ("TypeParam");
15051487
}
@@ -1665,10 +1647,7 @@ Dump::visit (Function &e)
16651647
put_field ("function_params", "empty");
16661648
}
16671649

1668-
if (e.has_function_return_type ())
1669-
visit_field ("return_type", *e.get_return_type ());
1670-
else
1671-
put_field ("return_type", "none");
1650+
visit_field ("return_type", e.get_return_type ());
16721651

16731652
if (!e.has_where_clause ())
16741653
put_field ("where_clause", "none");
@@ -1901,10 +1880,7 @@ Dump::visit (TraitItemFunc &e)
19011880

19021881
do_traitfunctiondecl (e.get_decl ());
19031882

1904-
if (e.has_definition ())
1905-
visit_field ("block_expr", e.get_block_expr ());
1906-
else
1907-
put_field ("block_expr", "none");
1883+
visit_field ("block_expr", e.get_block_expr ());
19081884

19091885
end ("TraitItemFunc");
19101886
}
@@ -2019,10 +1995,7 @@ Dump::visit (ExternalFunctionItem &e)
20191995

20201996
put_field ("has_variadics", std::to_string (e.is_variadic ()));
20211997

2022-
if (e.has_return_type ())
2023-
visit_field ("return_type", e.get_return_type ());
2024-
else
2025-
put_field ("return_type", "none");
1998+
visit_field ("return_type", e.get_return_type ());
20261999

20272000
end ("ExternalFunctionItem");
20282001
}

0 commit comments

Comments
 (0)