Skip to content

fix: Panic on accessing numeric fields in unions - #23229

Merged
ChayimFriedman2 merged 1 commit into
rust-lang:masterfrom
Wilfred:fix/union-tuple-index-panic
Aug 25, 2026
Merged

ChayimFriedman2 merged 1 commit into
rust-lang:masterfrom
Wilfred:fix/union-tuple-index-panic

Conversation

@Wilfred

@Wilfred Wilfred commented Aug 25, 2026

Copy link
Copy Markdown
Contributor

When writing foo.0 where foo is a union, we'd end up panicking with:

Failed to make ast node `syntax::ast::generated::nodes::Name` from text mod 0;

This is because make::name() requires a legal ident. In 480db31 we added checks for numeric fields (i.e. .0 instead of .foo) in several code paths but missed the union case.

Rather than adding another check, just change the fix to never be offered when the field name isn't a valid identifier.

Add a unit test for the union case too.

AI disclosure: Code partly written by GPT-5.6, review and commit message by me.

When writing `foo.0` where `foo` is a union, we'd end up panicking with:

    Failed to make ast node `syntax::ast::generated::nodes::Name` from text mod 0;

This is because `make::name()` requires a legal ident. In
480db31 we added checks for numeric
fields (i.e. `.0` instead of `.foo`) in several code paths but missed
the union case.

Rather than adding another check, just change the fix to never be
offered when the field name isn't a valid identifier.

Add a unit test for the union case too.

AI disclosure: Code partly written by GPT-5.6, review and commit
message by me.
@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Aug 25, 2026
@ChayimFriedman2
ChayimFriedman2 added this pull request to the merge queue Aug 25, 2026
Merged via the queue into rust-lang:master with commit 72ec8f1 Aug 25, 2026
18 checks passed
@rustbot rustbot removed the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Aug 25, 2026
@Wilfred
Wilfred deleted the fix/union-tuple-index-panic branch August 25, 2026 14:30
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.

3 participants