aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorArthur Cohen <arthur.cohen@embecosm.com>2022-04-12 10:40:02 +0200
committerArthur Cohen <arthur.cohen@embecosm.com>2022-04-12 15:26:11 +0200
commit3058b55328a3604d64ac799eaffb089b114e88a3 (patch)
tree7e425f9a87cc6fa3f4b2ff318b94c9628ff96c62
parent415586f0e22684dc7e73a2f4d6c0ec66ea42b3a4 (diff)
downloadgcc-3058b55328a3604d64ac799eaffb089b114e88a3.zip
gcc-3058b55328a3604d64ac799eaffb089b114e88a3.tar.gz
gcc-3058b55328a3604d64ac799eaffb089b114e88a3.tar.bz2
privacy: reachability: Visit all struct generic predicates
-rw-r--r--gcc/rust/privacy/rust-privacy-check.cc4
-rw-r--r--gcc/rust/privacy/rust-privacy-check.h1
-rw-r--r--gcc/rust/privacy/rust-reachability.cc35
-rw-r--r--gcc/rust/privacy/rust-reachability.h7
4 files changed, 38 insertions, 9 deletions
diff --git a/gcc/rust/privacy/rust-privacy-check.cc b/gcc/rust/privacy/rust-privacy-check.cc
index d52d8e1..ccef318 100644
--- a/gcc/rust/privacy/rust-privacy-check.cc
+++ b/gcc/rust/privacy/rust-privacy-check.cc
@@ -18,6 +18,7 @@
#include "rust-privacy-check.h"
#include "rust-reachability.h"
+#include "rust-hir-type-check.h"
extern bool
saw_errors (void);
@@ -28,7 +29,8 @@ void
Resolver::resolve (HIR::Crate &crate)
{
PrivacyContext ctx;
- auto visitor = ReachabilityVisitor (ctx);
+ auto ty_ctx = ::Rust::Resolver::TypeCheckContext::get ();
+ auto visitor = ReachabilityVisitor (ctx, *ty_ctx);
const auto &items = crate.items;
for (auto &item : items)
diff --git a/gcc/rust/privacy/rust-privacy-check.h b/gcc/rust/privacy/rust-privacy-check.h
index e0c4091..47fe7df 100644
--- a/gcc/rust/privacy/rust-privacy-check.h
+++ b/gcc/rust/privacy/rust-privacy-check.h
@@ -24,6 +24,7 @@
#include "rust-hir-expr.h"
#include "rust-hir-stmt.h"
#include "rust-hir-item.h"
+#include "rust-hir-type-check.h"
namespace Rust {
namespace Privacy {
diff --git a/gcc/rust/privacy/rust-reachability.cc b/gcc/rust/privacy/rust-reachability.cc
index e76ba71..8c1e9be 100644
--- a/gcc/rust/privacy/rust-reachability.cc
+++ b/gcc/rust/privacy/rust-reachability.cc
@@ -17,6 +17,7 @@
// <http://www.gnu.org/licenses/>.
#include "rust-reachability.h"
+#include "rust-tyty.h"
namespace Rust {
namespace Privacy {
@@ -80,12 +81,34 @@ ReachabilityVisitor::visit (HIR::StructStruct &struct_item)
if (field.get_visibility ().is_public ())
ctx.update_reachability (field.get_mappings (), struct_reach);
- // for (auto &generic : struct_item.get_generic_params ())
- // FIXME: How do we visit these generics's predicates with the
- // reachability visitor?
-
- // FIXME: How do we get each generic's predicates from here?
- // TypeContext?
+ for (auto &generic : struct_item.get_generic_params ())
+ {
+ switch (generic->get_kind ())
+ {
+ case HIR::GenericParam::LIFETIME:
+ break;
+ case HIR::GenericParam::TYPE:
+ TyTy::BaseType *generic_ty = nullptr;
+ rust_assert (
+ ty_ctx.lookup_type (generic->get_mappings ().get_hirid (),
+ &generic_ty));
+
+ if (generic_ty->get_kind () == TyTy::PARAM)
+ {
+ auto generic_param
+ = static_cast<TyTy::ParamType *> (generic_ty);
+ for (const auto &bound :
+ generic_param->get_specified_bounds ())
+ {
+ const auto trait = bound.get ()->get_hir_trait_ref ();
+ ctx.update_reachability (trait->get_mappings (),
+ struct_reach);
+ }
+ }
+
+ break;
+ }
+ }
// for (auto &field : struct_item.get_fields ())
// if (field.get_visibility ().is_public ())
diff --git a/gcc/rust/privacy/rust-reachability.h b/gcc/rust/privacy/rust-reachability.h
index 7518ad9..75ed269 100644
--- a/gcc/rust/privacy/rust-reachability.h
+++ b/gcc/rust/privacy/rust-reachability.h
@@ -25,6 +25,7 @@
#include "rust-hir-expr.h"
#include "rust-hir-stmt.h"
#include "rust-hir-item.h"
+#include "rust-hir-type-check.h"
namespace Rust {
namespace Privacy {
@@ -40,8 +41,9 @@ namespace Privacy {
class ReachabilityVisitor : public HIR::HIRVisItemVisitor
{
public:
- ReachabilityVisitor (PrivacyContext &ctx)
- : current_level (ReachLevel::Reachable), ctx (ctx)
+ ReachabilityVisitor (PrivacyContext &ctx,
+ const ::Rust::Resolver::TypeCheckContext &ty_ctx)
+ : current_level (ReachLevel::Reachable), ctx (ctx), ty_ctx (ty_ctx)
{}
virtual void visit (HIR::Module &mod);
@@ -62,6 +64,7 @@ public:
private:
ReachLevel current_level;
PrivacyContext &ctx;
+ const ::Rust::Resolver::TypeCheckContext &ty_ctx;
};
} // namespace Privacy
} // namespace Rust