[gcc r14-7936] gccrs: [E0573] Something other than type was used

Arthur Cohen cohenarthur@gcc.gnu.org
Tue Jan 16 18:08:47 GMT 2024


https://gcc.gnu.org/g:04d6111e6e68cb4b7f53027ed35a47241dfc7165

commit r14-7936-g04d6111e6e68cb4b7f53027ed35a47241dfc7165
Author: Muhammad Mahad <mahadtxt@gmail.com>
Date:   Fri Aug 18 16:28:34 2023 +0500

    gccrs: [E0573] Something other than type was used
    
    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>

Diff:
---
 gcc/rust/typecheck/rust-hir-type-check-type.cc | 14 +++++++++++---
 gcc/testsuite/rust/compile/issue-2479.rs       |  4 ++--
 2 files changed, 13 insertions(+), 5 deletions(-)

diff --git a/gcc/rust/typecheck/rust-hir-type-check-type.cc b/gcc/rust/typecheck/rust-hir-type-check-type.cc
index b3125f7e1a5..4db48f03bd2 100644
--- a/gcc/rust/typecheck/rust-hir-type-check-type.cc
+++ b/gcc/rust/typecheck/rust-hir-type-check-type.cc
@@ -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);
 	}
 
diff --git a/gcc/testsuite/rust/compile/issue-2479.rs b/gcc/testsuite/rust/compile/issue-2479.rs
index 4a0d3547b75..5cc403eef9e 100644
--- a/gcc/testsuite/rust/compile/issue-2479.rs
+++ b/gcc/testsuite/rust/compile/issue-2479.rs
@@ -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 }
 }
 }


More information about the Gcc-cvs mailing list