diff options
author | Philip Herron <herron.philip@googlemail.com> | 2025-01-21 17:19:13 +0000 |
---|---|---|
committer | CohenArthur <arthur.cohen@embecosm.com> | 2025-01-28 14:08:06 +0000 |
commit | 60e0d0453fbddef7cf8495f896f9ac189f4d7e17 (patch) | |
tree | 9d121e8a49ab52b51bf4d2cf2e48df0b03319ea3 /gcc/rust/backend/rust-compile-resolve-path.cc | |
parent | a3e147802e38ec7fc027d4b4116e110ac0a0d7b8 (diff) | |
download | gcc-60e0d0453fbddef7cf8495f896f9ac189f4d7e17.zip gcc-60e0d0453fbddef7cf8495f896f9ac189f4d7e17.tar.gz gcc-60e0d0453fbddef7cf8495f896f9ac189f4d7e17.tar.bz2 |
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 <herron.philip@googlemail.com>
Diffstat (limited to 'gcc/rust/backend/rust-compile-resolve-path.cc')
-rw-r--r-- | gcc/rust/backend/rust-compile-resolve-path.cc | 7 |
1 files changed, 2 insertions, 5 deletions
diff --git a/gcc/rust/backend/rust-compile-resolve-path.cc b/gcc/rust/backend/rust-compile-resolve-path.cc index 049b0d8..74e95e5 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<HIR::TraitItem *> 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 ()); |