Skip to content

fix(#37)#44

Merged
BenjaminBrienen merged 3 commits intobevyengine:mainfrom
kingwingfly:fix/#37
Nov 19, 2025
Merged

fix(#37)#44
BenjaminBrienen merged 3 commits intobevyengine:mainfrom
kingwingfly:fix/#37

Conversation

@kingwingfly
Copy link
Contributor

Objective

fixes #37

Solution

At first, I feel this part is strange:

    let len = 1 + input.end - input.start;
    let ident_tuples = (0..=len)
        .map(|i| {
            let idents = input
                .idents
                .iter()
                .map(|ident| format_ident!("{}{}", ident, i));
            to_ident_tuple_enumerated(idents, input.idents.len())
        })
        .collect::<Vec<_>>();

If end = 2, start = 0, then len = 3. But ident_tuples has 4 elements, while we only need 2.

I make changes to it first, and then #37 just fixed.

Testing

  • Did you test these changes? If so, how?
RUSTFLAGS="--cfg docsrs" cargo +nightly expand --example all_tuples

And got

#[allow(unused_variables)]
#[allow(non_snake_case)]
#[allow(clippy::unused_unit)]
impl Foo for () {
    const FOO_HARDER: bool = true;
    fn foo() -> bool {
        true
    }
}
#[allow(unused_variables)]
#[allow(non_snake_case)]
#[allow(clippy::unused_unit)]
#[doc(fake_variadic)]
///This trait is implemented for tuples down to 0 up to 15 items long.
impl<F: Foo> Foo for (F,) {
    const FOO_HARDER: bool = true && F::FOO_HARDER;
    fn foo() -> bool {
        true
    }
}
#[allow(unused_variables)]
#[allow(non_snake_case)]
#[allow(clippy::unused_unit)]
#[doc(hidden)]
impl<F0: Foo, F1: Foo> Foo for (F0, F1) {
    const FOO_HARDER: bool = true && F0::FOO_HARDER && F1::FOO_HARDER;
    fn foo() -> bool {
        true
    }
}
  • Are there any parts that need more testing?
    I open doc with this cmd
RUSTFLAGS="--cfg docsrs" cargo +nightly doc --open --example all_tuples

But the fake_variadics is not right. I believe it's due to I missed some flags and it'll be right when publishing onto cratesio.
However, I'm not very sure.

  • How can other people (reviewers) test your changes? Is there anything specific they need to know?
    Use correct command to check cargo doc result
    Mine is incorrect:
RUSTFLAGS="--cfg docsrs" cargo +nightly doc --open --example all_tuples

By the way,

  • I change doc_auto_cfg to doc_cfg, since they are merged since Rust nightly 1.92. And docs.rs uses nightly Rust. Anyway, this crate has no features gate, there's no effect I think.

@github-actions
Copy link

Welcome, new contributor!

Please make sure you've read our contributing guide and we look forward to reviewing your pull request shortly ✨

@alice-i-cecile alice-i-cecile added the C-Bug Something isn't working label Nov 17, 2025
@BenjaminBrienen
Copy link
Collaborator

Does this also fix #42?

let input = parse_macro_input!(input as AllTuples);
let len = 1 + input.end - input.start;
let ident_tuples = (0..=len)
let ident_tuples = (0..input.end)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add a test case to make sure that if the input is 16 to 20, then it is not implemented for 0..=15. I have a suspicion.

Copy link
Contributor Author

@kingwingfly kingwingfly Nov 19, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I first add a test 3..15, then it conflicts with the original 1..15, so I believe 16..20 doesn’t impl for 1..15. 1..15and 15..20 are in the same block in doc, if 15..20 implemented for 1..15 again, it would not compile. Maybe current test is enough...

EDIT: I only added test in all_tuples and forgot others...

@kingwingfly
Copy link
Contributor Author

kingwingfly commented Nov 19, 2025

I think it happens to fix #42 too. Because in this PR, only format idents needed (i.e. if all_tuples!(foo, 0, 2, T), only [T1, T2] and up to 2). There's no chance to generate redundant impl block. The original len = 2 + 1 - 0 = 3, it's then incorrect.

@BenjaminBrienen BenjaminBrienen merged commit 8545112 into bevyengine:main Nov 19, 2025
23 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

C-Bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

panics with “range end index out of range” when called as all_tuples_enumerated!(impl_baz, 3, 10, T)

3 participants