]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
gccrs: nr2.0: Resolve lang item paths properly.
authorArthur Cohen <arthur.cohen@embecosm.com>
Fri, 29 Nov 2024 11:35:37 +0000 (12:35 +0100)
committerArthur Cohen <arthur.cohen@embecosm.com>
Fri, 21 Mar 2025 11:33:14 +0000 (12:33 +0100)
gcc/rust/ChangeLog:

* resolve/rust-late-name-resolver-2.0.cc (Late::visit): New.
* resolve/rust-late-name-resolver-2.0.h: New.

gcc/rust/resolve/rust-late-name-resolver-2.0.cc
gcc/rust/resolve/rust-late-name-resolver-2.0.h

index 3af8496288dd097ef7219cf5c6ab6677ceec0d5d..ac5f1c575461fbe33374b403d4797f755b3d5334 100644 (file)
@@ -18,6 +18,7 @@
 
 #include "optional.h"
 #include "rust-ast-full.h"
+#include "rust-diagnostics.h"
 #include "rust-hir-map.h"
 #include "rust-late-name-resolver-2.0.h"
 #include "rust-default-resolver.h"
@@ -247,6 +248,25 @@ Late::visit (AST::PathInExpression &expr)
                 Definition (resolved->get_node_id ()));
 }
 
+void
+Late::visit (AST::LangItemPath &type)
+{
+  auto &mappings = Rust::Analysis::Mappings::get ();
+  auto lang_item = mappings.lookup_lang_item_node (type.get_lang_item_kind ());
+
+  if (!lang_item)
+    {
+      rust_fatal_error (
+       type.get_locus (), "use of undeclared lang item %qs",
+       LangItem::ToString (type.get_lang_item_kind ()).c_str ());
+      return;
+    }
+
+  ctx.map_usage (Usage (type.get_node_id ()), Definition (lang_item.value ()));
+
+  DefaultResolver::visit (type);
+}
+
 void
 Late::visit (AST::TypePath &type)
 {
index 79572fbc4fac606674a325f015edbe8840ac7367..6f1191662cc2bbb92daa7845a61e78df13906301 100644 (file)
@@ -46,6 +46,7 @@ public:
   // resolutions
   void visit (AST::IdentifierExpr &) override;
   void visit (AST::PathInExpression &) override;
+  void visit (AST::LangItemPath &) override;
   void visit (AST::TypePath &) override;
   void visit (AST::StructExprStruct &) override;
   void visit (AST::StructExprStructBase &) override;