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]>
---
This change was merged into the gccrs repository and is posted here for
upstream visibility and potential drive-by review, as requested by GCC
release managers.
Each commit email contains a link to its details on github from where you can
find the Pull-Request and associated discussions.
Commit on github:
https://github.com/Rust-GCC/gccrs/commit/fe109d6e5196e62d1e092d1f1e0b172d381461ed
The commit has NOT been mentioned in any issue.
The commit has been mentioned in the following pull-request(s):
- https://github.com/Rust-GCC/gccrs/pull/4975
.../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 3f4e35b3a..3c6270bf2 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 000000000..b2c1cae4a
--- /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() {}
base-commit: c8ddc01dca52f9494c2ae12524b89425528efb16
--
2.55.0