PoignardAzur / venial

"A very small syn"
MIT License
192 stars 9 forks source link

Unballanced brackets in type expression, when not ending with comma. #19

Closed lenscas closed 2 years ago

lenscas commented 2 years ago

I decided to give venial a try for my proc macros as it seems easier than syn for my purposes. However, I ran into a bug where the proc macro crashes with the error Unballanced brackets in type expression. despite the rust code being correctly formatted.

The rust code in question:

#[derive(Clone, RluaUserData)]
struct Example<A: Clone> {
    _test: A,
}

Curiously, adding a , after the Clone will make this error go away, as in this code works:

#[derive(Clone, RluaUserData)]
struct Example<A: Clone,> {
    _test: A,
}

repo that this happened in: https://github.com/lenscas/tealr/tree/chore/improve_proc_macros relevant files are https://github.com/lenscas/tealr/blob/chore/improve_proc_macros/tealr_derive/src/lib.rs#L48 (function that declares the derive macro)

https://github.com/lenscas/tealr/blob/388e7133a1b66cc9ee915e36ddac428bf1979329/tealr_derive/src/user_data.rs#L21 (function that creates the trait impl. I commented everything out to make sure the crash was not in my own code)

https://github.com/lenscas/tealr/blob/388e7133a1b66cc9ee915e36ddac428bf1979329/tealr/examples/rlua/derive.rs#L20 (example I use for testing, which contains the changes to get venial to panic)

PoignardAzur commented 2 years ago

Thanks for the report. I'll look into it.

PoignardAzur commented 2 years ago

Okay, so, quick update to confirm I can indeed reproduce the bug. (Sorry for the month-long silence)

I'm trying to find why.

lenscas commented 2 years ago

(Sorry for the month-long silence)

Don't worry. Life happens :) (Also, I decided to have this macro not work with generics for the time being as it is complicated enough as it is and getting the traits it implements to work correctly once generics are involved is also not exactly easy when doing it by hand. Doing it as part of a macro is just pain)

PoignardAzur commented 2 years ago

Yeah, macros with generics are still a pretty janky part of Rust.