#include "rust-reachability.h"
#include "rust-hir-type-check.h"
#include "rust-hir-map.h"
-#include "rust-name-resolver.h"
+#include "rust-immutable-name-resolution-context.h"
#include "rust-visibility-resolver.h"
#include "rust-pub-restricted-visitor.h"
#include "rust-privacy-reporter.h"
{
PrivacyContext ctx;
auto &mappings = Analysis::Mappings::get ();
- auto resolver = Rust::Resolver::Resolver::get ();
+ auto &resolver
+ = Resolver2_0::ImmutableNameResolutionContext::get ().resolver ();
auto ty_ctx = ::Rust::Resolver::TypeCheckContext::get ();
- VisibilityResolver (mappings, *resolver).go (crate);
+ VisibilityResolver (mappings, resolver).go (crate);
PubRestrictedVisitor (mappings).go (crate);
- PrivacyReporter (mappings, *resolver, *ty_ctx).go (crate);
+ PrivacyReporter (mappings, resolver, *ty_ctx).go (crate);
auto visitor = ReachabilityVisitor (ctx, *ty_ctx);
namespace Privacy {
PrivacyReporter::PrivacyReporter (
- Analysis::Mappings &mappings, Resolver::Resolver &resolver,
+ Analysis::Mappings &mappings,
+ const Resolver2_0::NameResolutionContext &resolver,
const Rust::Resolver::TypeCheckContext &ty_ctx)
: mappings (mappings), resolver (resolver), ty_ctx (ty_ctx),
current_module (tl::nullopt)
}
}
-static bool
-is_child_module (Analysis::Mappings &mappings, NodeId parent,
- NodeId possible_child)
-{
- if (flag_name_resolution_2_0)
- {
- auto &nr_ctx
- = Resolver2_0::ImmutableNameResolutionContext::get ().resolver ();
-
- return nr_ctx.values.is_module_descendant (parent, possible_child);
- }
-
- auto children = mappings.lookup_module_children (parent);
-
- if (!children)
- return false;
-
- // Visit all toplevel children
- for (auto &child : *children)
- if (child == possible_child)
- return true;
-
- // Now descend recursively in the child module tree
- for (auto &child : *children)
- if (is_child_module (mappings, child, possible_child))
- return true;
-
- return false;
-}
-
// FIXME: This function needs a lot of refactoring
void
PrivacyReporter::check_for_privacy_violation (const NodeId &use_id,
const location_t locus)
{
- 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 (use_id))
- ref_node_id = *id;
- }
- // FIXME: Don't assert here - we might be dealing with a type
- else if (!resolver.lookup_resolved_name (use_id, &ref_node_id))
- resolver.lookup_resolved_type (use_id, &ref_node_id);
+ NodeId ref_node_id;
// FIXME: Assert here. For now, we return since this causes issues when
// checking inferred types (#1260)
- // rust_assert (ref_node_id != UNKNOWN_NODEID);
- if (ref_node_id == UNKNOWN_NODEID)
+ if (auto id = resolver.lookup (use_id))
+ ref_node_id = *id;
+ else
return;
auto vis = mappings.lookup_visibility (ref_node_id);
// FIXME: This needs a LOT of TLC: hinting about the definition, a
// string to say if it's a module, function, type, etc...
- if (!is_child_module (mappings, mod_node_id, current_module.value ()))
+
+ if (!resolver.values.is_module_descendant (mod_node_id,
+ current_module.value ()))
valid = false;
}
break;
#include "rust-hir-expr.h"
#include "rust-hir-map.h"
#include "rust-hir-visitor.h"
+#include "rust-hir-type-check.h"
#include "rust-mapping-common.h"
-#include "rust-name-resolver.h"
+#include "rust-name-resolution-context.h"
namespace Rust {
namespace Privacy {
{
public:
PrivacyReporter (Analysis::Mappings &mappings,
- Rust::Resolver::Resolver &resolver,
+ const Resolver2_0::NameResolutionContext &resolver,
const Rust::Resolver::TypeCheckContext &ty_ctx);
/**
virtual void visit (HIR::ExprStmt &stmt);
Analysis::Mappings &mappings;
- Rust::Resolver::Resolver &resolver;
+ const Resolver2_0::NameResolutionContext &resolver;
const Rust::Resolver::TypeCheckContext &ty_ctx;
// `None` means we're in the root module - the crate
#include "rust-ast.h"
#include "rust-hir.h"
#include "rust-hir-item.h"
-#include "rust-immutable-name-resolution-context.h"
-
-// for flag_name_resolution_2_0
-#include "options.h"
+#include "rust-name-resolution-context.h"
namespace Rust {
namespace Privacy {
-VisibilityResolver::VisibilityResolver (Analysis::Mappings &mappings,
- Resolver::Resolver &resolver)
+VisibilityResolver::VisibilityResolver (
+ Analysis::Mappings &mappings,
+ const Resolver2_0::NameResolutionContext &resolver)
: mappings (mappings), resolver (resolver)
{}
= Error (restriction.get_locus (),
"cannot use non-module path as privacy restrictor");
- NodeId ref_node_id = UNKNOWN_NODEID;
- if (flag_name_resolution_2_0)
+ NodeId ref_node_id;
+ if (auto id = resolver.lookup (ast_node_id))
{
- auto &nr_ctx
- = Resolver2_0::ImmutableNameResolutionContext::get ().resolver ();
-
- if (auto id = nr_ctx.lookup (ast_node_id))
- {
- ref_node_id = *id;
- }
- else
- {
- invalid_path.emit ();
- return false;
- }
+ ref_node_id = *id;
}
- else if (!resolver.lookup_resolved_name (ast_node_id, &ref_node_id))
+ else
{
invalid_path.emit ();
return false;
#include "rust-hir-stmt.h"
#include "rust-hir-item.h"
#include "rust-hir-map.h"
-#include "rust-name-resolver.h"
+#include "rust-name-resolution-context.h"
#include "rust-hir-visitor.h"
namespace Rust {
{
public:
VisibilityResolver (Analysis::Mappings &mappings,
- Rust::Resolver::Resolver &resolver);
+ const Resolver2_0::NameResolutionContext &resolver);
/**
* Perform visibility resolving on an entire crate
private:
Analysis::Mappings &mappings;
- Rust::Resolver::Resolver &resolver;
+ const Resolver2_0::NameResolutionContext &resolver;
DefId current_module;
};