[COMMITTED 42/83] gccrs: Add missing handling to variance analysis

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


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

gcc/rust/ChangeLog:

	* typecheck/rust-tyty-variance-analysis.cc (GenericTyVisitorCtx::lookup_or_add_type):
	handle the other tyty types

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

diff --git a/gcc/rust/typecheck/rust-tyty-variance-analysis.cc b/gcc/rust/typecheck/rust-tyty-variance-analysis.cc
index ca8e9f6b1a8..6c6877ef9ec 100644
--- a/gcc/rust/typecheck/rust-tyty-variance-analysis.cc
+++ b/gcc/rust/typecheck/rust-tyty-variance-analysis.cc
@@ -366,15 +366,29 @@ GenericTyVisitorCtx::lookup_or_add_type (HirId hir_id)
     }
 
   SubstitutionRef *subst = nullptr;
-  if (auto adt = ty->try_as<ADTType> ())
-    {
-      subst = adt;
-    }
-  else
+  switch (ty->get_kind ())
     {
+    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_sorry_at (
 	ty->get_locus (),
 	"This is a compiler bug: Unhandled type in variance analysis");
+      break;
     }
   rust_assert (subst != nullptr);
 
-- 
2.50.1



More information about the Gcc-rust mailing list