From 6ce507dac54a4adb75afec393c3aab3105ad306e Mon Sep 17 00:00:00 2001 From: Arthur Cohen Date: Mon, 25 Nov 2024 12:21:05 +0100 Subject: [PATCH 1/2] lang-items: Move comment about arithmetic lang items gcc/rust/ChangeLog: * util/rust-lang-item.h: Fix comment location to align with other comments. --- gcc/rust/util/rust-lang-item.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gcc/rust/util/rust-lang-item.h b/gcc/rust/util/rust-lang-item.h index 414436f0c965..bcf41df559e5 100644 --- a/gcc/rust/util/rust-lang-item.h +++ b/gcc/rust/util/rust-lang-item.h @@ -23,12 +23,12 @@ namespace Rust { -// https://github.com/rust-lang/rust/blob/master/library/core/src/ops/arith.rs class LangItem { public: enum class Kind { + // https://github.com/rust-lang/rust/blob/master/library/core/src/ops/arith.rs ADD, SUBTRACT, MULTIPLY, From acf647baf019c5ae46cad047a5690db5c951006a Mon Sep 17 00:00:00 2001 From: Arthur Cohen Date: Mon, 25 Nov 2024 12:37:12 +0100 Subject: [PATCH 2/2] mappings: Move lang_item definitions to .cc gcc/rust/ChangeLog: * util/rust-hir-map.h: Move definitions from header... * util/rust-hir-map.cc: ...to source file. --- gcc/rust/util/rust-hir-map.cc | 19 +++++++++++++++++++ gcc/rust/util/rust-hir-map.h | 18 ++---------------- 2 files changed, 21 insertions(+), 16 deletions(-) diff --git a/gcc/rust/util/rust-hir-map.cc b/gcc/rust/util/rust-hir-map.cc index 65981095e699..7315edb2fb8f 100644 --- a/gcc/rust/util/rust-hir-map.cc +++ b/gcc/rust/util/rust-hir-map.cc @@ -1258,5 +1258,24 @@ Mappings::lookup_trait_item_lang_item (LangItem::Kind item, location_t locus) return lookup_trait_item_defid (trait_item_id); } +void +Mappings::insert_lang_item (LangItem::Kind item_type, DefId id) +{ + auto it = lang_item_mappings.find (item_type); + rust_assert (it == lang_item_mappings.end ()); + + lang_item_mappings[item_type] = id; +} + +tl::optional +Mappings::lookup_lang_item (LangItem::Kind item_type) +{ + auto it = lang_item_mappings.find (item_type); + if (it == lang_item_mappings.end ()) + return tl::nullopt; + + return it->second; +} + } // namespace Analysis } // namespace Rust diff --git a/gcc/rust/util/rust-hir-map.h b/gcc/rust/util/rust-hir-map.h index c07f254a020d..10ca71c57b69 100644 --- a/gcc/rust/util/rust-hir-map.h +++ b/gcc/rust/util/rust-hir-map.h @@ -256,22 +256,8 @@ class Mappings return it->second; } - void insert_lang_item (LangItem::Kind item_type, DefId id) - { - auto it = lang_item_mappings.find (item_type); - rust_assert (it == lang_item_mappings.end ()); - - lang_item_mappings[item_type] = id; - } - - tl::optional lookup_lang_item (LangItem::Kind item_type) - { - auto it = lang_item_mappings.find (item_type); - if (it == lang_item_mappings.end ()) - return tl::nullopt; - - return it->second; - } + void insert_lang_item (LangItem::Kind item_type, DefId id); + tl::optional lookup_lang_item (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);