]> git.ipfire.org Git - thirdparty/gcc.git/commit
gccrs: empty match expressions should resolve to !
authorPhilip Herron <herron.philip@googlemail.com>
Thu, 21 Nov 2024 17:36:34 +0000 (17:36 +0000)
committerArthur Cohen <arthur.cohen@embecosm.com>
Fri, 21 Mar 2025 11:33:02 +0000 (12:33 +0100)
commite4a92d706b30fb2e5c39161dc1ff9f4eabbec983
tree63a39eb2b7919eeb6b933985ed8e338631e5fc6a
parent6e90ff47c658f5a5e97b4b3ae1501efb6e076303
gccrs: empty match expressions should resolve to !

This is a special case in Rust and the ! type can unify with pretty much
anything its almost a inference variable and a unit-type for special cases.

Fixes Rust-GCC/gccrs#3231
Fixes Rust-GCC/gccrs#2567

gcc/rust/ChangeLog:

* backend/rust-compile-expr.cc (check_match_scrutinee): check for empty match
(CompileExpr::visit): fix assertion
* checks/errors/rust-hir-pattern-analysis.cc (check_match_usefulness): check for empty
* typecheck/rust-hir-type-check-expr.cc (TypeCheckExpr::visit): resolve to !

gcc/testsuite/ChangeLog:

* rust/compile/exhaustiveness1.rs: remove bad check
* rust/compile/issue-2567-1.rs: New test.
* rust/compile/issue-2567-2.rs: New test.
* rust/compile/issue-2567-3.rs: New test.
* rust/compile/issue-3231.rs: New test.

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
gcc/rust/backend/rust-compile-expr.cc
gcc/rust/checks/errors/rust-hir-pattern-analysis.cc
gcc/rust/typecheck/rust-hir-type-check-expr.cc
gcc/testsuite/rust/compile/exhaustiveness1.rs
gcc/testsuite/rust/compile/issue-2567-1.rs [new file with mode: 0644]
gcc/testsuite/rust/compile/issue-2567-2.rs [new file with mode: 0644]
gcc/testsuite/rust/compile/issue-2567-3.rs [new file with mode: 0644]
gcc/testsuite/rust/compile/issue-3231.rs [new file with mode: 0644]