Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions gcc/rust/typecheck/rust-hir-type-check-pattern.cc
Original file line number Diff line number Diff line change
Expand Up @@ -182,8 +182,14 @@ TypeCheckPattern::visit (HIR::StructPattern &pattern)
{
std::string variant_type
= TyTy::VariantDef::variant_type_string (variant->get_variant_type ());
rust_error_at (pattern.get_locus (),
"expected struct variant, found %s variant %s",

rich_location rich_locus (line_table, pattern.get_locus ());
std::string rich_msg = "use the tuple variant pattern syntax instead "
+ variant->get_identifier () + "(_)";
rich_locus.add_fixit_replace (rich_msg.c_str ());

rust_error_at (rich_locus, ErrorCode::E0769,
"%s variant %qs written as struct variant",
variant_type.c_str (),
variant->get_identifier ().c_str ());
return;
Expand Down
2 changes: 1 addition & 1 deletion gcc/testsuite/rust/compile/match4.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ fn inspect(f: Foo) {
Foo::A => {}
Foo::B => {}
Foo::C { a } => {}
// { dg-error "expected struct variant, found tuple variant C" "" { target *-*-* } .-1 }
// { dg-error "tuple variant .C. written as struct variant" "" { target *-*-* } .-1 }
Foo::D { x, y } => {}
}
}