TritonVM / tasm-lib

A collection of functions written in Triton VM assembly (tasm)
Apache License 2.0
11 stars 2 forks source link

TasmObject derive can't handle trailing comma in where clause. #91

Open dan-da opened 5 months ago

dan-da commented 5 months ago

TasmObject derive macro output fails to build when the target struct has a trailing comma in a where clause.

Does not build:

case: where clause, trailing comma, TasmObject derive

#[derive(BFieldCodec, TasmObject)]
pub struct Foo<T>
where T: BFieldCodec, {
    t_list: Vec<T>,
}

Error:

error: expected one of `{`, lifetime, or type, found `,`
  --> src/util_types/mmr/mmr_accumulator.rs:30:23
   |
30 | #[derive(BFieldCodec, TasmObject)]
   |                       ^^^^^^^^^^ expected one of `{`, lifetime, or type
   |
   = note: this error originates in the derive macro `TasmObject` (in Nightly builds, run with -Z macro-backtrace for more info)

error: proc-macro derive produced unparsable tokens
  --> src/util_types/mmr/mmr_accumulator.rs:30:23
   |
30 | #[derive(BFieldCodec, TasmObject)]
   |                       ^^^^^^^^^^

Variations that build

case: where clause, trailing comma, no TasmObject derive

#[derive(BFieldCodec)]
pub struct Foo<T>
where T: BFieldCodec, {
    t_list: Vec<T>,
}

case: no where clause, no trailing comma, TasmObject derive

#[derive(BFieldCodec, TasmObject)]
pub struct Foo<T: BFieldCodec> {
    t_list: Vec<T>,
}

case: no where clause, trailing comma, TasmObject derive

#[derive(BFieldCodec, TasmObject)]
pub struct Foo<T: BFieldCodec,> {
    t_list: Vec<T>,
}

case: where clause, no trailing comma, TasmObject derive

#[derive(BFieldCodec, TasmObject)]
pub struct Foo<T>
where T: BFieldCodec {
    t_list: Vec<T>,
}