From: Arthur Cohen Date: Thu, 26 Dec 2024 23:00:08 +0000 (+0000) Subject: gccrs: mappings: Add get_lang_item_node X-Git-Tag: basepoints/gcc-16~929 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=4d0cfd5b6f179081ab5fa412a8dd1d7762e9403c;p=thirdparty%2Fgcc.git gccrs: mappings: Add get_lang_item_node This method errors out if the lang item has not been declared yet. gcc/rust/ChangeLog: * util/rust-hir-map.cc (Mappings::get_lang_item_node): New. * util/rust-hir-map.h: New function. --- diff --git a/gcc/rust/util/rust-hir-map.cc b/gcc/rust/util/rust-hir-map.cc index f11a77954ae..b94591e014c 100644 --- a/gcc/rust/util/rust-hir-map.cc +++ b/gcc/rust/util/rust-hir-map.cc @@ -1299,5 +1299,15 @@ Mappings::lookup_lang_item_node (LangItem::Kind item_type) return it->second; } +NodeId +Mappings::get_lang_item_node (LangItem::Kind item_type) +{ + if (auto lookup = lookup_lang_item_node (item_type)) + return *lookup; + + rust_fatal_error (UNKNOWN_LOCATION, "failed to find lang item %qs", + LangItem::ToString (item_type).c_str ()); +} + } // namespace Analysis } // namespace Rust diff --git a/gcc/rust/util/rust-hir-map.h b/gcc/rust/util/rust-hir-map.h index aba51be4827..21e532812ff 100644 --- a/gcc/rust/util/rust-hir-map.h +++ b/gcc/rust/util/rust-hir-map.h @@ -261,6 +261,7 @@ public: void insert_lang_item_node (LangItem::Kind item_type, NodeId node_id); tl::optional lookup_lang_item_node (LangItem::Kind item_type); + NodeId get_lang_item_node (LangItem::Kind item_type); // This will fatal_error when this lang item does not exist DefId get_lang_item (LangItem::Kind item_type, location_t locus);