Skip to content

Wrong tuple lengths being documented. #42

@cbrownsey

Description

@cbrownsey

variadics_please version

Version 1.1.0.

What you did

In a crate I'm working on I saw that the implementation was for up to 17 items. This drew my eye because the 16 length limit is a limitation of the C library I'm using. A reproduction of the issue is below and can be run with cargo +nightly -Zscript ./repro.rs.

---
[dependencies]
variadics_please = "1.1.0"
---

macro_rules! fake_impl {
    ($(#[$meta:meta])* $($ty:ident),*) => {
        let s = stringify!($($meta)*);
        if !s.is_empty() {
            println!("{s}");
        }
    }
}

fn main() {
    variadics_please::all_tuples!(
        #[doc(fake_variadic)]
        fake_impl,
        0,
        1,
        T
    );
}

What went wrong

Despite only running on the tuples () and (T,), this snipped outputs the following:

cfg_attr(any(docsrs, docsrs_dep), doc(fake_variadic))
cfg_attr(any(docsrs, docsrs_dep), doc =
"This trait is implemented for tuples up to 2 items long.")

This is incorrect, as it will only implement the trait for items up to 1 item long.

Additional information

With a brief grep in the bevy repository, this issue looks like it affects at least twenty different trait implementations.

The source of this issue looks to be a double counting in each of the macro functions in the line let len = 1 + input.end - input.start;. Although this is used as an endpoint in a loop, the result of that iteration is ignored as the next iteration is over input.start..=input.end, which is why calling all_tuples with a range of 0 to 1 hasn't been outputting three implementations.

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-BugSomething isn't workingS-Ready-For-ImplementationThis issue is ready for an implementation PR. Go for it!

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions