Skip to content

Commit 2c71e71

Browse files
committed
fix: use unsuffixed numeric literal for tuple index
See <rust-lang/rust#60210> for more context. This has been a future-incompatibility warning since Rust 1.27, where tuple index subexpressions with invalid suffixes (in this case, `.0usize`) was erroneously accidentally accepted. This will become a hard error in Rust 1.91.
1 parent 37d526c commit 2c71e71

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

as_tuple_derive/src/lib.rs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@ extern crate proc_macro;
33
use proc_macro2::TokenStream;
44
use quote::quote;
55
use syn::{
6-
Data, DeriveInput, Fields, Generics, GenericParam, Ident,
7-
parse_macro_input, parse_quote,
6+
Data, DeriveInput, Fields, GenericParam, Generics, Ident, Index, parse_macro_input, parse_quote
87
};
98

109
#[proc_macro_derive(AsTuple)]
@@ -100,10 +99,13 @@ fn tuple_gen(data: &Data, options: TupleOptions) -> TokenStream {
10099
TupleOptions::Binding => {
101100
quote! { field_#i }
102101
},
103-
TupleOptions::Ref { mutable } => if !mutable {
104-
quote! { &self.#i }
105-
} else {
106-
quote! { &mut self.#i }
102+
TupleOptions::Ref { mutable } => {
103+
let i = Index::from(i);
104+
if !mutable {
105+
quote! { &self.#i }
106+
} else {
107+
quote! { &mut self.#i }
108+
}
107109
},
108110
});
109111
quote! { (#(#recurse),*) }

0 commit comments

Comments
 (0)