https://gcc.gnu.org/g:4095f6869384565792a3ec43533b68f469537432

commit r17-5708-g4095f6869384565792a3ec43533b68f469537432
Author: Utkarsh Bahuguna <[email protected]>
Date:   Wed Oct 7 18:01:30 2026 +0530

    gccrs: Report non-exhaustive matches as E0004
    
    The non-exhaustive patterns error had no error code, while rustc reports
    it as E0004. Attach the code to it.
    
    Assisted-by: Claude Opus 5.5 (Anthropic)
    
    gcc/rust/ChangeLog:
    
            * checks/errors/rust-hir-pattern-analysis.cc
            (emit_exhaustiveness_error): Emit the error as E0004.
    
    gcc/testsuite/ChangeLog:
    
            * rust/compile/exhaustiveness6.rs: New test.
    
    Signed-off-by: Utkarsh Bahuguna <[email protected]>

Diff:
---
 gcc/rust/checks/errors/rust-hir-pattern-analysis.cc |  2 +-
 gcc/testsuite/rust/compile/exhaustiveness6.rs       | 18 ++++++++++++++++++
 2 files changed, 19 insertions(+), 1 deletion(-)

diff --git a/gcc/rust/checks/errors/rust-hir-pattern-analysis.cc 
b/gcc/rust/checks/errors/rust-hir-pattern-analysis.cc
index 3f4e35b3ada7..3c6270bf249d 100644
--- a/gcc/rust/checks/errors/rust-hir-pattern-analysis.cc
+++ b/gcc/rust/checks/errors/rust-hir-pattern-analysis.cc
@@ -1635,7 +1635,7 @@ emit_exhaustiveness_error (Resolver::TypeCheckContext 
*ctx,
          if (i != witness.get_stacks ().size () - 1)
            buf << " and ";
        }
-      rust_error_at (expr.get_scrutinee_expr ().get_locus (),
+      rust_error_at (expr.get_scrutinee_expr ().get_locus (), ErrorCode::E0004,
                     "non-exhaustive patterns: %s not covered",
                     buf.str ().c_str ());
     }
diff --git a/gcc/testsuite/rust/compile/exhaustiveness6.rs 
b/gcc/testsuite/rust/compile/exhaustiveness6.rs
new file mode 100644
index 000000000000..b2c1cae4a64f
--- /dev/null
+++ b/gcc/testsuite/rust/compile/exhaustiveness6.rs
@@ -0,0 +1,18 @@
+#![feature(no_core)]
+#![no_core]
+
+// Non-exhaustive matches report E0004, like rustc.
+
+enum E {
+    A(),
+    B(),
+}
+
+fn f(e: E) {
+    match e {
+        // { dg-error "non-exhaustive patterns: 'E::B..' not covered .E0004." 
"" { target *-*-* } .-1 }
+        E::A() => {}
+    }
+}
+
+fn main() {}

Reply via email to