Skip to content

Conversation

Lishin1215
Copy link
Contributor

fix #3556
The changes ensure that type lookup failures no longer trigger assertions.
If further support for this pattern is needed, I'm happy to discuss possible approaches further!

gcc/rust/ChangeLog:

* typecheck/rust-tyty-util.cc (TyVar::TyVar): Add null check to avoid ICE.
(TyVar::get_tyty): Return nullptr when lookup fails.
(TyVar::clone): Handle null base type safely.
(TyVar::monomorphized_clone): Add fallback for error types.

gcc/testsuite/ChangeLog:

* rust/compile/issue-3556.rs: New test.

Comment on lines 34 to 36
{
return;
}
Copy link
Member

Choose a reason for hiding this comment

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

Usually for single statement, we skip the braces...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for the review, @dkm
I've updated the code style to remove the unnecessary braces!

Comment on lines 45 to 47
if (!ok || lookup == nullptr)
{
return nullptr;
Copy link
Member

Choose a reason for hiding this comment

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

ditto

Comment on lines 106 to 108
{
return TyVar::get_implicit_infer_var (UNKNOWN_LOCATION);
}
Copy link
Member

Choose a reason for hiding this comment

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

ditto

Comment on lines 121 to 123
{
return TyVar::get_implicit_infer_var (UNKNOWN_LOCATION);
}
Copy link
Member

Choose a reason for hiding this comment

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

ditto

@Lishin1215 Lishin1215 force-pushed the 3556 branch 2 times, most recently from 28f220a to 841af29 Compare October 13, 2025 22:37
gcc/rust/ChangeLog:

	* typecheck/rust-tyty-util.cc (TyVar::TyVar): Add null check to avoid ICE.
	(TyVar::get_tyty): Return nullptr when lookup fails.
	(TyVar::clone): Handle null base type safely.
	(TyVar::monomorphized_clone): Add fallback for error types.

gcc/testsuite/ChangeLog:

	* rust/compile/issue-3556.rs: New test.

Signed-off-by: lishin <[email protected]>
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.

Actually really good idea on failure to return an implicit infer var... nice one

@philberty philberty added this pull request to the merge queue Oct 16, 2025
Merged via the queue into Rust-GCC:master with commit 0427d48 Oct 16, 2025
13 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 TyVar, at rust/typecheck/rust-tyty-util.cc:31

3 participants