Skip to content

rust: Fix ICE in function_set_parameters#4501

Merged
CohenArthur merged 1 commit into
Rust-GCC:masterfrom
riogu:issue-3919
Mar 31, 2026
Merged

rust: Fix ICE in function_set_parameters#4501
CohenArthur merged 1 commit into
Rust-GCC:masterfrom
riogu:issue-3919

Conversation

@riogu
Copy link
Copy Markdown
Contributor

@riogu riogu commented Mar 25, 2026

When lowering a function to HIR with a refutable pattern in its parameter pattern, we were ICE'ing due to a lack of checks for invalid refutable patterns. Fix this by erroring on invalid patterns while lowering a function.

Fixes #3919

gcc/rust/ChangeLog:

* hir/rust-ast-lower-item.cc (ASTLoweringItem::visit): added refutable pattern checks for function params.

gcc/testsuite/ChangeLog:

* rust/compile/issue-3919-ice-func-parms.rs: New test.

When lowering a function to HIR with a refutable pattern in its
parameter pattern, we were ICE'ing due to a lack of checks for invalid
refutable patterns. Fix this by erroring on invalid patterns while
lowering a function.

	Fixes Rust-GCC#3919

gcc/rust/ChangeLog:

	* hir/rust-ast-lower-item.cc (ASTLoweringItem::visit): added
	refutable pattern checks for function params.

gcc/testsuite/ChangeLog:

	* rust/compile/issue-3919-ice-func-parms.rs: New test.

Signed-off-by: Egas Ribeiro <egas.g.ribeiro@tecnico.ulisboa.pt>
Copy link
Copy Markdown
Member

@CohenArthur CohenArthur left a comment

Choose a reason for hiding this comment

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

Thank you, that's good work! I'm not sure that we'll keep that check here in the lowerer but it definitely improves the compiler for now, so I'm in favor of merging it :)

@CohenArthur CohenArthur added this pull request to the merge queue Mar 31, 2026
@riogu
Copy link
Copy Markdown
Contributor Author

riogu commented Mar 31, 2026

Thank you, that's good work! I'm not sure that we'll keep that check here in the lowerer but it definitely improves the compiler for now, so I'm in favor of merging it :)

I wasn't sure where to place it more naturally before the lowering phase, but i felt it would be an improvement anyway.
It might be interesting to add support for Irrefutability checks, since i noticed that there is an overall lack for these, and could be implemented as mentioned in this comment in rust-ast.h and rust-hir-pattern-abstract.h, and also mentioned by #2082.

// Pattern base HIR node
class Pattern : public Node, virtual public FullVisitable
{
  ...
  // possible virtual methods: is_refutable()
  ...
}

doing that would replace this fix with an equivalent solution calling is_refutable(), but would require implementing all the derived cases.

Merged via the queue into Rust-GCC:master with commit 593fb15 Mar 31, 2026
12 checks passed
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 in function_set_parameters, at rust/rust-gcc.cc:2259

2 participants