]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
gccrs: [E0573] Something other than type was used
authorMuhammad Mahad <mahadtxt@gmail.com>
Fri, 18 Aug 2023 11:28:34 +0000 (16:28 +0500)
committerArthur Cohen <arthur.cohen@embecosm.com>
Tue, 16 Jan 2024 18:00:32 +0000 (19:00 +0100)
gcc/rust/ChangeLog:

* typecheck/rust-hir-type-check-type.cc:
Added last variant name, errorcode & rich location. for enum candidates.

gcc/testsuite/ChangeLog:

* rust/compile/issue-2479.rs: Updated comment.

Signed-off-by: Muhammad Mahad <mahadtxt@gmail.com>
gcc/rust/typecheck/rust-hir-type-check-type.cc
gcc/testsuite/rust/compile/issue-2479.rs

index b3125f7e1a5e95015d9a5d0be94569b44edbea51..4db48f03bd2082c42d88273ef746505e6b62a372 100644 (file)
@@ -510,9 +510,17 @@ TypeCheckType::resolve_segments (
 
       if (candidate.is_enum_candidate ())
        {
-         rust_error_at (seg->get_locus (),
-                        "expected type, found variant of %s",
-                        tyseg->get_name ().c_str ());
+         TyTy::ADTType *adt = static_cast<TyTy::ADTType *> (tyseg);
+         auto last_variant = adt->get_variants ();
+         TyTy::VariantDef *variant = last_variant.back ();
+
+         rich_location richloc (line_table, seg->get_locus ());
+         richloc.add_fixit_replace ("not a type");
+
+         rust_error_at (richloc, ErrorCode::E0573,
+                        "expected type, found variant of %<%s::%s%>",
+                        adt->get_name ().c_str (),
+                        variant->get_identifier ().c_str ());
          return new TyTy::ErrorType (expr_id);
        }
 
index 4a0d3547b7500b24f6995559f5f24df6e7bfc9c1..5cc403eef9e2063f4ab03c28b398d656e12533bd 100644 (file)
@@ -5,7 +5,7 @@ enum Dragon {
 }
 
 fn oblivion() -> Dragon::Born {
-// { dg-error "expected type, found variant of Dragon" "" { target *-*-* } .-1 }
+// { dg-error "expected type, found variant of .Dragon::Born." "" { target *-*-* } .-1 }
 // { dg-error "failed to resolve return type" "" { target *-*-* } .-2 }
     Dragon::Born
 }
@@ -17,6 +17,6 @@ enum Wizard {
 
 trait Isengard {
     fn wizard(_: Wizard::Saruman);
-    // { dg-error "expected type, found variant of Wizard" "" { target *-*-* } .-1 }
+    // { dg-error "expected type, found variant of .Wizard::Saruman." "" { target *-*-* } .-1 }
 }
 }