From aa0255591592df1a94f1956737f30b434962dc99 Mon Sep 17 00:00:00 2001 From: Philip Herron Date: Tue, 21 Jan 2025 17:19:13 +0000 Subject: gccrs: catch missing guard for optional result When we lookup here it returns an optional which can lead to a crash because it needs a guard if it has a value. gcc/rust/ChangeLog: * backend/rust-compile-resolve-path.cc (HIRCompileBase::query_compile): add guard gcc/testsuite/ChangeLog: * rust/compile/nr2/exclude: these tests now work it seems Signed-off-by: Philip Herron --- gcc/rust/backend/rust-compile-resolve-path.cc | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) (limited to 'gcc/rust/backend') diff --git a/gcc/rust/backend/rust-compile-resolve-path.cc b/gcc/rust/backend/rust-compile-resolve-path.cc index 69599cc..d248ee2 100644 --- a/gcc/rust/backend/rust-compile-resolve-path.cc +++ b/gcc/rust/backend/rust-compile-resolve-path.cc @@ -248,12 +248,9 @@ HIRCompileBase::query_compile (HirId ref, TyTy::BaseType *lookup, return CompileInherentImplItem::Compile (resolved_item->first, ctx, lookup, true, expr_locus); } - else + else if (auto trait_item + = ctx->get_mappings ().lookup_hir_trait_item (ref)) { - // it might be resolved to a trait item - tl::optional trait_item - = ctx->get_mappings ().lookup_hir_trait_item (ref); - HIR::Trait *trait = ctx->get_mappings ().lookup_trait_item_mapping ( trait_item.value ()->get_mappings ().get_hirid ()); -- cgit v1.1