[COMMITTED 44/83] gccrs: Fix debug output of variance analysis to switch to substitutionref

arthur.cohen@opensrcsec.com arthur.cohen@opensrcsec.com
Wed Sep 16 12:30:03 GMT 2026


From: Philip Herron <herron.philip@googlemail.com>

gcc/rust/ChangeLog:

	* typecheck/rust-tyty-variance-analysis.cc (GenericTyPerCrateCtx::debug_print_solutions):
	we can switch into a substitutionref base class to make this generic

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
---
 .../typecheck/rust-tyty-variance-analysis.cc  | 62 +++++++++++--------
 1 file changed, 36 insertions(+), 26 deletions(-)

diff --git a/gcc/rust/typecheck/rust-tyty-variance-analysis.cc b/gcc/rust/typecheck/rust-tyty-variance-analysis.cc
index 6c6877ef9ec..2b1a8b7db6f 100644
--- a/gcc/rust/typecheck/rust-tyty-variance-analysis.cc
+++ b/gcc/rust/typecheck/rust-tyty-variance-analysis.cc
@@ -180,39 +180,49 @@ GenericTyPerCrateCtx::debug_print_solutions ()
       BaseType *ty = lookup_type (ref);
 
       std::string result = "\t";
+      SubstitutionRef *subst = nullptr;
 
-      if (auto adt = ty->try_as<ADTType> ())
+      switch (ty->get_kind ())
 	{
-	  result += adt->get_identifier ();
-	  result += "<";
+	case TypeKind::ADT:
+	  subst = static_cast<ADTType *> (ty);
+	  break;
+	case TypeKind::FNDEF:
+	  subst = static_cast<FnType *> (ty);
+	  break;
+	case TypeKind::CLOSURE:
+	  subst = static_cast<ClosureType *> (ty);
+	  break;
+	case TypeKind::PROJECTION:
+	  subst = static_cast<ProjectionType *> (ty);
+	  break;
+	default:
+	  rust_unreachable ();
+	}
 
-	  size_t i = solution_index;
-	  for (auto &region : adt->get_used_arguments ().get_regions ())
-	    {
-	      (void) region;
-	      if (i > solution_index)
-		result += ", ";
-	      result += solutions[i].as_string ();
-	      i++;
-	    }
-	  for (auto &param : adt->get_substs ())
-	    {
-	      if (i > solution_index)
-		result += ", ";
-	      result += param.get_type_representation ().as_string ();
-	      result += "=";
-	      result += solutions[i].as_string ();
-	      i++;
-	    }
+      result += ty->get_name ();
+      result += "<";
 
-	  result += ">";
+      size_t i = solution_index;
+      for (auto &region : subst->get_used_arguments ().get_regions ())
+	{
+	  (void) region;
+	  if (i > solution_index)
+	    result += ", ";
+	  result += solutions[i].as_string ();
+	  i++;
 	}
-      else
+      for (auto &param : subst->get_substs ())
 	{
-	  rust_sorry_at (
-	    ty->get_ref (),
-	    "This is a compiler bug: Unhandled type in variance analysis");
+	  if (i > solution_index)
+	    result += ", ";
+	  result += param.get_type_representation ().as_string ();
+	  result += "=";
+	  result += solutions[i].as_string ();
+	  i++;
 	}
+
+      result += ">";
       rust_debug ("%s", result.c_str ());
     }
 }
-- 
2.50.1



More information about the Gcc-rust mailing list