[COMMITTED 103/146] gccrs: fix ICE with hir dump on closure

arthur.cohen@embecosm.com arthur.cohen@embecosm.com
Fri Mar 21 12:06:44 GMT 2025


From: Philip Herron <herron.philip@googlemail.com>

Return type and parameter types are optional on closures.

gcc/rust/ChangeLog:

	* hir/rust-hir-dump.cc (Dump::visit): add null guard

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
---
 gcc/rust/hir/rust-hir-dump.cc | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/gcc/rust/hir/rust-hir-dump.cc b/gcc/rust/hir/rust-hir-dump.cc
index 5acf53e9296..798179d172e 100644
--- a/gcc/rust/hir/rust-hir-dump.cc
+++ b/gcc/rust/hir/rust-hir-dump.cc
@@ -1244,13 +1244,17 @@ Dump::visit (ClosureExpr &e)
 	  auto oa = param.get_outer_attrs ();
 	  do_outer_attrs (oa);
 	  visit_field ("pattern", param.get_pattern ());
-	  visit_field ("type", param.get_type ());
+
+	  if (param.has_type_given ())
+	    visit_field ("type", param.get_type ());
+
 	  end ("ClosureParam");
 	}
       end_field ("params");
     }
 
-  visit_field ("return_type", e.get_return_type ());
+  if (e.has_return_type ())
+    visit_field ("return_type", e.get_return_type ());
 
   visit_field ("expr", e.get_expr ());
   end ("ClosureExpr");
-- 
2.45.2



More information about the Gcc-rust mailing list