]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
gccrs: Add ConstType boiler plate to handle const generics
authorPhilip Herron <herron.philip@googlemail.com>
Sun, 27 Jul 2025 19:19:41 +0000 (20:19 +0100)
committerArthur Cohen <arthur.cohen@embecosm.com>
Tue, 5 Aug 2025 14:37:01 +0000 (16:37 +0200)
This patch is all about just putting in the boiler plate for the new
BaseGeneric TyTy::ConstType. Nothing is really change but just the
nessecary cogs added to the machine.

gcc/rust/ChangeLog:

* backend/rust-compile-type.cc (TyTyResolveCompile::visit): error_mark_node for const types
* backend/rust-compile-type.h: boilerplate
* checks/errors/borrowck/rust-bir-fact-collector.h: likewise
* checks/errors/borrowck/rust-bir-place.h: likewise
* checks/errors/privacy/rust-privacy-reporter.cc (PrivacyReporter::check_base_type_privacy):
likewise
* typecheck/rust-substitution-mapper.cc (SubstMapperInternal::visit): likewise
* typecheck/rust-substitution-mapper.h: likewise
* typecheck/rust-tyty-bounds.cc (TypeBoundsProbe::assemble_marker_builtins): likewise
* typecheck/rust-tyty-call.h: likewise
* typecheck/rust-tyty-cmp.h (class ConstCmp): likewise
* typecheck/rust-tyty-variance-analysis-private.h: likewise
* typecheck/rust-tyty-visitor.h: likewise
* typecheck/rust-tyty.cc (TypeKindFormat::to_string): likewise
(BaseType::is_unit): likewise
(BaseType::has_substitutions_defined): likewise
(BaseType::needs_generic_substitutions): likewise
(ConstType::ConstType): likewise
(ConstType::accept_vis): likewise
(ConstType::as_string): likewise
(ConstType::can_eq): likewise
(ConstType::clone): likewise
(ConstType::get_symbol): likewise
(ConstType::get_generic_param): likewise
(ConstType::can_resolve): likewise
(ConstType::resolve): likewise
(ConstType::get_name): likewise
(ConstType::is_equal): likewise
(ConstType::handle_substitions): likewise
* typecheck/rust-tyty.h (enum TypeKind): new tyty_kind
(class ConstType): new type
* typecheck/rust-unify.cc (UnifyRules::go): Handle a const type unify
(UnifyRules::expect_inference_variable): likewise
(UnifyRules::expect_adt): likewise
(UnifyRules::expect_str): likewise
(UnifyRules::expect_reference): likewise
(UnifyRules::expect_pointer): likewise
(UnifyRules::expect_param): likewise
(UnifyRules::expect_array): likewise
(UnifyRules::expect_slice): likewise
(UnifyRules::expect_fndef): likewise
(UnifyRules::expect_fnptr): likewise
(UnifyRules::expect_tuple): likewise
(UnifyRules::expect_bool): likewise
(UnifyRules::expect_char): likewise
(UnifyRules::expect_int): likewise
(UnifyRules::expect_uint): likewise
(UnifyRules::expect_float): likewise
(UnifyRules::expect_isize): likewise
(UnifyRules::expect_usize): likewise
(UnifyRules::expect_placeholder): likewise
(UnifyRules::expect_projection): likewise
(UnifyRules::expect_dyn): likewise
(UnifyRules::expect_closure): likewise
(UnifyRules::expect_const): likewise
* typecheck/rust-unify.h: new expect_const_type handler

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
16 files changed:
gcc/rust/backend/rust-compile-type.cc
gcc/rust/backend/rust-compile-type.h
gcc/rust/checks/errors/borrowck/rust-bir-fact-collector.h
gcc/rust/checks/errors/borrowck/rust-bir-place.h
gcc/rust/checks/errors/privacy/rust-privacy-reporter.cc
gcc/rust/typecheck/rust-substitution-mapper.cc
gcc/rust/typecheck/rust-substitution-mapper.h
gcc/rust/typecheck/rust-tyty-bounds.cc
gcc/rust/typecheck/rust-tyty-call.h
gcc/rust/typecheck/rust-tyty-cmp.h
gcc/rust/typecheck/rust-tyty-variance-analysis-private.h
gcc/rust/typecheck/rust-tyty-visitor.h
gcc/rust/typecheck/rust-tyty.cc
gcc/rust/typecheck/rust-tyty.h
gcc/rust/typecheck/rust-unify.cc
gcc/rust/typecheck/rust-unify.h

index 8f13bba534b66edb53c6b1ca0c7b975ffc9ff167..2058ccd3aea8be0b1dcba955ce5c2273f95646b6 100644 (file)
@@ -141,6 +141,12 @@ TyTyResolveCompile::visit (const TyTy::ParamType &)
   translated = error_mark_node;
 }
 
+void
+TyTyResolveCompile::visit (const TyTy::ConstType &)
+{
+  translated = error_mark_node;
+}
+
 void
 TyTyResolveCompile::visit (const TyTy::ProjectionType &type)
 {
index 7ebc4a63192c044b2af3e972b7894143890c1152..0675343776586163679fbc67c693afe1327ef26d 100644 (file)
@@ -50,6 +50,7 @@ public:
   void visit (const TyTy::ReferenceType &) override;
   void visit (const TyTy::PointerType &) override;
   void visit (const TyTy::ParamType &) override;
+  void visit (const TyTy::ConstType &) override;
   void visit (const TyTy::StrType &) override;
   void visit (const TyTy::NeverType &) override;
   void visit (const TyTy::PlaceholderType &) override;
index e65b41662b6ecf507fb2912103ec56c23f58d0b1..4462d7773c756e215868f42d49c346d8ddd266aa 100644 (file)
@@ -824,6 +824,7 @@ protected: // Subset helpers.
       case TyTy::PLACEHOLDER:
       case TyTy::INFER:
       case TyTy::PARAM:
+      case TyTy::CONST:
       case TyTy::OPAQUE:
        rust_unreachable ();
       }
index c4631c7b2f16e47fb5c9f2bedd86479935b4d2d8..2e9103f0b658e527fb346336cb40e3162b66136a 100644 (file)
@@ -493,6 +493,7 @@ private:
       case TyTy::PROJECTION: // TODO: DUNNO
       case TyTy::CLOSURE:    // TODO: DUNNO
       case TyTy::DYNAMIC:    // TODO: dunno
+      case TyTy::CONST:
       case TyTy::OPAQUE:
        return false;
       }
index af529931b26a14c0b6fba52d3f7cd2a021b3b36b..4af9639c38ff25bb7a178978de9744fb1608e8b4 100644 (file)
@@ -277,6 +277,8 @@ PrivacyReporter::check_base_type_privacy (Analysis::NodeMapping &node_mappings,
       return;
     case TyTy::OPAQUE:
       return;
+    case TyTy::CONST:
+      return;
     case TyTy::ERROR:
       return;
     }
index bdfde55718bedbc837181449d477c0bea3a138d5..c5b823eabcc7b2d258557bdff7618427561348c4 100644 (file)
@@ -267,6 +267,12 @@ SubstMapperInternal::visit (TyTy::ParamType &type)
   resolved = type.handle_substitions (mappings);
 }
 
+void
+SubstMapperInternal::visit (TyTy::ConstType &type)
+{
+  resolved = type.handle_substitions (mappings);
+}
+
 void
 SubstMapperInternal::visit (TyTy::PlaceholderType &type)
 {
index 32ab71c6dfbfd171e55c35993678bacf191b122c..2389d83e392d1ace852bc5e99aaf1dd29eddb890 100644 (file)
@@ -61,6 +61,7 @@ public:
   void visit (TyTy::ReferenceType &) override { rust_unreachable (); }
   void visit (TyTy::PointerType &) override { rust_unreachable (); }
   void visit (TyTy::ParamType &) override { rust_unreachable (); }
+  void visit (TyTy::ConstType &) override { rust_unreachable (); }
   void visit (TyTy::StrType &) override { rust_unreachable (); }
   void visit (TyTy::NeverType &) override { rust_unreachable (); }
   void visit (TyTy::DynamicObjectType &) override { rust_unreachable (); }
@@ -92,6 +93,7 @@ public:
   void visit (TyTy::ReferenceType &type) override;
   void visit (TyTy::PointerType &type) override;
   void visit (TyTy::ParamType &type) override;
+  void visit (TyTy::ConstType &type) override;
   void visit (TyTy::PlaceholderType &type) override;
   void visit (TyTy::ProjectionType &type) override;
   void visit (TyTy::ClosureType &type) override;
@@ -145,6 +147,7 @@ public:
   void visit (TyTy::ReferenceType &) override { rust_unreachable (); }
   void visit (TyTy::PointerType &) override { rust_unreachable (); }
   void visit (TyTy::ParamType &) override { rust_unreachable (); }
+  void visit (TyTy::ConstType &) override { rust_unreachable (); }
   void visit (TyTy::StrType &) override { rust_unreachable (); }
   void visit (TyTy::NeverType &) override { rust_unreachable (); }
   void visit (TyTy::PlaceholderType &) override { rust_unreachable (); }
@@ -185,12 +188,13 @@ public:
   void visit (const TyTy::ReferenceType &) override {}
   void visit (const TyTy::PointerType &) override {}
   void visit (const TyTy::ParamType &) override {}
+  void visit (const TyTy::ConstType &) override {}
   void visit (const TyTy::StrType &) override {}
   void visit (const TyTy::NeverType &) override {}
   void visit (const TyTy::PlaceholderType &) override {}
   void visit (const TyTy::ProjectionType &) override {}
   void visit (const TyTy::DynamicObjectType &) override {}
-  void visit (const TyTy::OpaqueType &type) override {}
+  void visit (const TyTy::OpaqueType &) override {}
 
 private:
   GetUsedSubstArgs ();
index 3ae4effa6af40c3889e550bb439e95a5e6cfcc8b..dd15e735f7317131221c1ef5107c95abb8fdca2e 100644 (file)
@@ -173,6 +173,7 @@ TypeBoundsProbe::assemble_marker_builtins ()
       assemble_builtin_candidate (LangItem::Kind::SIZED);
       break;
 
+    case TyTy::CONST:
     case TyTy::DYNAMIC:
     case TyTy::ERROR:
       break;
index c42fdcd08f957ab20f47b31cc4257ae2451f6038..9e4aab56ea1e42b56ee820ec1f0b522063fd99e9 100644 (file)
@@ -62,6 +62,7 @@ public:
   void visit (DynamicObjectType &) override { rust_unreachable (); }
   void visit (ClosureType &type) override { rust_unreachable (); }
   void visit (OpaqueType &type) override { rust_unreachable (); }
+  void visit (ConstType &type) override { rust_unreachable (); }
 
   // tuple-structs
   void visit (ADTType &type) override;
index aeefaa9323b13eb72e9d7235f197c6992b0e28d1..c22dfdd7a2c1220f81717117f0f58247060f91e8 100644 (file)
@@ -447,6 +447,22 @@ public:
       }
   }
 
+  virtual void visit (const ConstType &type) override
+  {
+    ok = false;
+    if (emit_error_flag)
+      {
+       location_t ref_locus = mappings.lookup_location (type.get_ref ());
+       location_t base_locus
+         = mappings.lookup_location (get_base ()->get_ref ());
+       rich_location r (line_table, ref_locus);
+       r.add_range (base_locus);
+       rust_error_at (r, "expected [%s] got [%s]",
+                      get_base ()->as_string ().c_str (),
+                      type.as_string ().c_str ());
+      }
+  }
+
 protected:
   BaseCmp (const BaseType *base, bool emit_errors)
     : mappings (Analysis::Mappings::get ()),
@@ -1606,6 +1622,23 @@ private:
   const OpaqueType *base;
 };
 
+class ConstCmp : public BaseCmp
+{
+  using Rust::TyTy::BaseCmp::visit;
+
+public:
+  ConstCmp (const ConstType *base, bool emit_errors)
+    : BaseCmp (base, emit_errors), base (base)
+  {}
+
+  // TODO
+
+private:
+  const BaseType *get_base () const override { return base; }
+
+  const ConstType *base;
+};
+
 } // namespace TyTy
 } // namespace Rust
 
index d36afc89732e6c14d6d8c66a0cb55caa5dbad170..f4dc860fb11256ef8ffa14c31ee1b34c9ae3b402 100644 (file)
@@ -170,6 +170,8 @@ public:
   }
 
   void visit (OpaqueType &type) override {}
+
+  void visit (ConstType &type) override {}
 };
 
 /** Per crate context for generic type variance analysis. */
@@ -322,7 +324,7 @@ public:
                                    Variance variance) override;
   void add_constraints_from_generic_args (HirId ref, SubstitutionRef &subst,
                                          Variance variance,
-                                         bool invariant_args) override{};
+                                         bool invariant_args) override {};
   void add_constrints_from_param (ParamType &param, Variance variance) override;
 
   Variance contra (Variance variance) override
index 4f8e785606ee4f5535eb990b25d10bce6ff199cc..778307591d1426161ed111f05e3d7673e5592657 100644 (file)
@@ -45,6 +45,7 @@ public:
   virtual void visit (ReferenceType &type) = 0;
   virtual void visit (PointerType &type) = 0;
   virtual void visit (ParamType &type) = 0;
+  virtual void visit (ConstType &type) = 0;
   virtual void visit (StrType &type) = 0;
   virtual void visit (NeverType &type) = 0;
   virtual void visit (PlaceholderType &type) = 0;
@@ -75,6 +76,7 @@ public:
   virtual void visit (const ReferenceType &type) = 0;
   virtual void visit (const PointerType &type) = 0;
   virtual void visit (const ParamType &type) = 0;
+  virtual void visit (const ConstType &type) = 0;
   virtual void visit (const StrType &type) = 0;
   virtual void visit (const NeverType &type) = 0;
   virtual void visit (const PlaceholderType &type) = 0;
index 64207e9d7ea7ea1fb949df35a6e07f2c761fc63b..260926931f0039d293f72a5ad328fb2e72867663 100644 (file)
@@ -116,6 +116,9 @@ TypeKindFormat::to_string (TypeKind kind)
     case TypeKind::OPAQUE:
       return "Opaque";
 
+    case TypeKind::CONST:
+      return "Const";
+
     case TypeKind::ERROR:
       return "ERROR";
     }
@@ -225,6 +228,7 @@ BaseType::is_unit () const
     case OPAQUE:
     case STR:
     case DYNAMIC:
+    case CONST:
     case ERROR:
       return false;
 
@@ -892,6 +896,7 @@ BaseType::has_substitutions_defined () const
     case TUPLE:
     case PARAM:
     case PLACEHOLDER:
+    case CONST:
     case OPAQUE:
       return false;
 
@@ -958,6 +963,7 @@ BaseType::needs_generic_substitutions () const
     case TUPLE:
     case PARAM:
     case PLACEHOLDER:
+    case CONST:
     case OPAQUE:
       return false;
 
@@ -3580,6 +3586,103 @@ ParamType::is_implicit_self_trait () const
   return is_trait_self;
 }
 
+// ConstType
+
+ConstType::ConstType (ConstKind kind, std::string symbol, TyTy::BaseType *ty,
+                     tree value,
+                     std::vector<TypeBoundPredicate> specified_bounds,
+                     location_t locus, HirId ref, HirId ty_ref,
+                     HIR::GenericParam &param, std::set<HirId> refs)
+  : BaseGeneric (ref, ty_ref, KIND,
+                {Resolver::CanonicalPath::new_seg (UNKNOWN_NODEID, symbol),
+                 locus},
+                specified_bounds, refs),
+    const_kind (kind), ty (ty), value (value), symbol (symbol), param (param)
+{}
+
+void
+ConstType::accept_vis (TyVisitor &vis)
+{
+  vis.visit (*this);
+}
+
+void
+ConstType::accept_vis (TyConstVisitor &vis) const
+{
+  vis.visit (*this);
+}
+
+std::string
+ConstType::as_string () const
+{
+  return get_name ();
+}
+
+bool
+ConstType::can_eq (const BaseType *other, bool emit_errors) const
+{
+  ConstCmp r (this, emit_errors);
+  return r.can_eq (other);
+}
+
+BaseType *
+ConstType::clone () const
+{
+  return new ConstType (const_kind, symbol, ty, value, get_specified_bounds (),
+                       ident.locus, ref, ty_ref, param, get_combined_refs ());
+}
+
+std::string
+ConstType::get_symbol () const
+{
+  return symbol;
+}
+
+HIR::GenericParam &
+ConstType::get_generic_param ()
+{
+  return param;
+}
+
+bool
+ConstType::can_resolve () const
+{
+  return false;
+}
+
+BaseType *
+ConstType::resolve () const
+{
+  rust_unreachable ();
+  return nullptr;
+}
+
+std::string
+ConstType::get_name () const
+{
+  return "CONST_TYPE";
+}
+
+bool
+ConstType::is_equal (const BaseType &other) const
+{
+  if (get_kind () != other.get_kind ())
+    {
+      return false;
+    }
+
+  // TODO
+
+  return false;
+}
+
+ConstType *
+ConstType::handle_substitions (SubstitutionArgumentMappings &mappings)
+{
+  rust_unreachable ();
+  return nullptr;
+}
+
 // OpaqueType
 
 OpaqueType::OpaqueType (location_t locus, HirId ref,
index 381bbeb835d753bbba4446fe5eecb2e0a082b800..7fd5c4695e65f7a43dfcb949124dbc8a931585ea 100644 (file)
@@ -57,6 +57,7 @@ enum TypeKind
   REF,
   POINTER,
   PARAM,
+  CONST,
   ARRAY,
   SLICE,
   FNDEF,
@@ -431,6 +432,59 @@ private:
   HIR::GenericParam &param;
 };
 
+class ConstType : public BaseGeneric
+{
+public:
+  static constexpr auto KIND = TypeKind::CONST;
+
+  enum ConstKind
+  {
+    Decl,
+    Value,
+    Infer,
+    Error
+  };
+
+  ConstType (ConstKind kind, std::string symbol, TyTy::BaseType *ty, tree value,
+            std::vector<TypeBoundPredicate> specified_bounds, location_t locus,
+            HirId ref, HirId ty_ref, HIR::GenericParam &param,
+            std::set<HirId> refs = std::set<HirId> ());
+
+  void accept_vis (TyVisitor &vis) override;
+  void accept_vis (TyConstVisitor &vis) const override;
+
+  ConstKind get_const_kind () const { return const_kind; }
+  TyTy::BaseType *get_ty () const { return ty; }
+  tree get_value () const { return value; }
+
+  std::string as_string () const override;
+
+  bool can_eq (const BaseType *other, bool emit_errors) const override final;
+
+  BaseType *clone () const final override;
+
+  std::string get_symbol () const override final;
+
+  HIR::GenericParam &get_generic_param () override final;
+
+  bool can_resolve () const override final;
+
+  BaseType *resolve () const override final;
+
+  std::string get_name () const override final;
+
+  bool is_equal (const BaseType &other) const override;
+
+  ConstType *handle_substitions (SubstitutionArgumentMappings &mappings);
+
+private:
+  ConstKind const_kind;
+  TyTy::BaseType *ty;
+  tree value;
+  std::string symbol;
+  HIR::GenericParam &param;
+};
+
 class OpaqueType : public BaseType
 {
 public:
index ac9019369826f62e82b9c0a03dcaeefd43c58e69..7780ae63f1ce2543915d6353c013775c59f83e65 100644 (file)
@@ -17,6 +17,7 @@
 // <http://www.gnu.org/licenses/>.
 
 #include "rust-unify.h"
+#include "rust-tyty.h"
 #include "tree.h"
 
 namespace Rust {
@@ -326,6 +327,9 @@ UnifyRules::go ()
     case TyTy::OPAQUE:
       return expect_opaque (static_cast<TyTy::OpaqueType *> (ltype), rtype);
 
+    case TyTy::CONST:
+      return expect_const (static_cast<TyTy::ConstType *> (ltype), rtype);
+
     case TyTy::ERROR:
       return new TyTy::ErrorType (0);
     }
@@ -420,6 +424,7 @@ UnifyRules::expect_inference_variable (TyTy::InferType *ltype,
     case TyTy::PROJECTION:
     case TyTy::DYNAMIC:
     case TyTy::CLOSURE:
+    case TyTy::CONST:
     case TyTy::OPAQUE:
       {
        bool is_valid = (ltype->get_infer_kind ()
@@ -546,6 +551,7 @@ UnifyRules::expect_adt (TyTy::ADTType *ltype, TyTy::BaseType *rtype)
     case TyTy::DYNAMIC:
     case TyTy::CLOSURE:
     case TyTy::OPAQUE:
+    case TyTy::CONST:
     case TyTy::ERROR:
       return new TyTy::ErrorType (0);
     }
@@ -592,6 +598,7 @@ UnifyRules::expect_str (TyTy::StrType *ltype, TyTy::BaseType *rtype)
     case TyTy::DYNAMIC:
     case TyTy::CLOSURE:
     case TyTy::OPAQUE:
+    case TyTy::CONST:
     case TyTy::ERROR:
       return new TyTy::ErrorType (0);
     }
@@ -663,6 +670,7 @@ UnifyRules::expect_reference (TyTy::ReferenceType *ltype, TyTy::BaseType *rtype)
     case TyTy::DYNAMIC:
     case TyTy::CLOSURE:
     case TyTy::OPAQUE:
+    case TyTy::CONST:
     case TyTy::ERROR:
       return new TyTy::ErrorType (0);
     }
@@ -734,6 +742,7 @@ UnifyRules::expect_pointer (TyTy::PointerType *ltype, TyTy::BaseType *rtype)
     case TyTy::DYNAMIC:
     case TyTy::CLOSURE:
     case TyTy::OPAQUE:
+    case TyTy::CONST:
     case TyTy::ERROR:
       return new TyTy::ErrorType (0);
     }
@@ -798,6 +807,7 @@ UnifyRules::expect_param (TyTy::ParamType *ltype, TyTy::BaseType *rtype)
     case TyTy::DYNAMIC:
     case TyTy::CLOSURE:
     case TyTy::OPAQUE:
+    case TyTy::CONST:
     case TyTy::ERROR:
       return new TyTy::ErrorType (0);
     }
@@ -869,6 +879,7 @@ UnifyRules::expect_array (TyTy::ArrayType *ltype, TyTy::BaseType *rtype)
     case TyTy::DYNAMIC:
     case TyTy::CLOSURE:
     case TyTy::OPAQUE:
+    case TyTy::CONST:
     case TyTy::ERROR:
       return new TyTy::ErrorType (0);
     }
@@ -929,6 +940,7 @@ UnifyRules::expect_slice (TyTy::SliceType *ltype, TyTy::BaseType *rtype)
     case TyTy::DYNAMIC:
     case TyTy::CLOSURE:
     case TyTy::OPAQUE:
+    case TyTy::CONST:
     case TyTy::ERROR:
       return new TyTy::ErrorType (0);
     }
@@ -1018,6 +1030,7 @@ UnifyRules::expect_fndef (TyTy::FnType *ltype, TyTy::BaseType *rtype)
     case TyTy::DYNAMIC:
     case TyTy::CLOSURE:
     case TyTy::OPAQUE:
+    case TyTy::CONST:
     case TyTy::ERROR:
       return new TyTy::ErrorType (0);
     }
@@ -1166,6 +1179,7 @@ UnifyRules::expect_fnptr (TyTy::FnPtr *ltype, TyTy::BaseType *rtype)
     case TyTy::PROJECTION:
     case TyTy::DYNAMIC:
     case TyTy::OPAQUE:
+    case TyTy::CONST:
     case TyTy::ERROR:
       return new TyTy::ErrorType (0);
     }
@@ -1237,6 +1251,7 @@ UnifyRules::expect_tuple (TyTy::TupleType *ltype, TyTy::BaseType *rtype)
     case TyTy::DYNAMIC:
     case TyTy::CLOSURE:
     case TyTy::OPAQUE:
+    case TyTy::CONST:
     case TyTy::ERROR:
       return new TyTy::ErrorType (0);
     }
@@ -1286,6 +1301,7 @@ UnifyRules::expect_bool (TyTy::BoolType *ltype, TyTy::BaseType *rtype)
     case TyTy::DYNAMIC:
     case TyTy::CLOSURE:
     case TyTy::OPAQUE:
+    case TyTy::CONST:
     case TyTy::ERROR:
       return new TyTy::ErrorType (0);
     }
@@ -1335,6 +1351,7 @@ UnifyRules::expect_char (TyTy::CharType *ltype, TyTy::BaseType *rtype)
     case TyTy::DYNAMIC:
     case TyTy::CLOSURE:
     case TyTy::OPAQUE:
+    case TyTy::CONST:
     case TyTy::ERROR:
       return new TyTy::ErrorType (0);
     }
@@ -1392,6 +1409,7 @@ UnifyRules::expect_int (TyTy::IntType *ltype, TyTy::BaseType *rtype)
     case TyTy::DYNAMIC:
     case TyTy::CLOSURE:
     case TyTy::OPAQUE:
+    case TyTy::CONST:
     case TyTy::ERROR:
       return new TyTy::ErrorType (0);
     }
@@ -1449,6 +1467,7 @@ UnifyRules::expect_uint (TyTy::UintType *ltype, TyTy::BaseType *rtype)
     case TyTy::DYNAMIC:
     case TyTy::CLOSURE:
     case TyTy::OPAQUE:
+    case TyTy::CONST:
     case TyTy::ERROR:
       return new TyTy::ErrorType (0);
     }
@@ -1506,6 +1525,7 @@ UnifyRules::expect_float (TyTy::FloatType *ltype, TyTy::BaseType *rtype)
     case TyTy::DYNAMIC:
     case TyTy::CLOSURE:
     case TyTy::OPAQUE:
+    case TyTy::CONST:
     case TyTy::ERROR:
       return new TyTy::ErrorType (0);
     }
@@ -1555,6 +1575,7 @@ UnifyRules::expect_isize (TyTy::ISizeType *ltype, TyTy::BaseType *rtype)
     case TyTy::DYNAMIC:
     case TyTy::CLOSURE:
     case TyTy::OPAQUE:
+    case TyTy::CONST:
     case TyTy::ERROR:
       return new TyTy::ErrorType (0);
     }
@@ -1604,6 +1625,7 @@ UnifyRules::expect_usize (TyTy::USizeType *ltype, TyTy::BaseType *rtype)
     case TyTy::DYNAMIC:
     case TyTy::CLOSURE:
     case TyTy::OPAQUE:
+    case TyTy::CONST:
     case TyTy::ERROR:
       return new TyTy::ErrorType (0);
     }
@@ -1676,6 +1698,7 @@ UnifyRules::expect_placeholder (TyTy::PlaceholderType *ltype,
        return rtype->clone ();
       gcc_fallthrough ();
 
+    case TyTy::CONST:
     case TyTy::ERROR:
       return new TyTy::ErrorType (0);
     }
@@ -1725,6 +1748,7 @@ UnifyRules::expect_projection (TyTy::ProjectionType *ltype,
     case TyTy::NEVER:
     case TyTy::PLACEHOLDER:
     case TyTy::OPAQUE:
+    case TyTy::CONST:
     case TyTy::ERROR:
       return new TyTy::ErrorType (0);
     }
@@ -1786,6 +1810,7 @@ UnifyRules::expect_dyn (TyTy::DynamicObjectType *ltype, TyTy::BaseType *rtype)
     case TyTy::PLACEHOLDER:
     case TyTy::PROJECTION:
     case TyTy::OPAQUE:
+    case TyTy::CONST:
     case TyTy::ERROR:
       return new TyTy::ErrorType (0);
     }
@@ -1857,6 +1882,7 @@ UnifyRules::expect_closure (TyTy::ClosureType *ltype, TyTy::BaseType *rtype)
     case TyTy::PROJECTION:
     case TyTy::DYNAMIC:
     case TyTy::OPAQUE:
+    case TyTy::CONST:
     case TyTy::ERROR:
       return new TyTy::ErrorType (0);
     }
@@ -1909,5 +1935,18 @@ UnifyRules::expect_opaque (TyTy::OpaqueType *ltype, TyTy::BaseType *rtype)
   return ltype;
 }
 
+TyTy::BaseType *
+UnifyRules::expect_const (TyTy::ConstType *ltype, TyTy::BaseType *rtype)
+{
+  if (rtype->get_kind () != TyTy::TypeKind::CONST)
+    return new TyTy::ErrorType (0);
+
+  // TODO
+  // TyTy::ConstType &lhs = *ltype;
+  // TyTy::ConstType &rhs = *static_cast<TyTy::ConstType *> (rtype);
+
+  return new TyTy::ErrorType (0);
+}
+
 } // namespace Resolver
 } // namespace Rust
index f64f0ed27b828b9cd40aaa7cceb3403018adf218..b8c9cbcfcd67bce51647538736abb4611737a4b4 100644 (file)
@@ -84,6 +84,7 @@ protected:
                                  TyTy::BaseType *rtype);
   TyTy::BaseType *expect_opaque (TyTy::OpaqueType *ltype,
                                 TyTy::BaseType *rtype);
+  TyTy::BaseType *expect_const (TyTy::ConstType *ltype, TyTy::BaseType *rtype);
 
 private:
   UnifyRules (TyTy::TyWithLocation lhs, TyTy::TyWithLocation rhs,