Skip to content

Commit 8c403ca

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 8c403ca

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

as_tuple_derive/src/lib.rs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
extern crate proc_macro;
22

3-
use proc_macro2::TokenStream;
3+
use proc_macro2::{Literal, TokenStream};
44
use quote::quote;
55
use syn::{
66
Data, DeriveInput, Fields, Generics, GenericParam, Ident,
@@ -100,10 +100,13 @@ fn tuple_gen(data: &Data, options: TupleOptions) -> TokenStream {
100100
TupleOptions::Binding => {
101101
quote! { field_#i }
102102
},
103-
TupleOptions::Ref { mutable } => if !mutable {
104-
quote! { &self.#i }
105-
} else {
106-
quote! { &mut self.#i }
103+
TupleOptions::Ref { mutable } => {
104+
let i = Literal::usize_unsuffixed(i);
105+
if !mutable {
106+
quote! { &self.#i }
107+
} else {
108+
quote! { &mut self.#i }
109+
}
107110
},
108111
});
109112
quote! { (#(#recurse),*) }

0 commit comments

Comments
 (0)