Skip to content

Commit e56b411

Browse files
powerboat9philberty
authored andcommitted
gccrs: Resolve lang item types
Lang items might not already be resolved when an expression depending on them is resolved. The new test is a copy of for-loop1.rs in the same directory, but the main function item is moved towards the top of the file. It still produces a compiler error after type checking, but that can be resolved in another patch. gcc/rust/ChangeLog: * typecheck/rust-hir-type-check-expr.cc (TypeCheckExpr::visit (BoxExpr)): Attempt to resolve lang item, instead of just looking it up. (TypeCheckExpr::visit (RangeFromToExpr)): Likewise. (TypeCheckExpr::visit (RangeFromExpr)): Likewise. (TypeCheckExpr::visit (RangeToExpr)): Likewise. (TypeCheckExpr::visit (RangeFullExpr)): Likewise. gcc/testsuite/ChangeLog: * rust/compile/for-loop3.rs: New test. Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
1 parent c869502 commit e56b411

2 files changed

Lines changed: 554 additions & 20 deletions

File tree

gcc/rust/typecheck/rust-hir-type-check-expr.cc

Lines changed: 5 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -197,11 +197,8 @@ TypeCheckExpr::visit (HIR::BoxExpr &expr)
197197
= mappings.get_lang_item (LangItem::Kind::OWNED_BOX, expr.get_locus ());
198198

199199
HIR::Item *item = mappings.lookup_defid (owned_box_defid).value ();
200-
TyTy::BaseType *item_type = nullptr;
200+
TyTy::BaseType *item_type = TypeCheckItem::Resolve (*item);
201201

202-
bool ok
203-
= context->lookup_type (item->get_mappings ().get_hirid (), &item_type);
204-
rust_assert (ok);
205202
if (item_type->get_kind () != TyTy::TypeKind::ADT)
206203
{
207204
rust_error_at (item->get_locus (), ErrorCode::E0718,
@@ -829,10 +826,7 @@ TypeCheckExpr::visit (HIR::RangeFromToExpr &expr)
829826
// look it up and it _must_ be a struct definition
830827
HIR::Item *item = mappings.lookup_defid (respective_lang_item_id).value ();
831828

832-
TyTy::BaseType *item_type = nullptr;
833-
bool ok
834-
= context->lookup_type (item->get_mappings ().get_hirid (), &item_type);
835-
rust_assert (ok);
829+
TyTy::BaseType *item_type = TypeCheckItem::Resolve (*item);
836830
rust_assert (item_type->get_kind () == TyTy::TypeKind::ADT);
837831
TyTy::ADTType *adt = static_cast<TyTy::ADTType *> (item_type);
838832

@@ -880,10 +874,7 @@ TypeCheckExpr::visit (HIR::RangeFromExpr &expr)
880874
// look it up and it _must_ be a struct definition
881875
HIR::Item *item = mappings.lookup_defid (respective_lang_item_id).value ();
882876

883-
TyTy::BaseType *item_type = nullptr;
884-
bool ok
885-
= context->lookup_type (item->get_mappings ().get_hirid (), &item_type);
886-
rust_assert (ok);
877+
TyTy::BaseType *item_type = TypeCheckItem::Resolve (*item);
887878
rust_assert (item_type->get_kind () == TyTy::TypeKind::ADT);
888879
TyTy::ADTType *adt = static_cast<TyTy::ADTType *> (item_type);
889880

@@ -924,10 +915,7 @@ TypeCheckExpr::visit (HIR::RangeToExpr &expr)
924915
// look it up and it _must_ be a struct definition
925916
HIR::Item *item = mappings.lookup_defid (respective_lang_item_id).value ();
926917

927-
TyTy::BaseType *item_type = nullptr;
928-
bool ok
929-
= context->lookup_type (item->get_mappings ().get_hirid (), &item_type);
930-
rust_assert (ok);
918+
TyTy::BaseType *item_type = TypeCheckItem::Resolve (*item);
931919
rust_assert (item_type->get_kind () == TyTy::TypeKind::ADT);
932920
TyTy::ADTType *adt = static_cast<TyTy::ADTType *> (item_type);
933921

@@ -1065,10 +1053,7 @@ TypeCheckExpr::visit (HIR::RangeFullExpr &expr)
10651053
// look it up and it _must_ be a struct definition
10661054
HIR::Item *item = mappings.lookup_defid (respective_lang_item_id).value ();
10671055

1068-
TyTy::BaseType *item_type = nullptr;
1069-
bool ok
1070-
= context->lookup_type (item->get_mappings ().get_hirid (), &item_type);
1071-
rust_assert (ok);
1056+
TyTy::BaseType *item_type = TypeCheckItem::Resolve (*item);
10721057
rust_assert (item_type->is_unit ());
10731058

10741059
infered = item_type;

0 commit comments

Comments
 (0)