From: Owen Avery <powerboat9.ga...@gmail.com>

gcc/rust/ChangeLog:

        * typecheck/rust-hir-type-check-base.cc
        (TypeCheckBase::TypeCheckBase): Remove initialization of
        resolver field.
        * typecheck/rust-hir-type-check-base.h
        (TypeCheckBase::resolver): Remove field.
        * typecheck/rust-hir-trait-resolve.cc: Remove "options.h"
        include.
        (TraitResolver::resolve_path_to_trait): Assume name resolution
        2.0 is always enabled.
        * typecheck/rust-hir-type-check-enumitem.cc: Remove "options.h"
        include.
        (TypeCheckEnumItem::visit): Assume name resolution 2.0 is always
        enabled.
        * typecheck/rust-hir-type-check-expr.cc: Remove "options.h"
        include.
        (TypeCheckExpr::visit): Assume name resolution 2.0 is always
        enabled.
        (TypeCheckExpr::resolve_operator_overload): Likewise.
        (TypeCheckExpr::resolve_fn_trait_call): Likewise.
        * typecheck/rust-hir-type-check-implitem.cc: Remove "options.h"
        include.
        (TypeCheckImplItem::visit): Assume name resolution 2.0 is always
        enabled.
        * typecheck/rust-hir-type-check-item.cc: Remove "options.h"
        include.
        (TypeCheckItem::visit): Assume name resolution 2.0 is always
        enabled.
        * typecheck/rust-hir-type-check-path.cc (TypeCheckExpr::visit):
        Likewise.
        (TypeCheckExpr::resolve_root_path): Likewise.
        (TypeCheckExpr::resolve_segments): Likewise.
        * typecheck/rust-hir-type-check-pattern.cc: Remove "options.h"
        include.
        (TypeCheckPattern::visit): Assume name resolution 2.0 is always
        enabled.
        * typecheck/rust-hir-type-check-type.cc
        (TypeCheckType::resolve_root_path): Likewise.
        (ResolveWhereClauseItem::visit): Likewise.
        * typecheck/rust-hir-type-check.cc: Remove "options.h" include.
        (TraitItemReference::get_type_from_fn): Assume name resolution
        2.0 is always enabled.
        * typecheck/rust-type-util.cc (query_type): Likewise.

Signed-off-by: Owen Avery <powerboat9.ga...@gmail.com>
---
 gcc/rust/typecheck/rust-hir-trait-resolve.cc  |  25 +---
 .../typecheck/rust-hir-type-check-base.cc     |   3 +-
 gcc/rust/typecheck/rust-hir-type-check-base.h |   1 -
 .../typecheck/rust-hir-type-check-enumitem.cc |  91 ++++-----------
 .../typecheck/rust-hir-type-check-expr.cc     |  90 ++++----------
 .../typecheck/rust-hir-type-check-implitem.cc |  25 +---
 .../typecheck/rust-hir-type-check-item.cc     | 110 ++++--------------
 .../typecheck/rust-hir-type-check-path.cc     |  70 +++--------
 .../typecheck/rust-hir-type-check-pattern.cc  |  23 +---
 .../typecheck/rust-hir-type-check-type.cc     |  38 ++----
 gcc/rust/typecheck/rust-hir-type-check.cc     |  26 +----
 gcc/rust/typecheck/rust-type-util.cc          |  18 +--
 12 files changed, 119 insertions(+), 401 deletions(-)

diff --git a/gcc/rust/typecheck/rust-hir-trait-resolve.cc 
b/gcc/rust/typecheck/rust-hir-trait-resolve.cc
index 7f224076cd7..e2e9dbf83b0 100644
--- a/gcc/rust/typecheck/rust-hir-trait-resolve.cc
+++ b/gcc/rust/typecheck/rust-hir-trait-resolve.cc
@@ -22,9 +22,6 @@
 #include "rust-type-util.h"
 #include "rust-immutable-name-resolution-context.h"
 
-// used for flag_name_resolution_2_0
-#include "options.h"
-
 namespace Rust {
 namespace Resolver {
 
@@ -123,27 +120,15 @@ bool
 TraitResolver::resolve_path_to_trait (const HIR::TypePath &path,
                                      HIR::Trait **resolved) const
 {
+  auto &nr_ctx
+    = Resolver2_0::ImmutableNameResolutionContext::get ().resolver ();
+
   NodeId ref;
-  bool ok;
-  if (flag_name_resolution_2_0)
+  if (auto ref_opt = nr_ctx.lookup (path.get_mappings ().get_nodeid ()))
     {
-      auto &nr_ctx
-       = Resolver2_0::ImmutableNameResolutionContext::get ().resolver ();
-
-      auto ref_opt = nr_ctx.lookup (path.get_mappings ().get_nodeid ());
-
-      if ((ok = ref_opt.has_value ()))
-       ref = *ref_opt;
+      ref = *ref_opt;
     }
   else
-    {
-      auto path_nodeid = path.get_mappings ().get_nodeid ();
-      ok = resolver->lookup_resolved_type (path_nodeid, &ref)
-          || resolver->lookup_resolved_name (path_nodeid, &ref)
-          || resolver->lookup_resolved_macro (path_nodeid, &ref);
-    }
-
-  if (!ok)
     {
       rust_error_at (path.get_locus (), "Failed to resolve path to node-id");
       return false;
diff --git a/gcc/rust/typecheck/rust-hir-type-check-base.cc 
b/gcc/rust/typecheck/rust-hir-type-check-base.cc
index 4bbd52a29f4..c1f15afae61 100644
--- a/gcc/rust/typecheck/rust-hir-type-check-base.cc
+++ b/gcc/rust/typecheck/rust-hir-type-check-base.cc
@@ -28,8 +28,7 @@ namespace Rust {
 namespace Resolver {
 
 TypeCheckBase::TypeCheckBase ()
-  : mappings (Analysis::Mappings::get ()), resolver (Resolver::get ()),
-    context (TypeCheckContext::get ())
+  : mappings (Analysis::Mappings::get ()), context (TypeCheckContext::get ())
 {}
 
 void
diff --git a/gcc/rust/typecheck/rust-hir-type-check-base.h 
b/gcc/rust/typecheck/rust-hir-type-check-base.h
index a8084f2bf5b..fc55516fab1 100644
--- a/gcc/rust/typecheck/rust-hir-type-check-base.h
+++ b/gcc/rust/typecheck/rust-hir-type-check-base.h
@@ -69,7 +69,6 @@ protected:
                                                 location_t locus);
 
   Analysis::Mappings &mappings;
-  Resolver *resolver;
   TypeCheckContext *context;
 };
 
diff --git a/gcc/rust/typecheck/rust-hir-type-check-enumitem.cc 
b/gcc/rust/typecheck/rust-hir-type-check-enumitem.cc
index 2dbd84d254a..23a8cca3d14 100644
--- a/gcc/rust/typecheck/rust-hir-type-check-enumitem.cc
+++ b/gcc/rust/typecheck/rust-hir-type-check-enumitem.cc
@@ -23,9 +23,6 @@
 #include "rust-type-util.h"
 #include "rust-immutable-name-resolution-context.h"
 
-// for flag_name_resolution_2_0
-#include "options.h"
-
 namespace Rust {
 namespace Resolver {
 
@@ -79,25 +76,13 @@ TypeCheckEnumItem::visit (HIR::EnumItem &item)
   rust_assert (ok);
   context->insert_type (mapping, isize);
 
-  tl::optional<CanonicalPath> canonical_path;
-
-  if (flag_name_resolution_2_0)
-    {
-      auto &nr_ctx
-       = Resolver2_0::ImmutableNameResolutionContext::get ().resolver ();
-
-      canonical_path
-       = nr_ctx.to_canonical_path (item.get_mappings ().get_nodeid ());
-    }
-  else
-    {
-      canonical_path
-       = mappings.lookup_canonical_path (item.get_mappings ().get_nodeid ());
-    }
+  auto &nr_ctx
+    = Resolver2_0::ImmutableNameResolutionContext::get ().resolver ();
 
-  rust_assert (canonical_path.has_value ());
+  CanonicalPath canonical_path
+    = nr_ctx.to_canonical_path (item.get_mappings ().get_nodeid ());
 
-  RustIdent ident{*canonical_path, item.get_locus ()};
+  RustIdent ident{canonical_path, item.get_locus ()};
   variant = new TyTy::VariantDef (item.get_mappings ().get_hirid (),
                                  item.get_mappings ().get_defid (),
                                  item.get_identifier ().as_string (), ident,
@@ -123,25 +108,13 @@ TypeCheckEnumItem::visit (HIR::EnumItemDiscriminant &item)
              TyTy::TyWithLocation (expected_ty),
              TyTy::TyWithLocation (capacity_type), item.get_locus ());
 
-  tl::optional<CanonicalPath> canonical_path;
-
-  if (flag_name_resolution_2_0)
-    {
-      auto &nr_ctx
-       = Resolver2_0::ImmutableNameResolutionContext::get ().resolver ();
-
-      canonical_path
-       = nr_ctx.to_canonical_path (item.get_mappings ().get_nodeid ());
-    }
-  else
-    {
-      canonical_path
-       = mappings.lookup_canonical_path (item.get_mappings ().get_nodeid ());
-    }
+  auto &nr_ctx
+    = Resolver2_0::ImmutableNameResolutionContext::get ().resolver ();
 
-  rust_assert (canonical_path.has_value ());
+  CanonicalPath canonical_path
+    = nr_ctx.to_canonical_path (item.get_mappings ().get_nodeid ());
 
-  RustIdent ident{*canonical_path, item.get_locus ()};
+  RustIdent ident{canonical_path, item.get_locus ()};
   variant
     = new TyTy::VariantDef (item.get_mappings ().get_hirid (),
                            item.get_mappings ().get_defid (),
@@ -185,25 +158,13 @@ TypeCheckEnumItem::visit (HIR::EnumItemTuple &item)
   rust_assert (ok);
   context->insert_type (mapping, isize);
 
-  tl::optional<CanonicalPath> canonical_path;
+  auto &nr_ctx
+    = Resolver2_0::ImmutableNameResolutionContext::get ().resolver ();
 
-  if (flag_name_resolution_2_0)
-    {
-      auto &nr_ctx
-       = Resolver2_0::ImmutableNameResolutionContext::get ().resolver ();
-
-      canonical_path
-       = nr_ctx.to_canonical_path (item.get_mappings ().get_nodeid ());
-    }
-  else
-    {
-      canonical_path
-       = mappings.lookup_canonical_path (item.get_mappings ().get_nodeid ());
-    }
-
-  rust_assert (canonical_path.has_value ());
+  CanonicalPath canonical_path
+    = nr_ctx.to_canonical_path (item.get_mappings ().get_nodeid ());
 
-  RustIdent ident{*canonical_path, item.get_locus ()};
+  RustIdent ident{canonical_path, item.get_locus ()};
   variant = new TyTy::VariantDef (item.get_mappings ().get_hirid (),
                                  item.get_mappings ().get_defid (),
                                  item.get_identifier ().as_string (), ident,
@@ -245,25 +206,13 @@ TypeCheckEnumItem::visit (HIR::EnumItemStruct &item)
   rust_assert (ok);
   context->insert_type (mapping, isize);
 
-  tl::optional<CanonicalPath> canonical_path;
-
-  if (flag_name_resolution_2_0)
-    {
-      auto &nr_ctx
-       = Resolver2_0::ImmutableNameResolutionContext::get ().resolver ();
-
-      canonical_path
-       = nr_ctx.to_canonical_path (item.get_mappings ().get_nodeid ());
-    }
-  else
-    {
-      canonical_path
-       = mappings.lookup_canonical_path (item.get_mappings ().get_nodeid ());
-    }
+  auto &nr_ctx
+    = Resolver2_0::ImmutableNameResolutionContext::get ().resolver ();
 
-  rust_assert (canonical_path.has_value ());
+  CanonicalPath canonical_path
+    = nr_ctx.to_canonical_path (item.get_mappings ().get_nodeid ());
 
-  RustIdent ident{*canonical_path, item.get_locus ()};
+  RustIdent ident{canonical_path, item.get_locus ()};
   variant = new TyTy::VariantDef (item.get_mappings ().get_hirid (),
                                  item.get_mappings ().get_defid (),
                                  item.get_identifier ().as_string (), ident,
diff --git a/gcc/rust/typecheck/rust-hir-type-check-expr.cc 
b/gcc/rust/typecheck/rust-hir-type-check-expr.cc
index 9f8d31109b1..ead751a0a7d 100644
--- a/gcc/rust/typecheck/rust-hir-type-check-expr.cc
+++ b/gcc/rust/typecheck/rust-hir-type-check-expr.cc
@@ -34,9 +34,6 @@
 #include "rust-immutable-name-resolution-context.h"
 #include "rust-compile-base.h"
 
-// for flag_name_resolution_2_0
-#include "options.h"
-
 namespace Rust {
 namespace Resolver {
 
@@ -1460,26 +1457,11 @@ TypeCheckExpr::visit (HIR::MethodCallExpr &expr)
   // store the expected fntype
   context->insert_type (expr.get_method_name ().get_mappings (), lookup);
 
-  if (flag_name_resolution_2_0)
-    {
-      auto &nr_ctx = const_cast<Resolver2_0::NameResolutionContext &> (
-       Resolver2_0::ImmutableNameResolutionContext::get ().resolver ());
+  auto &nr_ctx = const_cast<Resolver2_0::NameResolutionContext &> (
+    Resolver2_0::ImmutableNameResolutionContext::get ().resolver ());
 
-      nr_ctx.map_usage (Resolver2_0::Usage (expr.get_mappings ().get_nodeid 
()),
-                       Resolver2_0::Definition (resolved_node_id));
-    }
-  // set up the resolved name on the path
-  else if (resolver->get_name_scope ().decl_was_declared_here (
-            resolved_node_id))
-    {
-      resolver->insert_resolved_name (expr.get_mappings ().get_nodeid (),
-                                     resolved_node_id);
-    }
-  else
-    {
-      resolver->insert_resolved_misc (expr.get_mappings ().get_nodeid (),
-                                     resolved_node_id);
-    }
+  nr_ctx.map_usage (Resolver2_0::Usage (expr.get_mappings ().get_nodeid ()),
+                   Resolver2_0::Definition (resolved_node_id));
 
   // return the result of the function back
   infered = function_ret_tyty;
@@ -1821,19 +1803,12 @@ TypeCheckExpr::visit (HIR::ClosureExpr &expr)
   // Resolve closure captures
 
   std::set<NodeId> captures;
-  if (flag_name_resolution_2_0)
-    {
-      auto &nr_ctx = const_cast<Resolver2_0::NameResolutionContext &> (
-       Resolver2_0::ImmutableNameResolutionContext::get ().resolver ());
+  auto &nr_ctx = const_cast<Resolver2_0::NameResolutionContext &> (
+    Resolver2_0::ImmutableNameResolutionContext::get ().resolver ());
 
-      if (auto opt_cap = nr_ctx.mappings.lookup_captures (closure_node_id))
-       for (auto cap : opt_cap.value ())
-         captures.insert (cap);
-    }
-  else
-    {
-      captures = resolver->get_captures (closure_node_id);
-    }
+  if (auto opt_cap = nr_ctx.mappings.lookup_captures (closure_node_id))
+    for (auto cap : opt_cap.value ())
+      captures.insert (cap);
 
   infered = new TyTy::ClosureType (ref, id, ident, closure_args, result_type,
                                   subst_refs, captures);
@@ -2141,19 +2116,11 @@ TypeCheckExpr::resolve_operator_overload (
   context->insert_operator_overload (expr.get_mappings ().get_hirid (), type);
 
   // set up the resolved name on the path
-  if (flag_name_resolution_2_0)
-    {
-      auto &nr_ctx = const_cast<Resolver2_0::NameResolutionContext &> (
-       Resolver2_0::ImmutableNameResolutionContext::get ().resolver ());
+  auto &nr_ctx = const_cast<Resolver2_0::NameResolutionContext &> (
+    Resolver2_0::ImmutableNameResolutionContext::get ().resolver ());
 
-      nr_ctx.map_usage (Resolver2_0::Usage (expr.get_mappings ().get_nodeid 
()),
-                       Resolver2_0::Definition (resolved_node_id));
-    }
-  else
-    {
-      resolver->insert_resolved_name (expr.get_mappings ().get_nodeid (),
-                                     resolved_node_id);
-    }
+  nr_ctx.map_usage (Resolver2_0::Usage (expr.get_mappings ().get_nodeid ()),
+                   Resolver2_0::Definition (resolved_node_id));
 
   // return the result of the function back
   infered = function_ret_tyty;
@@ -2346,32 +2313,15 @@ TypeCheckExpr::resolve_fn_trait_call (HIR::CallExpr 
&expr,
   context->insert_operator_overload (expr.get_mappings ().get_hirid (), fn);
 
   // set up the resolved name on the path
-  if (flag_name_resolution_2_0)
-    {
-      auto &nr_ctx = const_cast<Resolver2_0::NameResolutionContext &> (
-       Resolver2_0::ImmutableNameResolutionContext::get ().resolver ());
+  auto &nr_ctx = const_cast<Resolver2_0::NameResolutionContext &> (
+    Resolver2_0::ImmutableNameResolutionContext::get ().resolver ());
 
-      auto existing = nr_ctx.lookup (expr.get_mappings ().get_nodeid ());
-      if (existing)
-       rust_assert (*existing == resolved_node_id);
-      else
-       nr_ctx.map_usage (Resolver2_0::Usage (
-                           expr.get_mappings ().get_nodeid ()),
-                         Resolver2_0::Definition (resolved_node_id));
-    }
+  auto existing = nr_ctx.lookup (expr.get_mappings ().get_nodeid ());
+  if (existing)
+    rust_assert (*existing == resolved_node_id);
   else
-    {
-      NodeId existing = UNKNOWN_NODEID;
-      bool ok
-       = resolver->lookup_resolved_name (expr.get_mappings ().get_nodeid (),
-                                         &existing);
-
-      if (ok)
-       rust_assert (existing == resolved_node_id);
-      else
-       resolver->insert_resolved_name (expr.get_mappings ().get_nodeid (),
-                                       resolved_node_id);
-    }
+    nr_ctx.map_usage (Resolver2_0::Usage (expr.get_mappings ().get_nodeid ()),
+                     Resolver2_0::Definition (resolved_node_id));
 
   // return the result of the function back
   *result = function_ret_tyty;
diff --git a/gcc/rust/typecheck/rust-hir-type-check-implitem.cc 
b/gcc/rust/typecheck/rust-hir-type-check-implitem.cc
index 00f0cc66974..76ff6903077 100644
--- a/gcc/rust/typecheck/rust-hir-type-check-implitem.cc
+++ b/gcc/rust/typecheck/rust-hir-type-check-implitem.cc
@@ -28,9 +28,6 @@
 #include "rust-tyty.h"
 #include "rust-immutable-name-resolution-context.h"
 
-// for flag_name_resolution_2_0
-#include "options.h"
-
 namespace Rust {
 namespace Resolver {
 
@@ -338,25 +335,13 @@ TypeCheckImplItem::visit (HIR::Function &function)
        TyTy::FnParam (param.get_param_name ().clone_pattern (), param_tyty));
     }
 
-  tl::optional<CanonicalPath> canonical_path;
-
-  if (flag_name_resolution_2_0)
-    {
-      auto &nr_ctx
-       = Resolver2_0::ImmutableNameResolutionContext::get ().resolver ();
-
-      canonical_path
-       = nr_ctx.to_canonical_path (function.get_mappings ().get_nodeid ());
-    }
-  else
-    {
-      canonical_path = mappings.lookup_canonical_path (
-       function.get_mappings ().get_nodeid ());
-    }
+  auto &nr_ctx
+    = Resolver2_0::ImmutableNameResolutionContext::get ().resolver ();
 
-  rust_assert (canonical_path.has_value ());
+  CanonicalPath canonical_path
+    = nr_ctx.to_canonical_path (function.get_mappings ().get_nodeid ());
 
-  RustIdent ident{*canonical_path, function.get_locus ()};
+  RustIdent ident{canonical_path, function.get_locus ()};
   auto fnType = new TyTy::FnType (
     function.get_mappings ().get_hirid (),
     function.get_mappings ().get_defid (),
diff --git a/gcc/rust/typecheck/rust-hir-type-check-item.cc 
b/gcc/rust/typecheck/rust-hir-type-check-item.cc
index 70622778a1c..e86525a68e5 100644
--- a/gcc/rust/typecheck/rust-hir-type-check-item.cc
+++ b/gcc/rust/typecheck/rust-hir-type-check-item.cc
@@ -33,9 +33,6 @@
 #include "rust-type-util.h"
 #include "rust-tyty-variance-analysis.h"
 
-// for flag_name_resolution_2_0
-#include "options.h"
-
 namespace Rust {
 namespace Resolver {
 
@@ -195,24 +192,11 @@ TypeCheckItem::visit (HIR::TupleStruct &struct_decl)
 
   // get the path
 
-  auto path = CanonicalPath::create_empty ();
+  auto &nr_ctx
+    = Resolver2_0::ImmutableNameResolutionContext::get ().resolver ();
 
-  // FIXME: HACK: ARTHUR: Disgusting
-  if (flag_name_resolution_2_0)
-    {
-      auto &nr_ctx
-       = Resolver2_0::ImmutableNameResolutionContext::get ().resolver ();
-
-      path
-       = nr_ctx.to_canonical_path (struct_decl.get_mappings ().get_nodeid ());
-    }
-  else
-    {
-      path
-       = mappings
-           .lookup_canonical_path (struct_decl.get_mappings ().get_nodeid ())
-           .value ();
-    }
+  CanonicalPath path
+    = nr_ctx.to_canonical_path (struct_decl.get_mappings ().get_nodeid ());
 
   RustIdent ident{path, struct_decl.get_locus ()};
 
@@ -275,23 +259,11 @@ TypeCheckItem::visit (HIR::StructStruct &struct_decl)
       context->insert_type (field.get_mappings (), ty_field->get_field_type 
());
     }
 
-  auto path = CanonicalPath::create_empty ();
+  auto &nr_ctx
+    = Resolver2_0::ImmutableNameResolutionContext::get ().resolver ();
 
-  // FIXME: HACK: ARTHUR: Disgusting
-  if (flag_name_resolution_2_0)
-    {
-      auto &nr_ctx
-       = Resolver2_0::ImmutableNameResolutionContext::get ().resolver ();
-      path
-       = nr_ctx.to_canonical_path (struct_decl.get_mappings ().get_nodeid ());
-    }
-  else
-    {
-      path
-       = mappings
-           .lookup_canonical_path (struct_decl.get_mappings ().get_nodeid ())
-           .value ();
-    }
+  CanonicalPath path
+    = nr_ctx.to_canonical_path (struct_decl.get_mappings ().get_nodeid ());
 
   RustIdent ident{path, struct_decl.get_locus ()};
 
@@ -362,26 +334,14 @@ TypeCheckItem::visit (HIR::Enum &enum_decl)
        }
     }
 
-  // get the path
-  tl::optional<CanonicalPath> canonical_path;
+  auto &nr_ctx
+    = Resolver2_0::ImmutableNameResolutionContext::get ().resolver ();
 
-  if (flag_name_resolution_2_0)
-    {
-      auto &nr_ctx
-       = Resolver2_0::ImmutableNameResolutionContext::get ().resolver ();
-
-      canonical_path
-       = nr_ctx.to_canonical_path (enum_decl.get_mappings ().get_nodeid ());
-    }
-  else
-    {
-      canonical_path = mappings.lookup_canonical_path (
-       enum_decl.get_mappings ().get_nodeid ());
-    }
-
-  rust_assert (canonical_path.has_value ());
+  // get the path
+  CanonicalPath canonical_path
+    = nr_ctx.to_canonical_path (enum_decl.get_mappings ().get_nodeid ());
 
-  RustIdent ident{*canonical_path, enum_decl.get_locus ()};
+  RustIdent ident{canonical_path, enum_decl.get_locus ()};
 
   // multi variant ADT
   auto *type
@@ -426,26 +386,14 @@ TypeCheckItem::visit (HIR::Union &union_decl)
                            ty_variant->get_field_type ());
     }
 
-  // get the path
-  tl::optional<CanonicalPath> canonical_path;
+  auto &nr_ctx
+    = Resolver2_0::ImmutableNameResolutionContext::get ().resolver ();
 
-  if (flag_name_resolution_2_0)
-    {
-      auto &nr_ctx
-       = Resolver2_0::ImmutableNameResolutionContext::get ().resolver ();
-
-      canonical_path
-       = nr_ctx.to_canonical_path (union_decl.get_mappings ().get_nodeid ());
-    }
-  else
-    {
-      canonical_path = mappings.lookup_canonical_path (
-       union_decl.get_mappings ().get_nodeid ());
-    }
-
-  rust_assert (canonical_path.has_value ());
+  // get the path
+  CanonicalPath canonical_path
+    = nr_ctx.to_canonical_path (union_decl.get_mappings ().get_nodeid ());
 
-  RustIdent ident{*canonical_path, union_decl.get_locus ()};
+  RustIdent ident{canonical_path, union_decl.get_locus ()};
 
   // there is only a single variant
   std::vector<TyTy::VariantDef *> variants;
@@ -602,21 +550,11 @@ TypeCheckItem::visit (HIR::Function &function)
        TyTy::FnParam (param.get_param_name ().clone_pattern (), param_tyty));
     }
 
-  auto path = CanonicalPath::create_empty ();
+  auto &nr_ctx
+    = Resolver2_0::ImmutableNameResolutionContext::get ().resolver ();
 
-  // FIXME: HACK: ARTHUR: Disgusting
-  if (flag_name_resolution_2_0)
-    {
-      auto &nr_ctx
-       = Resolver2_0::ImmutableNameResolutionContext::get ().resolver ();
-      path = nr_ctx.to_canonical_path (function.get_mappings ().get_nodeid ());
-    }
-  else
-    {
-      path = mappings
-              .lookup_canonical_path (function.get_mappings ().get_nodeid ())
-              .value ();
-    }
+  CanonicalPath path
+    = nr_ctx.to_canonical_path (function.get_mappings ().get_nodeid ());
 
   RustIdent ident{path, function.get_locus ()};
 
diff --git a/gcc/rust/typecheck/rust-hir-type-check-path.cc 
b/gcc/rust/typecheck/rust-hir-type-check-path.cc
index 5662da5310e..cc5c412f986 100644
--- a/gcc/rust/typecheck/rust-hir-type-check-path.cc
+++ b/gcc/rust/typecheck/rust-hir-type-check-path.cc
@@ -157,20 +157,11 @@ TypeCheckExpr::visit (HIR::QualifiedPathInExpression 
&expr)
   bool fully_resolved = expr.get_segments ().size () <= 1;
   if (fully_resolved)
     {
-      if (flag_name_resolution_2_0)
-       {
-         auto &nr_ctx = const_cast<Resolver2_0::NameResolutionContext &> (
-           Resolver2_0::ImmutableNameResolutionContext::get ().resolver ());
+      auto &nr_ctx = const_cast<Resolver2_0::NameResolutionContext &> (
+       Resolver2_0::ImmutableNameResolutionContext::get ().resolver ());
 
-         nr_ctx.map_usage (Resolver2_0::Usage (
-                             expr.get_mappings ().get_nodeid ()),
-                           Resolver2_0::Definition (root_resolved_node_id));
-       }
-      else
-       {
-         resolver->insert_resolved_name (expr.get_mappings ().get_nodeid (),
-                                         root_resolved_node_id);
-       }
+      nr_ctx.map_usage (Resolver2_0::Usage (expr.get_mappings ().get_nodeid 
()),
+                       Resolver2_0::Definition (root_resolved_node_id));
       return;
     }
 
@@ -264,24 +255,16 @@ TypeCheckExpr::resolve_root_path (HIR::PathInExpression 
&expr, size_t *offset,
       bool is_root = *offset == 0;
       NodeId ast_node_id = seg.get_mappings ().get_nodeid ();
 
-      // then lookup the reference_node_id
-      NodeId ref_node_id = UNKNOWN_NODEID;
+      auto &nr_ctx
+       = Resolver2_0::ImmutableNameResolutionContext::get ().resolver ();
 
-      if (flag_name_resolution_2_0)
+      // lookup the reference_node_id
+      NodeId ref_node_id;
+      if (auto res = nr_ctx.lookup (ast_node_id))
        {
-         auto &nr_ctx
-           = Resolver2_0::ImmutableNameResolutionContext::get ().resolver ();
-
-         // assign the ref_node_id if we've found something
-         nr_ctx.lookup (ast_node_id).map ([&ref_node_id] (NodeId resolved) {
-           ref_node_id = resolved;
-         });
+         ref_node_id = *res;
        }
-      else if (!resolver->lookup_resolved_name (ast_node_id, &ref_node_id))
-       resolver->lookup_resolved_type (ast_node_id, &ref_node_id);
-
-      // ref_node_id is the NodeId that the segments refers to.
-      if (ref_node_id == UNKNOWN_NODEID)
+      else
        {
          if (root_tyty != nullptr && *offset > 0)
            {
@@ -561,33 +544,12 @@ TypeCheckExpr::resolve_segments (NodeId 
root_resolved_node_id,
     }
 
   rust_assert (resolved_node_id != UNKNOWN_NODEID);
-  if (flag_name_resolution_2_0)
-    {
-      auto &nr_ctx = const_cast<Resolver2_0::NameResolutionContext &> (
-       Resolver2_0::ImmutableNameResolutionContext::get ().resolver ());
 
-      nr_ctx.map_usage (Resolver2_0::Usage (expr_mappings.get_nodeid ()),
-                       Resolver2_0::Definition (resolved_node_id));
-    }
-  // name scope first
-  else if (resolver->get_name_scope ().decl_was_declared_here (
-            resolved_node_id))
-    {
-      resolver->insert_resolved_name (expr_mappings.get_nodeid (),
-                                     resolved_node_id);
-    }
-  // check the type scope
-  else if (resolver->get_type_scope ().decl_was_declared_here (
-            resolved_node_id))
-    {
-      resolver->insert_resolved_type (expr_mappings.get_nodeid (),
-                                     resolved_node_id);
-    }
-  else
-    {
-      resolver->insert_resolved_misc (expr_mappings.get_nodeid (),
-                                     resolved_node_id);
-    }
+  auto &nr_ctx = const_cast<Resolver2_0::NameResolutionContext &> (
+    Resolver2_0::ImmutableNameResolutionContext::get ().resolver ());
+
+  nr_ctx.map_usage (Resolver2_0::Usage (expr_mappings.get_nodeid ()),
+                   Resolver2_0::Definition (resolved_node_id));
 
   infered = tyseg;
 }
diff --git a/gcc/rust/typecheck/rust-hir-type-check-pattern.cc 
b/gcc/rust/typecheck/rust-hir-type-check-pattern.cc
index 13fc9c85cc8..2190faec751 100644
--- a/gcc/rust/typecheck/rust-hir-type-check-pattern.cc
+++ b/gcc/rust/typecheck/rust-hir-type-check-pattern.cc
@@ -22,9 +22,6 @@
 #include "rust-type-util.h"
 #include "rust-immutable-name-resolution-context.h"
 
-// for flag_name_resolution_2_0
-#include "options.h"
-
 namespace Rust {
 namespace Resolver {
 
@@ -54,23 +51,13 @@ TypeCheckPattern::visit (HIR::PathInExpression &pattern)
   NodeId ref_node_id = UNKNOWN_NODEID;
   bool maybe_item = false;
 
-  if (flag_name_resolution_2_0)
-    {
-      auto &nr_ctx
-       = Resolver2_0::ImmutableNameResolutionContext::get ().resolver ();
+  auto &nr_ctx
+    = Resolver2_0::ImmutableNameResolutionContext::get ().resolver ();
 
-      if (auto id = nr_ctx.lookup (pattern.get_mappings ().get_nodeid ()))
-       {
-         ref_node_id = *id;
-         maybe_item = true;
-       }
-    }
-  else
+  if (auto id = nr_ctx.lookup (pattern.get_mappings ().get_nodeid ()))
     {
-      maybe_item |= resolver->lookup_resolved_name (
-       pattern.get_mappings ().get_nodeid (), &ref_node_id);
-      maybe_item |= resolver->lookup_resolved_type (
-       pattern.get_mappings ().get_nodeid (), &ref_node_id);
+      ref_node_id = *id;
+      maybe_item = true;
     }
 
   bool path_is_const_item = false;
diff --git a/gcc/rust/typecheck/rust-hir-type-check-type.cc 
b/gcc/rust/typecheck/rust-hir-type-check-type.cc
index 462b3d48767..21237f58868 100644
--- a/gcc/rust/typecheck/rust-hir-type-check-type.cc
+++ b/gcc/rust/typecheck/rust-hir-type-check-type.cc
@@ -336,19 +336,13 @@ TypeCheckType::resolve_root_path (HIR::TypePath &path, 
size_t *offset,
          seg->get_lang_item ());
       else
        {
-         // FIXME: HACK: ARTHUR: Remove this
-         if (flag_name_resolution_2_0)
-           {
-             auto &nr_ctx = Resolver2_0::ImmutableNameResolutionContext::get ()
-                              .resolver ();
+         auto &nr_ctx
+           = Resolver2_0::ImmutableNameResolutionContext::get ().resolver ();
 
-             // assign the ref_node_id if we've found something
-             nr_ctx.lookup (ast_node_id)
-               .map (
-                 [&ref_node_id] (NodeId resolved) { ref_node_id = resolved; });
-           }
-         else if (!resolver->lookup_resolved_name (ast_node_id, &ref_node_id))
-           resolver->lookup_resolved_type (ast_node_id, &ref_node_id);
+         // assign the ref_node_id if we've found something
+         nr_ctx.lookup (ast_node_id).map ([&ref_node_id] (NodeId resolved) {
+           ref_node_id = resolved;
+         });
        }
 
       // ref_node_id is the NodeId that the segments refers to.
@@ -1081,23 +1075,15 @@ ResolveWhereClauseItem::visit 
(HIR::TypeBoundWhereClauseItem &item)
 
   // then lookup the reference_node_id
   NodeId ref_node_id = UNKNOWN_NODEID;
-  if (flag_name_resolution_2_0)
-    {
-      auto &nr_ctx
-       = Resolver2_0::ImmutableNameResolutionContext::get ().resolver ();
 
-      if (auto id = nr_ctx.lookup (ast_node_id))
-       ref_node_id = *id;
-    }
-  else
-    {
-      NodeId id = UNKNOWN_NODEID;
+  auto &nr_ctx
+    = Resolver2_0::ImmutableNameResolutionContext::get ().resolver ();
 
-      if (resolver->lookup_resolved_type (ast_node_id, &id))
-       ref_node_id = id;
+  if (auto id = nr_ctx.lookup (ast_node_id))
+    {
+      ref_node_id = *id;
     }
-
-  if (ref_node_id == UNKNOWN_NODEID)
+  else
     {
       // FIXME
       rust_error_at (UNDEF_LOCATION,
diff --git a/gcc/rust/typecheck/rust-hir-type-check.cc 
b/gcc/rust/typecheck/rust-hir-type-check.cc
index 27879e3d4e9..6097c4e5be8 100644
--- a/gcc/rust/typecheck/rust-hir-type-check.cc
+++ b/gcc/rust/typecheck/rust-hir-type-check.cc
@@ -26,9 +26,6 @@
 #include "rust-hir-type-check-struct-field.h"
 #include "rust-immutable-name-resolution-context.h"
 
-// for flag_name_resolution_2_0
-#include "options.h"
-
 extern bool saw_errors (void);
 
 namespace Rust {
@@ -275,26 +272,13 @@ TraitItemReference::get_type_from_fn (/*const*/ 
HIR::TraitItemFunc &fn) const
        TyTy::FnParam (param.get_param_name ().clone_pattern (), param_tyty));
     }
 
-  auto &mappings = Analysis::Mappings::get ();
-
-  tl::optional<CanonicalPath> canonical_path;
-  if (flag_name_resolution_2_0)
-    {
-      auto &nr_ctx
-       = Resolver2_0::ImmutableNameResolutionContext::get ().resolver ();
-
-      canonical_path
-       = nr_ctx.to_canonical_path (fn.get_mappings ().get_nodeid ());
-    }
-  else
-    {
-      canonical_path
-       = mappings.lookup_canonical_path (fn.get_mappings ().get_nodeid ());
-    }
+  auto &nr_ctx
+    = Resolver2_0::ImmutableNameResolutionContext::get ().resolver ();
 
-  rust_assert (canonical_path);
+  CanonicalPath canonical_path
+    = nr_ctx.to_canonical_path (fn.get_mappings ().get_nodeid ());
 
-  RustIdent ident{*canonical_path, fn.get_locus ()};
+  RustIdent ident{canonical_path, fn.get_locus ()};
   auto resolved = new TyTy::FnType (
     fn.get_mappings ().get_hirid (), fn.get_mappings ().get_defid (),
     function.get_function_name ().as_string (), ident,
diff --git a/gcc/rust/typecheck/rust-type-util.cc 
b/gcc/rust/typecheck/rust-type-util.cc
index a549449dcef..0f14e0a6008 100644
--- a/gcc/rust/typecheck/rust-type-util.cc
+++ b/gcc/rust/typecheck/rust-type-util.cc
@@ -37,7 +37,6 @@ bool
 query_type (HirId reference, TyTy::BaseType **result)
 {
   auto &mappings = Analysis::Mappings::get ();
-  auto &resolver = *Resolver::get ();
   TypeCheckContext *context = TypeCheckContext::get ();
 
   if (context->lookup_type (reference, result))
@@ -103,18 +102,13 @@ query_type (HirId reference, TyTy::BaseType **result)
          NodeId ref_node_id = UNKNOWN_NODEID;
          NodeId ast_node_id = ty.get_mappings ().get_nodeid ();
 
-         if (flag_name_resolution_2_0)
-           {
-             auto &nr_ctx = Resolver2_0::ImmutableNameResolutionContext::get ()
-                              .resolver ();
+         auto &nr_ctx
+           = Resolver2_0::ImmutableNameResolutionContext::get ().resolver ();
 
-             // assign the ref_node_id if we've found something
-             nr_ctx.lookup (ast_node_id)
-               .map (
-                 [&ref_node_id] (NodeId resolved) { ref_node_id = resolved; });
-           }
-         else if (!resolver.lookup_resolved_name (ast_node_id, &ref_node_id))
-           resolver.lookup_resolved_type (ast_node_id, &ref_node_id);
+         // assign the ref_node_id if we've found something
+         nr_ctx.lookup (ast_node_id).map ([&ref_node_id] (NodeId resolved) {
+           ref_node_id = resolved;
+         });
 
          if (ref_node_id != UNKNOWN_NODEID)
            {
-- 
2.49.0

Reply via email to