]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
gccrs: Add get_defid helper to TypeCheckContextItem
authorPhilip Herron <herron.philip@googlemail.com>
Mon, 17 Apr 2023 20:50:54 +0000 (21:50 +0100)
committerArthur Cohen <arthur.cohen@embecosm.com>
Tue, 16 Jan 2024 17:34:12 +0000 (18:34 +0100)
gcc/rust/ChangeLog:

* typecheck/rust-hir-type-check.h: Add prototype
* typecheck/rust-typecheck-context.cc (TypeCheckContextItem::get_defid): implementation

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
gcc/rust/typecheck/rust-hir-type-check.h
gcc/rust/typecheck/rust-typecheck-context.cc

index 10aa3b32a9e00234c17bbae81ef2b09b3a9bd041..3f43bc89d6fdf3e001362f06a1079e4229390488 100644 (file)
@@ -51,6 +51,8 @@ public:
 
   TyTy::FnType *get_context_type ();
 
+  DefId get_defid () const;
+
 private:
   union Item
   {
index dcf06098cc5345ab50b819ef28dfa05acf6d65b8..7c0dc06372d040145741011255cd08c5c348376c 100644 (file)
@@ -576,5 +576,23 @@ TypeCheckContextItem::get_context_type ()
   return static_cast<TyTy::FnType *> (lookup);
 }
 
+DefId
+TypeCheckContextItem::get_defid () const
+{
+  switch (get_type ())
+    {
+    case ITEM:
+      return item.item->get_mappings ().get_defid ();
+
+    case IMPL_ITEM:
+      return item.impl_item.second->get_mappings ().get_defid ();
+
+    case TRAIT_ITEM:
+      return item.trait_item->get_mappings ().get_defid ();
+    }
+
+  return UNKNOWN_DEFID;
+}
+
 } // namespace Resolver
 } // namespace Rust