Skip to content

Commit 1c4f312

Browse files
MahadMuhammadphilberty
authored andcommitted
gccrs: [E0769] Use of tuple struct/variant in struct variant
gcc/rust/ChangeLog: * typecheck/rust-hir-type-check-pattern.cc (TypeCheckPattern::visit): Added error code and rich location. gcc/testsuite/ChangeLog: * rust/compile/match4.rs: Updated new error commment. Signed-off-by: Muhammad Mahad <mahadtxt@gmail.com>
1 parent aea1005 commit 1c4f312

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

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

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -184,8 +184,14 @@ TypeCheckPattern::visit (HIR::StructPattern &pattern)
184184
{
185185
std::string variant_type
186186
= TyTy::VariantDef::variant_type_string (variant->get_variant_type ());
187-
rust_error_at (pattern.get_locus (),
188-
"expected struct variant, found %s variant %s",
187+
188+
rich_location rich_locus (line_table, pattern.get_locus ());
189+
std::string rich_msg = "use the tuple variant pattern syntax instead "
190+
+ variant->get_identifier () + "(_)";
191+
rich_locus.add_fixit_replace (rich_msg.c_str ());
192+
193+
rust_error_at (rich_locus, ErrorCode::E0769,
194+
"%s variant %qs written as struct variant",
189195
variant_type.c_str (),
190196
variant->get_identifier ().c_str ());
191197
return;

gcc/testsuite/rust/compile/match4.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ fn inspect(f: Foo) {
1010
Foo::A => {}
1111
Foo::B => {}
1212
Foo::C { a } => {}
13-
// { dg-error "expected struct variant, found tuple variant C" "" { target *-*-* } .-1 }
13+
// { dg-error "tuple variant .C. written as struct variant" "" { target *-*-* } .-1 }
1414
Foo::D { x, y } => {}
1515
}
1616
}

0 commit comments

Comments
 (0)