From: Utkarsh Bahuguna <[email protected]>
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]>
Tested on x86_64-pc-linux-gnu.
---
.../checks/errors/rust-hir-pattern-analysis.cc | 2 +-
gcc/testsuite/rust/compile/exhaustiveness6.rs | 18 ++++++++++++++++++
2 files changed, 19 insertions(+), 1 deletion(-)
create mode 100644 gcc/testsuite/rust/compile/exhaustiveness6.rs
diff --git a/gcc/rust/checks/errors/rust-hir-pattern-analysis.cc
b/gcc/rust/checks/errors/rust-hir-pattern-analysis.cc
index 3f4e35b3ada..3c6270bf249 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 00000000000..b2c1cae4a64
--- /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() {}
--
2.55.0