rust-itertools / itertools

Extra iterator adaptors, iterator methods, free functions, and macros.
https://docs.rs/itertools/
Apache License 2.0
2.72k stars 309 forks source link

iproduct rejects trailing comma #868

Closed ijackson closed 8 months ago

ijackson commented 8 months ago

To reproduce:

use itertools::iproduct;

fn main() {
    for e in iproduct!(
        [1,2],
        [3,4],
    ) {
        println!("{e:?}");
    }
}

Expected output: it works (printing 4 lines of output).

Actual output:

error: unexpected end of macro invocation
   --> src/main.rs:6:15
    |
6   |         [3,4],
    |               ^ missing tokens in macro arguments
    |
note: while trying to match meta-variable `$K:expr`
   --> /playground/.cargo/registry/src/index.crates.io-6f17d22bba15001f/itertools-0.12.0/src/lib.rs:259:26
    |
259 |     ($I:expr, $J:expr, $($K:expr),+) => (
    |                          ^^^^^^^

chain! and izip! are fine.

Removing the trailing comma works:

use itertools::iproduct;

fn main() {
    for e in iproduct!(
        [1,2],
        [3,4]
    ) {
        println!("{e:?}");
    }
}
Philippe-Cholet commented 8 months ago

I agree.

Philippe-Cholet commented 8 months ago

Add $(,)? at the end of each pattern of the macro would solve this.