]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
gccrs: mappings: Add get_lang_item_node
authorArthur Cohen <arthur.cohen@embecosm.com>
Thu, 26 Dec 2024 23:00:08 +0000 (23:00 +0000)
committerArthur Cohen <arthur.cohen@embecosm.com>
Fri, 21 Mar 2025 11:57:49 +0000 (12:57 +0100)
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.

gcc/rust/util/rust-hir-map.cc
gcc/rust/util/rust-hir-map.h

index f11a77954aeff5aa50c4e732c836cdd64ea65c6a..b94591e014c4a0fcf371bc52e2661e0c982e4cec 100644 (file)
@@ -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
index aba51be4827fadb972556d58c1bed1bf16d6372f..21e532812ff7cb41a5dfa95423aa7f86f3979907 100644 (file)
@@ -261,6 +261,7 @@ public:
 
   void insert_lang_item_node (LangItem::Kind item_type, NodeId node_id);
   tl::optional<NodeId &> 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);