Skip to content

Tuple indexing regression #59553

Closed
Closed
@taiki-e

Description

@taiki-e

#59421 breaks some code generated by proc macros because quote converts integer to a tokenstream with a suffix.

Proc macro:

extern crate proc_macro;
use proc_macro::TokenStream;
use quote::quote;

#[proc_macro]
pub fn foo(_: TokenStream) -> TokenStream {
    let index = 0;
    TokenStream::from(quote! {
        struct Foo(());
        fn bar() {
            let x = Foo(());
            x.#index
        }
    })
}

Calling code:

foo!();

Error:

error: suffixes on a tuple index are invalid
 --> src\lib.rs:3:1
  |
3 | foo!();
  | ^^^^^^^ invalid suffix `i32`

It can be avoided by using syn::Index::from or proc_macro::Literal::*_unsuffixed.

I have already fixed my library (taiki-e/pin-project@5f5cc35), but it can happen elsewhere.

Metadata

Metadata

Assignees

Labels

A-parserArea: The lexing & parsing of Rust source code to an ASTI-needs-decisionIssue: In need of a decision.P-highHigh priorityT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.T-langRelevant to the language team, which will review and decide on the PR/issue.regression-from-stable-to-betaPerformance or correctness regression from stable to beta.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions