Skip to content

Commit 8fcbb07

Browse files
MahadMuhammadCohenArthur
authored andcommitted
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 <[email protected]>
1 parent 3196ca3 commit 8fcbb07

File tree

2 files changed

+13
-5
lines changed

2 files changed

+13
-5
lines changed

gcc/rust/typecheck/rust-hir-type-check-type.cc

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -510,9 +510,17 @@ TypeCheckType::resolve_segments (
510510

511511
if (candidate.is_enum_candidate ())
512512
{
513-
rust_error_at (seg->get_locus (),
514-
"expected type, found variant of %s",
515-
tyseg->get_name ().c_str ());
513+
TyTy::ADTType *adt = static_cast<TyTy::ADTType *> (tyseg);
514+
auto last_variant = adt->get_variants ();
515+
TyTy::VariantDef *variant = last_variant.back ();
516+
517+
rich_location richloc (line_table, seg->get_locus ());
518+
richloc.add_fixit_replace ("not a type");
519+
520+
rust_error_at (richloc, ErrorCode::E0573,
521+
"expected type, found variant of %<%s::%s%>",
522+
adt->get_name ().c_str (),
523+
variant->get_identifier ().c_str ());
516524
return new TyTy::ErrorType (expr_id);
517525
}
518526

gcc/testsuite/rust/compile/issue-2479.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ enum Dragon {
55
}
66

77
fn oblivion() -> Dragon::Born {
8-
// { dg-error "expected type, found variant of Dragon" "" { target *-*-* } .-1 }
8+
// { dg-error "expected type, found variant of .Dragon::Born." "" { target *-*-* } .-1 }
99
// { dg-error "failed to resolve return type" "" { target *-*-* } .-2 }
1010
Dragon::Born
1111
}
@@ -17,6 +17,6 @@ enum Wizard {
1717

1818
trait Isengard {
1919
fn wizard(_: Wizard::Saruman);
20-
// { dg-error "expected type, found variant of Wizard" "" { target *-*-* } .-1 }
20+
// { dg-error "expected type, found variant of .Wizard::Saruman." "" { target *-*-* } .-1 }
2121
}
2222
}

0 commit comments

Comments
 (0)