Tracking issue for future-incompatbility warning 'invalid literal suffix on tuple index' (not a lint) · Issue #60210 · rust-lang/rust (original) (raw)

This is the summary issue for a bug fix related to tuple indexing. The goal of this page is describe why this change was made and how you can fix code that is affected by it. It also provides a place to ask questions or register a complaint if you feel the change should not be made. For more information on the policy around future-compatibility warnings, see our breaking change policy guidelines.

What is the warning for?

As reported in #59418, the compiler incorrectly accepts foo.0_u32 (and other suffixes) when indexing into tuples. The expected syntax is simply foo.0. We are presently issuing warnings when this incorrect syntax is used but we expect to transition those warnings to errors in the future.

How can you fix your code?

Most often this error manifests in procedural macros that employ the syn or quote crates. It can be avoided by using syn::Index::from or proc_macro::Literal::*_unsuffixed. For example, if before you were generating foo.0 doing something like this:

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

you might now do instead:

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

When will this warning become a hard error?

At the beginning of each 6-week release cycle, the Rust compiler team
will review the set of outstanding future compatibility warnings and
nominate some of them for Final Comment Period. Toward the end of
the cycle, we will review any comments and make a final determination
whether to convert the warning into a hard error or remove it
entirely.

Here are some of the regressions found in the wild: