Skip to content

gccrs: Fix ICE in path pattern refutability - #4808

Open
u7k4rs6 wants to merge 1 commit into
Rust-GCC:masterfrom
u7k4rs6:fix-4732-path-pattern-refutable
Open

u7k4rs6 wants to merge 1 commit into
Rust-GCC:masterfrom
u7k4rs6:fix-4732-path-pattern-refutable

Conversation

@u7k4rs6

@u7k4rs6 u7k4rs6 commented Aug 22, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #4732

PathPattern::is_refutable looked up the final path segment's HirId in the HIR item map. A path segment does not carry the HirId of the referenced item, so lookup_hir_item always failed and path patterns in let bindings and function parameters reached rust_internal_error_at.

The fix resolves the path using the path expression's NodeId, then maps the resolved definition through lookup_node_to_hir to find the HIR item. Both Values and Types namespaces are checked.

Enum variants are stored separately from regular HIR items, so failed item lookup falls back to checking the scrutinee type. Non-enum ADTs are also handled to avoid another ICE for unit struct patterns.

This adds the first rust/hir -> rust/resolve include. No build changes are needed since rust/resolve is already on the include path, and there is no include cycle. rust-hir-pattern-abstract.cc already includes rust-hir-type-check.h and calls TypeCheckContext::get () in is_refutable_with_lookup, so this file already depends on a later pass. I can move the lookup into PatternChecker if the direct dependency is considered undesirable, but that would require threading the context through the is_refutable virtual interface since it recurses into nested patterns.

refutable-path.rs now checks the expected diagnostics instead of using dg-ice, covering let bindings, function parameters, an associated constant, and a const generic. irrefutable-path-single-variant.rs was added to directly test single-variant enums and unit structs without hitting the existing backend ICE from #4553.

irrefutable-path.rs is left unchanged and keeps its dg-ice, but now reaches a different ICE. The single-variant enum parameter is correctly considered irrefutable, so compilation proceeds into the backend and hits the pre-existing function_set_parameters assertion from #4553, which irrefutable-slice.rs already XFAILs on.

Validation on the rebased head: 11,598 expected passes, 86 expected failures, 10 unsupported, zero unexpected failures.

@u7k4rs6

u7k4rs6 commented Sep 4, 2026

Copy link
Copy Markdown
Contributor Author

Reworked the hunk and replaced rust_unreachable since non-ADT paths are refutable constants.
Added tests for associated consts and const generics and rebased on master, suite is clean.

@powerboat9

Copy link
Copy Markdown
Collaborator

For

	* rust/compile/refutable-path.rs:
	Remove dg-ice and add associated const and const generic cases.

could you stick more of the second line after the colon?

@u7k4rs6
u7k4rs6 force-pushed the fix-4732-path-pattern-refutable branch from 3ec7478 to dfe4ea5 Compare September 4, 2026 13:11
@u7k4rs6

u7k4rs6 commented Sep 4, 2026

Copy link
Copy Markdown
Contributor Author

@powerboat9 Done with the re- wrapping

@u7k4rs6
u7k4rs6 force-pushed the fix-4732-path-pattern-refutable branch 3 times, most recently from 3aa30bc to 721545d Compare September 17, 2026 13:25

@CohenArthur CohenArthur left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The code changes look good to me. I reached out privately for the commit message which I think needs to be changed.

@u7k4rs6
u7k4rs6 force-pushed the fix-4732-path-pattern-refutable branch 3 times, most recently from 75d0a5c to 757dc19 Compare September 19, 2026 18:59
Resolve path patterns through their node id instead of the last segment,
handling variant, impl, and trait mappings before falling back to the
scrutinee type.

Closes Rust-GCC#4732. A single variant enum is now seen as
irrefutable, so compilation reaches the backend and trips the older
assertion from Rust-GCC#4553, which is why irrefutable-path.rs
keeps its dg-ice.

gcc/rust/ChangeLog:

	* hir/tree/rust-hir-pattern-abstract.cc (PathPattern::is_refutable):
	Resolve path patterns through the node to HIR mappings instead of
	calling rust_unreachable.

gcc/testsuite/ChangeLog:

	* rust/compile/refutable-path.rs: Remove dg-ice.
	* rust/compile/irrefutable-path-single-variant.rs: New test.

Signed-off-by: Utkarsh Bahuguna <utkarshbahuguna10@gmail.com>
@u7k4rs6
u7k4rs6 force-pushed the fix-4732-path-pattern-refutable branch from 757dc19 to 5f4b7be Compare September 28, 2026 05:59
@u7k4rs6
u7k4rs6 requested a review from CohenArthur September 29, 2026 18:49

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ICE failed to lookup hir item during refutability checks

3 participants