From: Muhammad Mahad Date: Wed, 16 Aug 2023 10:30:45 +0000 (+0500) Subject: gccrs: [E0769] Use of tuple struct/variant in struct variant X-Git-Tag: basepoints/gcc-15~2193 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=af2ae3076418f7908cd4f7bb842718070429fdad;p=thirdparty%2Fgcc.git 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 --- diff --git a/gcc/rust/typecheck/rust-hir-type-check-pattern.cc b/gcc/rust/typecheck/rust-hir-type-check-pattern.cc index 18e9b3442ac8..8e9dd556a3c0 100644 --- a/gcc/rust/typecheck/rust-hir-type-check-pattern.cc +++ b/gcc/rust/typecheck/rust-hir-type-check-pattern.cc @@ -184,8 +184,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; diff --git a/gcc/testsuite/rust/compile/match4.rs b/gcc/testsuite/rust/compile/match4.rs index 35b90a64fa5f..552aa163db50 100644 --- a/gcc/testsuite/rust/compile/match4.rs +++ b/gcc/testsuite/rust/compile/match4.rs @@ -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 } => {} } }