aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMuhammad Mahad <mahadtxt@gmail.com>2023-08-18 16:28:34 +0500
committerArthur Cohen <arthur.cohen@embecosm.com>2024-01-16 19:00:32 +0100
commit04d6111e6e68cb4b7f53027ed35a47241dfc7165 (patch)
tree724db9a35a0b403b413bb4750a3264bf7d102779
parent3d75a9b0edf7b76ac45246e4591a9ab437f54825 (diff)
downloadgcc-04d6111e6e68cb4b7f53027ed35a47241dfc7165.zip
gcc-04d6111e6e68cb4b7f53027ed35a47241dfc7165.tar.gz
gcc-04d6111e6e68cb4b7f53027ed35a47241dfc7165.tar.bz2
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>
-rw-r--r--gcc/rust/typecheck/rust-hir-type-check-type.cc14
-rw-r--r--gcc/testsuite/rust/compile/issue-2479.rs4
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 b3125f7..4db48f0 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 4a0d354..5cc403e 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 }
}
}