From: Muhammad Mahad Date: Fri, 18 Aug 2023 11:28:34 +0000 (+0500) Subject: gccrs: [E0573] Something other than type was used X-Git-Tag: basepoints/gcc-15~2203 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=04d6111e6e68cb4b7f53027ed35a47241dfc7165;p=thirdparty%2Fgcc.git 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 --- diff --git a/gcc/rust/typecheck/rust-hir-type-check-type.cc b/gcc/rust/typecheck/rust-hir-type-check-type.cc index b3125f7e1a5e..4db48f03bd20 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 (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 4a0d3547b750..5cc403eef9e2 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 } } }