From: Owen Avery <[email protected]>
gcc/rust/ChangeLog:
* checks/errors/borrowck/rust-bir-builder-internal.h: Include
"rust-immutable-name-resolution-context.h" and "options.h".
(AbstractBuilder::resolve_label): Use the 2.0 name resolver when
it's enabled.
(AbstractBuilder::resolve_variable): Likewise.
(AbstractBuilder::resolve_variable_or_fn): Likewise.
Signed-off-by: Owen Avery <[email protected]>
---
.../borrowck/rust-bir-builder-internal.h | 54 +++++++++++++++----
1 file changed, 44 insertions(+), 10 deletions(-)
diff --git a/gcc/rust/checks/errors/borrowck/rust-bir-builder-internal.h
b/gcc/rust/checks/errors/borrowck/rust-bir-builder-internal.h
index 4df0e14c0ec..e2cc2ddb0d8 100644
--- a/gcc/rust/checks/errors/borrowck/rust-bir-builder-internal.h
+++ b/gcc/rust/checks/errors/borrowck/rust-bir-builder-internal.h
@@ -27,6 +27,8 @@
#include "rust-name-resolver.h"
#include "rust-bir.h"
#include "rust-bir-free-region.h"
+#include "rust-immutable-name-resolution-context.h"
+#include "options.h"
namespace Rust {
@@ -402,19 +404,40 @@ protected: // HIR resolution helpers
template <typename T> NodeId resolve_label (T &expr)
{
NodeId resolved_label;
- bool ok
- = ctx.resolver.lookup_resolved_label (expr.get_mappings ().get_nodeid (),
- &resolved_label);
- rust_assert (ok);
+ if (flag_name_resolution_2_0)
+ {
+ auto &nr_ctx
+ = Resolver2_0::ImmutableNameResolutionContext::get ().resolver ();
+ auto res = nr_ctx.lookup (expr.get_mappings ().get_nodeid ());
+ rust_assert (res.has_value ());
+ resolved_label = res.value ();
+ }
+ else
+ {
+ bool ok = ctx.resolver.lookup_resolved_label (
+ expr.get_mappings ().get_nodeid (), &resolved_label);
+ rust_assert (ok);
+ }
return resolved_label;
}
template <typename T> PlaceId resolve_variable (T &variable)
{
NodeId variable_id;
- bool ok = ctx.resolver.lookup_resolved_name (
- variable.get_mappings ().get_nodeid (), &variable_id);
- rust_assert (ok);
+ if (flag_name_resolution_2_0)
+ {
+ auto &nr_ctx
+ = Resolver2_0::ImmutableNameResolutionContext::get ().resolver ();
+ auto res = nr_ctx.lookup (variable.get_mappings ().get_nodeid ());
+ rust_assert (res.has_value ());
+ variable_id = res.value ();
+ }
+ else
+ {
+ bool ok = ctx.resolver.lookup_resolved_name (
+ variable.get_mappings ().get_nodeid (), &variable_id);
+ rust_assert (ok);
+ }
return ctx.place_db.lookup_variable (variable_id);
}
@@ -425,9 +448,20 @@ protected: // HIR resolution helpers
// Unlike variables,
// functions do not have to be declared in PlaceDB before use.
NodeId variable_id;
- bool ok = ctx.resolver.lookup_resolved_name (
- variable.get_mappings ().get_nodeid (), &variable_id);
- rust_assert (ok);
+ if (flag_name_resolution_2_0)
+ {
+ auto &nr_ctx
+ = Resolver2_0::ImmutableNameResolutionContext::get ().resolver ();
+ auto res = nr_ctx.lookup (variable.get_mappings ().get_nodeid ());
+ rust_assert (res.has_value ());
+ variable_id = res.value ();
+ }
+ else
+ {
+ bool ok = ctx.resolver.lookup_resolved_name (
+ variable.get_mappings ().get_nodeid (), &variable_id);
+ rust_assert (ok);
+ }
if (ty->is<TyTy::FnType> ())
return ctx.place_db.get_constant (ty);
else
--
2.49.0