Skip to content

Reject invalid literal suffixes in tuple indexing, tuple struct indexing, and struct field name position #145463

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

jieyouxu
Copy link
Member

@jieyouxu jieyouxu commented Aug 15, 2025

Tracking issue: #60210
Closes #60210

Summary

Bump the "suffixes on a tuple index are invalid" non-lint pseudo future-incompatibility warning (#60210)1 to a hard error across all editions, rejecting the remaining carve outs from accidentally accepted invalid suffixes since Rust 1.27.

What specifically breaks?

Code that still relied on invalid {i,u}{32,size} suffixes being temporarily accepted by #60186 as an ecosystem impact mitigation measure (cf. #60138). Specifically, the following cases (particularly the construction of these forms in proc macros like reported in #60138):

Position 1: Invalid {i,u}{32,size} suffixes in tuple indexing

fn main() {
    let _x = (42,).0invalid; // Already error, already rejected by #59421
    let _x = (42,).0i8;      // Already error, not one of the #60186 carve outs.
    let _x = (42,).0usize;   // warning: suffixes on a tuple index are invalid
}

Position 2: Invalid {i,u}{32,size} suffixes in tuple struct indexing

fn main() {
    struct X(i32);
    let _x = X(42);
	let _x = _x.0invalid; // Already error, already rejected by #59421
    let _x = _x.0i8;      // Already error, not one of the #60186 carve outs.
    let _x = _x.0usize;   // warning: suffixes on a tuple index are invalid
}

Position 3: Invalid {i,u}{32,size} suffixes in numeric struct field names

fn main() {
    struct X(i32, i32, i32);
    let _x = X(1, 2, 3);
    let _y = X { 0usize: 42, 1: 42, 2: 42 };    // warning: suffixes on a tuple index are invalid
	match _x {
        X { 0usize: 1, 1: 2, 2: 3 } => todo!(), // warning: suffixes on a tuple index are invalid
        _ => {}
    }
}

Position 4: Invalid {i,u}{32,size} suffixes in std::mem::offset_of!

While investigating the warning, unfortunately I noticed std::mem::offset_of! also happens to use the "expect no suffix" code path which had the carve outs. So this was accepted since Rust 1.77.0 with the same FCW:

fn main() {
    #[repr(C)]
    pub struct Struct<T>(u8, T);

    assert_eq!(std::mem::offset_of!(Struct<u32>, 0usize), 0);
    //~^ WARN suffixes on a tuple index are invalid
}

The above forms in proc macros

For instance, constructions like (see tracking issue #60210):

let i = 0;
quote! { foo.$i }

where the user needs to actually write

let i = syn::Index::from(0);
quote! { foo.$i }

Crater results

Conducted a crater run (#145463 (comment)).

Review remarks

  • Commits 1-3 expands the test coverage to better reflect the current situation before doing any functional changes.
  • Commit 4 is an intentional breaking change. We bump the non-lint "suffixes on a tuple index are invalid" warning into a hard error. Thus, this will need a crater run and a T-lang FCP.

Tasks

  • Run crater to check if anyone is still relying on this being not a hard error. Determine degree of ecosystem breakage.
  • If degree of breakage seems acceptable, draft nomination report for T-lang for FCP.
  • Determine hard error on Edition 2024+, or on all editions.

Footnotes

  1. The FCW was implemented as a non-lint warning (meaning it has no associated lint name, and you can't #![deny(..)] it) because spans coming from proc macros could not be distinguished from regular field access. This warning was also intentionally impossible to silence. See https://github.com/rust-lang/rust/pull/60186#issuecomment-485581694.

@jieyouxu jieyouxu added A-grammar Area: The grammar of Rust A-parser Area: The lexing & parsing of Rust source code to an AST T-lang Relevant to the language team T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. needs-fcp This change is insta-stable, or significant enough to need a team FCP to proceed. A-proc-macros Area: Procedural macros labels Aug 15, 2025
@rustbot rustbot added A-tidy Area: The tidy tool T-bootstrap Relevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap) labels Aug 15, 2025
@jieyouxu jieyouxu added the needs-crater This change needs a crater run to check for possible breakage in the ecosystem. label Aug 15, 2025
@jieyouxu
Copy link
Member Author

@bors try

@rust-bors

This comment has been minimized.

rust-bors bot added a commit that referenced this pull request Aug 16, 2025
[WIP] Reject invalid literal suffixes in tuple indexing, tuple struct indexing, and struct field name position
@rust-bors
Copy link

rust-bors bot commented Aug 16, 2025

☀️ Try build successful (CI)
Build commit: c6f1a85 (c6f1a85c8f06c93ddc6200caf413929a2e7e7dd6, parent: cd7cbe818e4a66d46fe2df993d1b8518eba8a5cd)

@jieyouxu
Copy link
Member Author

@craterbot check

@craterbot
Copy link
Collaborator

👌 Experiment pr-145463 created and queued.
🤖 Automatically detected try build c6f1a85
🔍 You can check out the queue and this experiment's details.

ℹ️ Crater is a tool to run experiments across parts of the Rust ecosystem. Learn more

@craterbot craterbot added S-waiting-on-crater Status: Waiting on a crater run to be completed. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Aug 16, 2025
@jieyouxu jieyouxu removed the needs-crater This change needs a crater run to check for possible breakage in the ecosystem. label Aug 16, 2025
@craterbot
Copy link
Collaborator

🚧 Experiment pr-145463 is now running

ℹ️ Crater is a tool to run experiments across parts of the Rust ecosystem. Learn more

@craterbot
Copy link
Collaborator

🎉 Experiment pr-145463 is completed!
📊 7 regressed and 4 fixed (683072 total)
📰 Open the summary report.

⚠️ If you notice any spurious failure please add them to the denylist!
ℹ️ Crater is a tool to run experiments across parts of the Rust ecosystem. Learn more

@craterbot craterbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-crater Status: Waiting on a crater run to be completed. labels Aug 18, 2025
@jieyouxu jieyouxu changed the title [WIP] Reject invalid literal suffixes in tuple indexing, tuple struct indexing, and struct field name position Reject invalid literal suffixes in tuple indexing, tuple struct indexing, and struct field name position Aug 18, 2025
@jieyouxu jieyouxu marked this pull request as ready for review August 18, 2025 13:31
@rustbot
Copy link
Collaborator

rustbot commented Aug 18, 2025

r? @wesleywiser

rustbot has assigned @wesleywiser.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

@jieyouxu
Copy link
Member Author

jieyouxu commented Aug 18, 2025

Nominating for T-lang FCP. Please refer to PR description for request.

@rustbot label: +I-lang-nominated

@rustbot rustbot added the I-lang-nominated Nominated for discussion during a lang team meeting. label Aug 18, 2025
Copy link
Member

@fmease fmease left a comment

Choose a reason for hiding this comment

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

r=me after nits and if/once T-lang approves with a fFCP-merge.

@fmease fmease assigned fmease and unassigned wesleywiser Aug 18, 2025
@fmease fmease added S-waiting-on-team Status: Awaiting decision from the relevant subteam (see the T-<team> label). and removed T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-bootstrap Relevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap) S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Aug 18, 2025
To make it more obvious what it's testing.

This is its own commit to make git blame easier.
Actually, the accidentally accepted invalid suffixes also include tuple
struct indexing positions, struct numeral field name positions. So
before changing anything, first expand test coverage, so we can observe
the effect of bumping the non-lint pseudo-FCW warning into a hard error.
@rustbot rustbot added the T-bootstrap Relevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap) label Aug 18, 2025
@rustbot
Copy link
Collaborator

rustbot commented Aug 18, 2025

This PR was rebased onto a different master commit. Here's a range-diff highlighting what actually changed.

Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers.

@jieyouxu
Copy link
Member Author

Addressed nits in (range-diff)1

Footnotes

  1. So nice <3

@fmease fmease removed the T-bootstrap Relevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap) label Aug 18, 2025
@traviscross traviscross added the P-lang-drag-1 Lang team prioritization drag level 1. https://rust-lang.zulipchat.com/#narrow/channel/410516-t-lang label Aug 18, 2025
@traviscross
Copy link
Contributor

Let's do it. Thanks @jieyouxu for putting it forward and for the great write-up.

@rfcbot fcp merge

@rfcbot
Copy link
Collaborator

rfcbot commented Aug 18, 2025

Team member @traviscross has proposed to merge this. The next step is review by the rest of the tagged team members:

No concerns currently listed.

Once a majority of reviewers approve (and at most 2 approvals are outstanding), this will enter its final comment period. If you spot a major issue that hasn't been raised at any point in this process, please speak up!

cc @rust-lang/lang-advisors: FCP proposed for lang, please feel free to register concerns.
See this document for info about what commands tagged team members can give me.

@rfcbot rfcbot added proposed-final-comment-period Proposed to merge/close by relevant subteam, see T-<team> label. Will enter FCP once signed off. disposition-merge This issue / PR is in PFCP or FCP with a disposition to merge it. labels Aug 18, 2025
@ehuss
Copy link
Contributor

ehuss commented Aug 18, 2025

Can we get a PR to the reference to update everything there?
I'm not sure all that needs to be updated, but there is possibly:

  • The note
  • The grammar. I think that includes TUPLE_INDEX? I'm not sure what else.

@jieyouxu
Copy link
Member Author

Sure. I'll send one tmrw / Wednesday. Will need to double-check which bits of the grammar needs updating tho.

@traviscross traviscross added the S-waiting-on-documentation Status: Waiting on approved PRs to documentation before merging label Aug 18, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-grammar Area: The grammar of Rust A-parser Area: The lexing & parsing of Rust source code to an AST A-proc-macros Area: Procedural macros A-tidy Area: The tidy tool disposition-merge This issue / PR is in PFCP or FCP with a disposition to merge it. I-lang-nominated Nominated for discussion during a lang team meeting. needs-fcp This change is insta-stable, or significant enough to need a team FCP to proceed. P-lang-drag-1 Lang team prioritization drag level 1. https://rust-lang.zulipchat.com/#narrow/channel/410516-t-lang proposed-final-comment-period Proposed to merge/close by relevant subteam, see T-<team> label. Will enter FCP once signed off. S-waiting-on-documentation Status: Waiting on approved PRs to documentation before merging S-waiting-on-team Status: Awaiting decision from the relevant subteam (see the T-<team> label). T-lang Relevant to the language team
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Tracking issue for future-incompatbility warning 'invalid literal suffix on tuple index' (not a lint)
8 participants