From 4c4a569d37c1d2056b354364679ee79cfac2f4df Mon Sep 17 00:00:00 2001 From: Pierre-Emmanuel Patry Date: Tue, 10 Dec 2024 12:50:43 +0100 Subject: [PATCH] Prevent hir dump from visiting missing types The hir dump was trying to visit init expression and types even when those were missing. gcc/rust/ChangeLog: * hir/rust-hir-dump.cc (Dump::visit): Add check for type and initial expression. Signed-off-by: Pierre-Emmanuel Patry --- gcc/rust/hir/rust-hir-dump.cc | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/gcc/rust/hir/rust-hir-dump.cc b/gcc/rust/hir/rust-hir-dump.cc index 914dbf0e76ca..e4d4f2c38745 100644 --- a/gcc/rust/hir/rust-hir-dump.cc +++ b/gcc/rust/hir/rust-hir-dump.cc @@ -2254,8 +2254,10 @@ Dump::visit (LetStmt &e) put_field ("variable_pattern", e.get_pattern ().as_string ()); - visit_field ("type", e.get_type ()); - visit_field ("init_expr", e.get_init_expr ()); + if (e.has_type ()) + visit_field ("type", e.get_type ()); + if (e.has_init_expr ()) + visit_field ("init_expr", e.get_init_expr ()); end ("LetStmt"); }