]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
gccrs: Fix invalid call to vector::front in TypeBoundPredicate constructors
authorOwen Avery <powerboat9.gamer@gmail.com>
Thu, 24 Aug 2023 02:49:30 +0000 (22:49 -0400)
committerArthur Cohen <arthur.cohen@embecosm.com>
Tue, 16 Jan 2024 18:04:30 +0000 (19:04 +0100)
gcc/rust/ChangeLog:

* typecheck/rust-hir-type-check-expr.cc
(TypeCheckExpr::resolve_fn_trait_call): Add TODO comment.
* typecheck/rust-tyty-bounds.cc
(TypeBoundPredicate::TypeBoundPredicate):
Add assertions, new error constructor.
(TypeBoundPredicate::error): Use new error constructor.
* typecheck/rust-tyty.h
(struct TypeBoundPredicate::mark_is_error): New.
(TypeBoundPredicate::TypeBoundPredicate):
Add new error constructor.

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
gcc/rust/typecheck/rust-hir-type-check-expr.cc
gcc/rust/typecheck/rust-tyty-bounds.cc
gcc/rust/typecheck/rust-tyty.h

index af350ed67d3085fe473bddc8170851d12158ef70..f4ffc40fe09942df707eaeb596397b17dc3f3930 100644 (file)
@@ -1826,6 +1826,7 @@ TypeCheckExpr::resolve_fn_trait_call (HIR::CallExpr &expr,
                                      TyTy::BaseType **result)
 {
   // we turn this into a method call expr
+  // TODO: add implicit self argument (?)
   auto associated_predicate = TyTy::TypeBoundPredicate::error ();
   HIR::PathIdentSegment method_name
     = resolve_possible_fn_trait_call_method_name (*receiver_tyty,
index 6239a83f6073b1e3d5a552662fa80ba91fc7431b..6a87c05dbf4de81b2781d1562d3066cd4aae69e4 100644 (file)
@@ -310,6 +310,8 @@ TypeBoundPredicate::TypeBoundPredicate (
     reference (trait_reference.get_mappings ().get_defid ()), locus (locus),
     error_flag (false), polarity (polarity)
 {
+  rust_assert (!trait_reference.get_trait_substs ().empty ());
+
   substitutions.clear ();
   for (const auto &p : trait_reference.get_trait_substs ())
     substitutions.push_back (p.clone ());
@@ -326,6 +328,8 @@ TypeBoundPredicate::TypeBoundPredicate (
     reference (reference), locus (locus), error_flag (false),
     polarity (polarity)
 {
+  rust_assert (!subst.empty ());
+
   substitutions.clear ();
   for (const auto &p : subst)
     substitutions.push_back (p.clone ());
@@ -335,6 +339,12 @@ TypeBoundPredicate::TypeBoundPredicate (
   used_arguments.get_mappings ().push_back (placeholder_self);
 }
 
+TypeBoundPredicate::TypeBoundPredicate (mark_is_error)
+  : SubstitutionRef ({}, SubstitutionArgumentMappings::empty ()),
+    reference (UNKNOWN_DEFID), locus (UNDEF_LOCATION), error_flag (true),
+    polarity (BoundPolarity::RegularBound)
+{}
+
 TypeBoundPredicate::TypeBoundPredicate (const TypeBoundPredicate &other)
   : SubstitutionRef ({}, SubstitutionArgumentMappings::empty ()),
     reference (other.reference), locus (other.locus),
@@ -413,10 +423,7 @@ TypeBoundPredicate::operator= (const TypeBoundPredicate &other)
 TypeBoundPredicate
 TypeBoundPredicate::error ()
 {
-  auto p = TypeBoundPredicate (UNKNOWN_DEFID, {}, BoundPolarity::RegularBound,
-                              UNDEF_LOCATION);
-  p.error_flag = true;
-  return p;
+  return TypeBoundPredicate (mark_is_error ());
 }
 
 std::string
index fa2c88ccb9a504f35380672b35438c6e68d9f6c6..51bf0b463bdd11c6ef0d533f3f4cff00b8b839a4 100644 (file)
@@ -450,6 +450,12 @@ public:
   bool is_equal (const TypeBoundPredicate &other) const;
 
 private:
+  struct mark_is_error
+  {
+  };
+
+  TypeBoundPredicate (mark_is_error);
+
   DefId reference;
   location_t locus;
   bool error_flag;