Skip to content

parser: fix tuple field parsing in offset_of - #23287

Open
Siteshcodes wants to merge 3 commits into
rust-lang:masterfrom
Siteshcodes:fix-offset-of-float-index
Open

parser: fix tuple field parsing in offset_of#23287
Siteshcodes wants to merge 3 commits into
rust-lang:masterfrom
Siteshcodes:fix-offset-of-float-index

Conversation

@Siteshcodes

@Siteshcodes Siteshcodes commented Sep 3, 2026

Copy link
Copy Markdown

Fixes #23178.

When using offset_of with nested tuple fields such as 0.1.1.1, the lexer parses parts of the field path (0.1 and 1.1) as float literals. This makes offset_of reject the expression with a syntax error.

This PR splits float literals while parsing offset_of into field indices and dots, so the resulting events match the structure expected by OFFSET_OF_EXPR. This follows the same general approach used by rustc in break_up_float.

Also adds an inline regression test covering nested tuple fields.

AI disclosure: Used AI as an exploratory tool to navigate the parser/event plumbing and help with the refactoring.

@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Sep 3, 2026
@Siteshcodes

Copy link
Copy Markdown
Author

The Rust, Rust Cross, rustfmt, clippy, miri, and analysis-stats checks pass.

The remaining failures are unrelated to this PR:

  • proc-macro-srv (windows): failure in existing master code in crates/proc-macro-srv/src/dylib.rs
  • Typo Check: existing typos in unrelated files

I reproduced the relevant failures locally and confirmed they are not introduced by this change.

@ChayimFriedman2

Copy link
Copy Markdown
Contributor

I suspect you used AI without disclosing that. Please note that our AI policy requires disclosure. Make sure to read the policy and follow it.

@Siteshcodes

Copy link
Copy Markdown
Author

Thanks for taking a look. To be fully transparent about AI usage per the policy:

Where AI helped: I used AI as an exploratory tool to navigate event.rs and syntax-bridge, trace how FloatSplitHack was originally wired up in commit 6fa6efe, and help deduplicate the float-splitting helper between FIELD_EXPR and offset_of.
What I understand and wrote: The core problem is that the lexer tokenizes 0.1 into a single FLOAT_NUMBER. In standard field access (foo.0.1), this is split into nested FIELD_EXPR nodes. offset_of needs flat NAME_REF and DOT tokens directly under OFFSET_OF_EXPR. I adapted the parsing in atom.rs, ensured the CST output matches this flat structure, and added the inline test fixture.
rustc citation: This mirrors how rustc handles float field indices in compiler/rustc_parse/src/parser/expr.rs via break_up_float().

Happy to make any adjustments or refactor further if you’d prefer a different approach here.

@ShoyuVanilla

Copy link
Copy Markdown
Member

Tests:

* `cargo fmt --all -- --check`

* `cargo test -p parser`

* `cargo test -p syntax-bridge -p mbe`

* `git diff --check`

I guess no human would write such section to PR description

@Siteshcodes

Copy link
Copy Markdown
Author

Fair catch — that template was indeed generated when I first opened the PR. I've updated the PR description now in my own words.

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

Labels

S-waiting-on-review Status: Awaiting review from the assignee but also interested parties.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

FP Syntax Error in Expansion: expected integer, identifier, self, super, crate, or Self tuple type

4 participants