Skip to content

Commit a43edad

Browse files
jdupakphilberty
authored andcommitted
TyTy: Collect variance info from types
gcc/rust/ChangeLog: * typecheck/rust-hir-type-check-item.cc (TypeCheckItem::visit): Collect variance info from types. Signed-off-by: Jakub Dupak <dev@jakubdupak.com>
1 parent e37cc5f commit a43edad

File tree

1 file changed

+14
-4
lines changed

1 file changed

+14
-4
lines changed

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

+14-4
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@
2626
#include "rust-substitution-mapper.h"
2727
#include "rust-type-util.h"
2828

29+
#include <rust-tyty-variance-analysis.h>
30+
2931
namespace Rust {
3032
namespace Resolver {
3133

@@ -204,7 +206,7 @@ TypeCheckItem::visit (HIR::TupleStruct &struct_decl)
204206
TyTy::ADTType::ReprOptions repr
205207
= parse_repr_options (attrs, struct_decl.get_locus ());
206208

207-
TyTy::BaseType *type = new TyTy::ADTType (
209+
auto *type = new TyTy::ADTType (
208210
struct_decl.get_mappings ().get_hirid (), mappings->get_next_hir_id (),
209211
struct_decl.get_identifier ().as_string (), ident,
210212
TyTy::ADTType::ADTKind::TUPLE_STRUCT, std::move (variants),
@@ -215,6 +217,8 @@ TypeCheckItem::visit (HIR::TupleStruct &struct_decl)
215217

216218
context->insert_type (struct_decl.get_mappings (), type);
217219
infered = type;
220+
221+
TyTy::VarianceAnalysis::add_type_constraints (*type);
218222
}
219223

220224
void
@@ -266,7 +270,7 @@ TypeCheckItem::visit (HIR::StructStruct &struct_decl)
266270
TyTy::ADTType::ReprOptions repr
267271
= parse_repr_options (attrs, struct_decl.get_locus ());
268272

269-
TyTy::BaseType *type = new TyTy::ADTType (
273+
auto *type = new TyTy::ADTType (
270274
struct_decl.get_mappings ().get_hirid (), mappings->get_next_hir_id (),
271275
struct_decl.get_identifier ().as_string (), ident,
272276
TyTy::ADTType::ADTKind::STRUCT_STRUCT, std::move (variants),
@@ -277,6 +281,8 @@ TypeCheckItem::visit (HIR::StructStruct &struct_decl)
277281

278282
context->insert_type (struct_decl.get_mappings (), type);
279283
infered = type;
284+
285+
TyTy::VarianceAnalysis::add_type_constraints (*type);
280286
}
281287

282288
void
@@ -307,7 +313,7 @@ TypeCheckItem::visit (HIR::Enum &enum_decl)
307313
RustIdent ident{*canonical_path, enum_decl.get_locus ()};
308314

309315
// multi variant ADT
310-
TyTy::BaseType *type
316+
auto *type
311317
= new TyTy::ADTType (enum_decl.get_mappings ().get_hirid (),
312318
mappings->get_next_hir_id (),
313319
enum_decl.get_identifier ().as_string (), ident,
@@ -316,6 +322,8 @@ TypeCheckItem::visit (HIR::Enum &enum_decl)
316322

317323
context->insert_type (enum_decl.get_mappings (), type);
318324
infered = type;
325+
326+
TyTy::VarianceAnalysis::add_type_constraints (*type);
319327
}
320328

321329
void
@@ -363,7 +371,7 @@ TypeCheckItem::visit (HIR::Union &union_decl)
363371
TyTy::VariantDef::VariantType::STRUCT, nullptr,
364372
std::move (fields)));
365373

366-
TyTy::BaseType *type
374+
auto *type
367375
= new TyTy::ADTType (union_decl.get_mappings ().get_hirid (),
368376
mappings->get_next_hir_id (),
369377
union_decl.get_identifier ().as_string (), ident,
@@ -372,6 +380,8 @@ TypeCheckItem::visit (HIR::Union &union_decl)
372380

373381
context->insert_type (union_decl.get_mappings (), type);
374382
infered = type;
383+
384+
TyTy::VarianceAnalysis::add_type_constraints (*type);
375385
}
376386

377387
void

0 commit comments

Comments
 (0)