Skip to content

Conversation

@lowr
Copy link
Contributor

@lowr lowr commented Oct 19, 2025

This PR fixes an ICE during typeckecking tuple struct patterns. When the type of a tuple struct pattern's path is resolved to an enum, the path is expected to refer to an enum variant in a correct Rust program. However, it may refer to the enum itself, in which case we should emit an error.

Note that while #3917 reported that the given code had run into an ICE during AST lowering, it currently causes an ICE in typecheck at the same location as #3918. This PR therefore resolves both issues.

Fixes #3917
Fixes #3918
Fixes #3926

@lowr lowr force-pushed the fix/enum-in-tuple-struct-pat branch from a3c2e07 to 36d75ba Compare October 19, 2025 13:14
@Polygonalr
Copy link
Contributor

This also fixes the ICE for #3926, maybe you can add a test for it as well, thanks!

When we typecheck a tuple struct pattern and the type of its path is
an enum, it may refer to the enum itself and not a variant. Emit an
E0532 error on such cases.

Fixes Rust-GCC#3917
Fixes Rust-GCC#3918
Fixes Rust-GCC#3926

gcc/rust/ChangeLog:

	* typecheck/rust-hir-type-check-pattern.cc (TypeCheckPattern::visit): Emit
	an error when the path refers to an enum itself rather than its variant.

gcc/testsuite/ChangeLog:

	* rust/compile/match-tuplestructpattern-non-variant.rs: New test.

Signed-off-by: Ryo Yoshida <low.ryoshida@gmail.com>
@lowr lowr force-pushed the fix/enum-in-tuple-struct-pat branch from 36d75ba to a346043 Compare October 19, 2025 13:52
@lowr
Copy link
Contributor Author

lowr commented Oct 19, 2025

@Polygonalr Thanks for the heads up! I've updated the commit message and the PR description to include #3926.

I think the new test already covers the case, but let me know if I should tweak something.

Copy link
Member

@philberty philberty left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@philberty philberty added this pull request to the merge queue Oct 20, 2025
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Oct 20, 2025
@philberty philberty added this pull request to the merge queue Oct 20, 2025
Merged via the queue into Rust-GCC:master with commit 10ee102 Oct 20, 2025
13 checks passed
@github-project-automation github-project-automation bot moved this from Todo to Done in libcore 1.49 Oct 20, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Status: Done

3 participants