https://gcc.gnu.org/g:0390f9422a86ba44f066b29cc7fab2be1b7990d0

commit r16-2985-g0390f9422a86ba44f066b29cc7fab2be1b7990d0
Author: Philip Herron <herron.phi...@googlemail.com>
Date:   Sun Jul 27 20:19:41 2025 +0100

    gccrs: Add ConstType boiler plate to handle const generics
    
    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.phi...@googlemail.com>

Diff:
---
 gcc/rust/backend/rust-compile-type.cc              |   6 ++
 gcc/rust/backend/rust-compile-type.h               |   1 +
 .../errors/borrowck/rust-bir-fact-collector.h      |   1 +
 gcc/rust/checks/errors/borrowck/rust-bir-place.h   |   1 +
 .../checks/errors/privacy/rust-privacy-reporter.cc |   2 +
 gcc/rust/typecheck/rust-substitution-mapper.cc     |   6 ++
 gcc/rust/typecheck/rust-substitution-mapper.h      |   6 +-
 gcc/rust/typecheck/rust-tyty-bounds.cc             |   1 +
 gcc/rust/typecheck/rust-tyty-call.h                |   1 +
 gcc/rust/typecheck/rust-tyty-cmp.h                 |  33 +++++++
 .../rust-tyty-variance-analysis-private.h          |   4 +-
 gcc/rust/typecheck/rust-tyty-visitor.h             |   2 +
 gcc/rust/typecheck/rust-tyty.cc                    | 103 +++++++++++++++++++++
 gcc/rust/typecheck/rust-tyty.h                     |  54 +++++++++++
 gcc/rust/typecheck/rust-unify.cc                   |  39 ++++++++
 gcc/rust/typecheck/rust-unify.h                    |   1 +
 16 files changed, 259 insertions(+), 2 deletions(-)

diff --git a/gcc/rust/backend/rust-compile-type.cc 
b/gcc/rust/backend/rust-compile-type.cc
index 8f13bba534b6..2058ccd3aea8 100644
--- a/gcc/rust/backend/rust-compile-type.cc
+++ b/gcc/rust/backend/rust-compile-type.cc
@@ -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)
 {
diff --git a/gcc/rust/backend/rust-compile-type.h 
b/gcc/rust/backend/rust-compile-type.h
index 7ebc4a63192c..067534377658 100644
--- a/gcc/rust/backend/rust-compile-type.h
+++ b/gcc/rust/backend/rust-compile-type.h
@@ -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;
diff --git a/gcc/rust/checks/errors/borrowck/rust-bir-fact-collector.h 
b/gcc/rust/checks/errors/borrowck/rust-bir-fact-collector.h
index e65b41662b6e..4462d7773c75 100644
--- a/gcc/rust/checks/errors/borrowck/rust-bir-fact-collector.h
+++ b/gcc/rust/checks/errors/borrowck/rust-bir-fact-collector.h
@@ -824,6 +824,7 @@ protected: // Subset helpers.
       case TyTy::PLACEHOLDER:
       case TyTy::INFER:
       case TyTy::PARAM:
+      case TyTy::CONST:
       case TyTy::OPAQUE:
        rust_unreachable ();
       }
diff --git a/gcc/rust/checks/errors/borrowck/rust-bir-place.h 
b/gcc/rust/checks/errors/borrowck/rust-bir-place.h
index c4631c7b2f16..2e9103f0b658 100644
--- a/gcc/rust/checks/errors/borrowck/rust-bir-place.h
+++ b/gcc/rust/checks/errors/borrowck/rust-bir-place.h
@@ -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;
       }
diff --git a/gcc/rust/checks/errors/privacy/rust-privacy-reporter.cc 
b/gcc/rust/checks/errors/privacy/rust-privacy-reporter.cc
index af529931b26a..4af9639c38ff 100644
--- a/gcc/rust/checks/errors/privacy/rust-privacy-reporter.cc
+++ b/gcc/rust/checks/errors/privacy/rust-privacy-reporter.cc
@@ -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;
     }
diff --git a/gcc/rust/typecheck/rust-substitution-mapper.cc 
b/gcc/rust/typecheck/rust-substitution-mapper.cc
index bdfde55718be..c5b823eabcc7 100644
--- a/gcc/rust/typecheck/rust-substitution-mapper.cc
+++ b/gcc/rust/typecheck/rust-substitution-mapper.cc
@@ -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)
 {
diff --git a/gcc/rust/typecheck/rust-substitution-mapper.h 
b/gcc/rust/typecheck/rust-substitution-mapper.h
index 32ab71c6dfbf..2389d83e392d 100644
--- a/gcc/rust/typecheck/rust-substitution-mapper.h
+++ b/gcc/rust/typecheck/rust-substitution-mapper.h
@@ -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 ();
diff --git a/gcc/rust/typecheck/rust-tyty-bounds.cc 
b/gcc/rust/typecheck/rust-tyty-bounds.cc
index 3ae4effa6af4..dd15e735f731 100644
--- a/gcc/rust/typecheck/rust-tyty-bounds.cc
+++ b/gcc/rust/typecheck/rust-tyty-bounds.cc
@@ -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;
diff --git a/gcc/rust/typecheck/rust-tyty-call.h 
b/gcc/rust/typecheck/rust-tyty-call.h
index c42fdcd08f95..9e4aab56ea1e 100644
--- a/gcc/rust/typecheck/rust-tyty-call.h
+++ b/gcc/rust/typecheck/rust-tyty-call.h
@@ -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;
diff --git a/gcc/rust/typecheck/rust-tyty-cmp.h 
b/gcc/rust/typecheck/rust-tyty-cmp.h
index aeefaa9323b1..c22dfdd7a2c1 100644
--- a/gcc/rust/typecheck/rust-tyty-cmp.h
+++ b/gcc/rust/typecheck/rust-tyty-cmp.h
@@ -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
 
diff --git a/gcc/rust/typecheck/rust-tyty-variance-analysis-private.h 
b/gcc/rust/typecheck/rust-tyty-variance-analysis-private.h
index d36afc89732e..f4dc860fb112 100644
--- a/gcc/rust/typecheck/rust-tyty-variance-analysis-private.h
+++ b/gcc/rust/typecheck/rust-tyty-variance-analysis-private.h
@@ -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
diff --git a/gcc/rust/typecheck/rust-tyty-visitor.h 
b/gcc/rust/typecheck/rust-tyty-visitor.h
index 4f8e785606ee..778307591d14 100644
--- a/gcc/rust/typecheck/rust-tyty-visitor.h
+++ b/gcc/rust/typecheck/rust-tyty-visitor.h
@@ -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;
diff --git a/gcc/rust/typecheck/rust-tyty.cc b/gcc/rust/typecheck/rust-tyty.cc
index 64207e9d7ea7..260926931f00 100644
--- a/gcc/rust/typecheck/rust-tyty.cc
+++ b/gcc/rust/typecheck/rust-tyty.cc
@@ -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,
diff --git a/gcc/rust/typecheck/rust-tyty.h b/gcc/rust/typecheck/rust-tyty.h
index 381bbeb835d7..7fd5c4695e65 100644
--- a/gcc/rust/typecheck/rust-tyty.h
+++ b/gcc/rust/typecheck/rust-tyty.h
@@ -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:
diff --git a/gcc/rust/typecheck/rust-unify.cc b/gcc/rust/typecheck/rust-unify.cc
index ac9019369826..7780ae63f1ce 100644
--- a/gcc/rust/typecheck/rust-unify.cc
+++ b/gcc/rust/typecheck/rust-unify.cc
@@ -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
diff --git a/gcc/rust/typecheck/rust-unify.h b/gcc/rust/typecheck/rust-unify.h
index f64f0ed27b82..b8c9cbcfcd67 100644
--- a/gcc/rust/typecheck/rust-unify.h
+++ b/gcc/rust/typecheck/rust-unify.h
@@ -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,

Reply via email to