Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Minor changes needed for borrowck #2770

Merged
merged 7 commits into from
Dec 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions gcc/rust/checks/errors/borrowck/rust-bir-builder-internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -261,12 +261,12 @@ class AbstractBuilder

protected: // HIR resolution helpers
template <typename T>
[[nodiscard]] TyTy::BaseType *lookup_type (T &hir_node) const
WARN_UNUSED_RESULT TyTy::BaseType *lookup_type (T &hir_node) const
{
return lookup_type (hir_node.get_mappings ().get_hirid ());
}

[[nodiscard]] TyTy::BaseType *lookup_type (HirId hirid) const
WARN_UNUSED_RESULT TyTy::BaseType *lookup_type (HirId hirid) const
{
TyTy::BaseType *type = nullptr;
bool ok = ctx.tyctx.lookup_type (hirid, &type);
Expand Down
8 changes: 4 additions & 4 deletions gcc/rust/checks/errors/borrowck/rust-bir-place.h
Original file line number Diff line number Diff line change
Expand Up @@ -148,9 +148,9 @@ class PlaceDB
0);
}

[[nodiscard]] PlaceId lookup_or_add_path (Place::Kind kind,
TyTy::BaseType *tyty,
PlaceId parent, size_t id = 0)
WARN_UNUSED_RESULT PlaceId lookup_or_add_path (Place::Kind kind,
TyTy::BaseType *tyty,
PlaceId parent, size_t id = 0)
{
PlaceId current = 0;
if (parent < places.size ())
Expand Down Expand Up @@ -211,7 +211,7 @@ class PlaceDB
auto lookup = lookup_variable (id);
if (lookup != INVALID_PLACE)
return lookup;
places.push_back (
add_place (
{Place::VARIABLE, id, {}, is_type_copy (tyty), false, NO_LIFETIME, tyty});
return places.size () - 1;
};
Expand Down
3 changes: 2 additions & 1 deletion gcc/rust/checks/errors/borrowck/rust-borrow-checker.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ class BorrowChecker

public:
explicit BorrowChecker (bool enable_dump_bir)
: enable_dump_bir (enable_dump_bir){};
: enable_dump_bir (enable_dump_bir)
{}

/** Perform borrow-checking using polonius on an entire crate */
void go (HIR::Crate &crate);
Expand Down
2 changes: 2 additions & 0 deletions gcc/rust/hir/tree/rust-hir-item.h
Original file line number Diff line number Diff line change
Expand Up @@ -443,6 +443,8 @@ struct SelfParam
// Returns whether the self-param has a valid lifetime.
bool has_lifetime () const { return !lifetime.is_error (); }

const Lifetime &get_lifetime () const { return lifetime; }

// Returns whether the self-param is in an error state.
bool is_error () const { return self_kind == ImplicitSelfKind::NONE; }

Expand Down
4 changes: 4 additions & 0 deletions gcc/rust/hir/tree/rust-hir-path.h
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,10 @@ class GenericArgs
std::string as_string () const;

std::vector<Lifetime> &get_lifetime_args () { return lifetime_args; }
const std::vector<Lifetime> &get_lifetime_args () const
{
return lifetime_args;
}

std::vector<std::unique_ptr<Type> > &get_type_args () { return type_args; }

Expand Down
7 changes: 6 additions & 1 deletion gcc/rust/hir/tree/rust-hir.h
Original file line number Diff line number Diff line change
Expand Up @@ -572,7 +572,10 @@ class Lifetime : public TypeParamBound

void accept_vis (HIRFullVisitor &vis) override;

std::string get_name () const { return lifetime_name; }
WARN_UNUSED_RESULT const std::string &get_name () const
{
return lifetime_name;
}

AST::Lifetime::LifetimeType get_lifetime_type () const
{
Expand Down Expand Up @@ -662,6 +665,8 @@ class LifetimeParam : public GenericParam
// Returns whether the lifetime param has any lifetime bounds.
bool has_lifetime_bounds () const { return !lifetime_bounds.empty (); }

std::vector<Lifetime> &get_lifetime_bounds () { return lifetime_bounds; }

// Returns whether the lifetime param has an outer attribute.
bool has_outer_attribute () const { return !outer_attr.is_empty (); }

Expand Down
11 changes: 3 additions & 8 deletions gcc/rust/typecheck/rust-hir-type-check-type.cc
Original file line number Diff line number Diff line change
Expand Up @@ -442,14 +442,9 @@ TypeCheckType::resolve_root_path (HIR::TypePath &path, size_t *offset,
root_tyty = lookup;

// this enforces the proper get_segments checks to take place
bool is_adt = root_tyty->get_kind () == TyTy::TypeKind::ADT;
if (is_adt)
{
const TyTy::ADTType &adt
= *static_cast<const TyTy::ADTType *> (root_tyty);
if (adt.is_enum ())
return root_tyty;
}
auto *maybe_adt = root_tyty->try_as<const TyTy::ADTType> ();
if (maybe_adt && maybe_adt->is_enum ())
return root_tyty;
}

return root_tyty;
Expand Down
Loading