Fix all_tuples macro for non-0/1 starts (#4002)

# Objective
`all_tuples` panics when the start count is set to anything other than 0 or 1. Fix this bug.

## Solution
Originally part of #2381, this PR fixes the slice indexing used by the proc macro.
This commit is contained in:
James Liu 2022-02-21 23:49:08 +00:00
parent fb8af3aec3
commit 5afda8df6f

View file

@ -46,7 +46,7 @@ impl Parse for AllTuples {
#[proc_macro]
pub fn all_tuples(input: TokenStream) -> TokenStream {
let input = parse_macro_input!(input as AllTuples);
let len = (input.start..=input.end).count();
let len = input.end - input.start;
let mut ident_tuples = Vec::with_capacity(len);
for i in input.start..=input.end {
let idents = input
@ -66,7 +66,7 @@ pub fn all_tuples(input: TokenStream) -> TokenStream {
let macro_ident = &input.macro_ident;
let invocations = (input.start..=input.end).map(|i| {
let ident_tuples = &ident_tuples[0..i];
let ident_tuples = &ident_tuples[0..i - input.start];
quote! {
#macro_ident!(#(#ident_tuples),*);
}