diff --git a/gcc/rust/hir/tree/rust-hir-path.h b/gcc/rust/hir/tree/rust-hir-path.h index 2af492bcfb2..3ce54cce30c 100644 --- a/gcc/rust/hir/tree/rust-hir-path.h +++ b/gcc/rust/hir/tree/rust-hir-path.h @@ -24,6 +24,7 @@ #include "rust-hir-type-no-bounds.h" #include "rust-hir-pattern-abstract.h" #include "rust-hir-expr-abstract.h" +#include "rust-system.h" namespace Rust { namespace HIR { @@ -281,8 +282,11 @@ class PathPattern : public Pattern size_t get_num_segments () const { if (kind == Kind::LangItem) - rust_fatal_error (UNKNOWN_LOCATION, "[ARTHUR] %s", - LangItem::ToString (*lang_item).c_str ()); + { + // rust_fatal_error (UNKNOWN_LOCATION, "[ARTHUR] %s", + // LangItem::ToString (*lang_item).c_str ()); + rust_unreachable (); + } rust_assert (kind == Kind::Segmented); return segments.size (); @@ -317,6 +321,12 @@ class PathPattern : public Pattern return PatternType::PATH; } + LangItem::Kind get_lang_item_kind () const + { + rust_assert (kind == Kind::LangItem); + return *lang_item; + } + Kind get_path_kind () const { return kind; } }; diff --git a/gcc/rust/typecheck/rust-hir-type-check-path.cc b/gcc/rust/typecheck/rust-hir-type-check-path.cc index ee295a16a31..9d9493ad0fb 100644 --- a/gcc/rust/typecheck/rust-hir-type-check-path.cc +++ b/gcc/rust/typecheck/rust-hir-type-check-path.cc @@ -16,6 +16,9 @@ // along with GCC; see the file COPYING3. If not see // . +#include "rust-diagnostics.h" +#include "rust-hir-map.h" +#include "rust-hir-path.h" #include "rust-hir-type-check-expr.h" #include "rust-hir-type-check-type.h" #include "rust-hir-type-check-item.h" @@ -24,6 +27,7 @@ #include "rust-hir-path-probe.h" #include "rust-type-util.h" #include "rust-hir-type-bounds.h" +#include "rust-hir-item.h" #include "rust-session-manager.h" #include "rust-immutable-name-resolution-context.h" @@ -179,20 +183,42 @@ void TypeCheckExpr::visit (HIR::PathInExpression &expr) { NodeId resolved_node_id = UNKNOWN_NODEID; - size_t offset = -1; - TyTy::BaseType *tyseg = resolve_root_path (expr, &offset, &resolved_node_id); - if (tyseg->get_kind () == TyTy::TypeKind::ERROR) - return; - - bool fully_resolved = offset == expr.get_segments ().size (); - if (fully_resolved) + if (expr.get_path_kind () == HIR::PathPattern::Kind::LangItem) { - infered = tyseg; - return; + if (auto lookup = Analysis::Mappings::get ().lookup_lang_item_node ( + expr.get_lang_item_kind ())) + { + auto hir_id = mappings.lookup_node_to_hir (*lookup); + + TyTy::BaseType *resolved = nullptr; + context->lookup_type (*hir_id, &resolved); + + infered = resolved; + return; + } + else + rust_fatal_error ( + expr.get_locus (), "lang item missing: %s", + LangItem::ToString (expr.get_lang_item_kind ()).c_str ()); } + else + { + size_t offset = -1; + TyTy::BaseType *tyseg + = resolve_root_path (expr, &offset, &resolved_node_id); + if (tyseg->get_kind () == TyTy::TypeKind::ERROR) + return; + + bool fully_resolved = offset == expr.get_segments ().size (); + if (fully_resolved) + { + infered = tyseg; + return; + } - resolve_segments (resolved_node_id, expr.get_segments (), offset, tyseg, - expr.get_mappings (), expr.get_locus ()); + resolve_segments (resolved_node_id, expr.get_segments (), offset, tyseg, + expr.get_mappings (), expr.get_locus ()); + } } TyTy::BaseType *