aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorPhilip Herron <philip.herron@embecosm.com>2021-03-01 10:57:15 +0000
committerPhilip Herron <herron.philip@googlemail.com>2021-03-01 12:41:45 +0000
commit2a7cbe4fd99513fdf85f77a80eb04a3d99924162 (patch)
tree5d94fe72e0efaccdef6465fe4065685bc3bbb25c /gcc
parentf879526899b4680b65da052f4ef396577e6ba621 (diff)
downloadgcc-2a7cbe4fd99513fdf85f77a80eb04a3d99924162.zip
gcc-2a7cbe4fd99513fdf85f77a80eb04a3d99924162.tar.gz
gcc-2a7cbe4fd99513fdf85f77a80eb04a3d99924162.tar.bz2
Ensure compilation fails when Struct is constructed with CallExpr
CallExpr is only used for TupleStructs, so this needs to refelect rustc behaviour.
Diffstat (limited to 'gcc')
-rw-r--r--gcc/rust/typecheck/rust-hir-type-check-toplevel.h8
-rw-r--r--gcc/rust/typecheck/rust-tyty.cc13
-rw-r--r--gcc/rust/typecheck/rust-tyty.h11
3 files changed, 22 insertions, 10 deletions
diff --git a/gcc/rust/typecheck/rust-hir-type-check-toplevel.h b/gcc/rust/typecheck/rust-hir-type-check-toplevel.h
index a7fa604..a729cfe 100644
--- a/gcc/rust/typecheck/rust-hir-type-check-toplevel.h
+++ b/gcc/rust/typecheck/rust-hir-type-check-toplevel.h
@@ -72,8 +72,8 @@ public:
TyTy::BaseType *type
= new TyTy::ADTType (struct_decl.get_mappings ().get_hirid (),
mappings->get_next_hir_id (),
- struct_decl.get_identifier (), std::move (fields),
- std::move (substitions));
+ struct_decl.get_identifier (), true,
+ std::move (fields), std::move (substitions));
context->insert_type (struct_decl.get_mappings (), type);
}
@@ -109,8 +109,8 @@ public:
TyTy::BaseType *type
= new TyTy::ADTType (struct_decl.get_mappings ().get_hirid (),
mappings->get_next_hir_id (),
- struct_decl.get_identifier (), std::move (fields),
- std::move (substitions));
+ struct_decl.get_identifier (), false,
+ std::move (fields), std::move (substitions));
context->insert_type (struct_decl.get_mappings (), type);
}
diff --git a/gcc/rust/typecheck/rust-tyty.cc b/gcc/rust/typecheck/rust-tyty.cc
index 89507c7..7fbef0c 100644
--- a/gcc/rust/typecheck/rust-tyty.cc
+++ b/gcc/rust/typecheck/rust-tyty.cc
@@ -204,8 +204,8 @@ ADTType::clone ()
for (auto &f : fields)
cloned_fields.push_back ((StructFieldType *) f->clone ());
- return new ADTType (get_ref (), get_ty_ref (), identifier, cloned_fields,
- clone_substs (), get_combined_refs ());
+ return new ADTType (get_ref (), get_ty_ref (), identifier, get_is_tuple (),
+ cloned_fields, clone_substs (), get_combined_refs ());
}
ADTType *
@@ -804,6 +804,15 @@ ParamType::resolve ()
void
TypeCheckCallExpr::visit (ADTType &type)
{
+ if (!type.get_is_tuple ())
+ {
+ rust_error_at (
+ call.get_locus (),
+ "expected function, tuple struct or tuple variant, found struct `%s`",
+ type.get_name ().c_str ());
+ return;
+ }
+
if (call.num_params () != type.num_fields ())
{
rust_error_at (call.get_locus (),
diff --git a/gcc/rust/typecheck/rust-tyty.h b/gcc/rust/typecheck/rust-tyty.h
index 50fc352..8f71748 100644
--- a/gcc/rust/typecheck/rust-tyty.h
+++ b/gcc/rust/typecheck/rust-tyty.h
@@ -392,24 +392,26 @@ private:
class ADTType : public BaseType, public SubstitionRef<ADTType>
{
public:
- ADTType (HirId ref, std::string identifier,
+ ADTType (HirId ref, std::string identifier, bool is_tuple,
std::vector<StructFieldType *> fields,
std::vector<SubstitionMapping> subst_refs,
std::set<HirId> refs = std::set<HirId> ())
: BaseType (ref, ref, TypeKind::ADT, refs),
SubstitionRef (std::move (subst_refs)), identifier (identifier),
- fields (fields)
+ fields (fields), is_tuple (is_tuple)
{}
- ADTType (HirId ref, HirId ty_ref, std::string identifier,
+ ADTType (HirId ref, HirId ty_ref, std::string identifier, bool is_tuple,
std::vector<StructFieldType *> fields,
std::vector<SubstitionMapping> subst_refs,
std::set<HirId> refs = std::set<HirId> ())
: BaseType (ref, ty_ref, TypeKind::ADT, refs),
SubstitionRef (std::move (subst_refs)), identifier (identifier),
- fields (fields)
+ fields (fields), is_tuple (is_tuple)
{}
+ bool get_is_tuple () { return is_tuple; }
+
void accept_vis (TyVisitor &vis) override;
bool is_unit () const override { return false; }
@@ -484,6 +486,7 @@ public:
private:
std::string identifier;
std::vector<StructFieldType *> fields;
+ bool is_tuple;
};
class FnType : public BaseType