mirror of
https://github.com/gcc-mirror/gcc.git
synced 2026-05-06 14:59:39 +02:00
gccrs: nr2.0: Fix borrow checking
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 <powerboat9.gamer@gmail.com>
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user