]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
gccrs: [E0769] Use of tuple struct/variant in struct variant
authorMuhammad Mahad <mahadtxt@gmail.com>
Wed, 16 Aug 2023 10:30:45 +0000 (15:30 +0500)
committerArthur Cohen <arthur.cohen@embecosm.com>
Tue, 16 Jan 2024 18:00:34 +0000 (19:00 +0100)
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>
gcc/rust/typecheck/rust-hir-type-check-pattern.cc
gcc/testsuite/rust/compile/match4.rs

index 18e9b3442ac8322b83030d8d5fad8ab1d19b40b7..8e9dd556a3c0ff92e03bd74b8449abb76bda3f2b 100644 (file)
@@ -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;
index 35b90a64fa5f9933b445cc79dc9daaf3d1334aa4..552aa163db504e6f459b5e9557f469bd2050871e 100644 (file)
@@ -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 } => {}
     }
 }