From 4f58a20d7e27aaa63e21dba072013b496baa94d1 Mon Sep 17 00:00:00 2001 From: Raiki Tamura Date: Fri, 9 Aug 2024 23:56:55 +0900 Subject: gccrs: Add typecheck for path patterns. gcc/rust/ChangeLog: * hir/tree/rust-hir.cc (Item::item_kind_string): New function. * hir/tree/rust-hir.h: New function. * typecheck/rust-hir-type-check-expr.cc (TypeCheckExpr::visit): Modify to check all arms in match expressions even if some of them has errors. * typecheck/rust-hir-type-check-pattern.cc (TypeCheckPattern::visit): Add and fix check for path patterns. gcc/testsuite/ChangeLog: * rust/compile/issue-2324-2.rs: Fix error message. * rust/compile/match9.rs: New test. Signed-off-by: Raiki Tamura --- gcc/testsuite/rust/compile/issue-2324-2.rs | 2 +- gcc/testsuite/rust/compile/match9.rs | 30 ++++++++++++++++++++++++++++++ 2 files changed, 31 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/rust/compile/match9.rs (limited to 'gcc/testsuite/rust/compile') diff --git a/gcc/testsuite/rust/compile/issue-2324-2.rs b/gcc/testsuite/rust/compile/issue-2324-2.rs index 5ef4014..1530b00 100644 --- a/gcc/testsuite/rust/compile/issue-2324-2.rs +++ b/gcc/testsuite/rust/compile/issue-2324-2.rs @@ -6,7 +6,7 @@ enum State { fn print_on_failure(state: &State) { match *state { State::Succeeded => (), - State::Failed => (), // { dg-error "expected unit struct, unit variant or constant, found tuple variant" } + State::Failed => (), // { dg-error "expected unit struct, unit variant or constant, found struct variant" } _ => () } } diff --git a/gcc/testsuite/rust/compile/match9.rs b/gcc/testsuite/rust/compile/match9.rs new file mode 100644 index 0000000..115d458 --- /dev/null +++ b/gcc/testsuite/rust/compile/match9.rs @@ -0,0 +1,30 @@ +enum E { + A(), + B, +} + +const CONST_E: E = E::A(); + +static static_e: E = E::A(); + +type type_alias = E; + +fn f(e: E) { + match e { + E::A => {} + // { dg-error "expected unit struct, unit variant or constant, found tuple variant .E::A." "" { target *-*-* } .-1 } + E::B => {} + crate::CONST_E => {} + crate::type_alias => {} + // { dg-error "expected unit struct, unit variant or constant, found type alias .crate::type_alias." "" { target *-*-* } .-1 } + crate::E => {} + // { dg-error "expected unit struct, unit variant or constant, found enum .crate::E." "" { target *-*-* } .-1 } + crate::static_e => {} + // { dg-error "expected unit struct, unit variant or constant, found static .crate::static_e." "" { target *-*-* } .-1 } + crate::f => {} + // { dg-error "expected unit struct, unit variant or constant, found function .crate::f." "" { target *-*-* } .-1 } + _ => {} + } +} + +fn main() {} -- cgit v1.1