hecatia-elegua / bilge

Use bitsized types as if they were a feature of rust.
Apache License 2.0
171 stars 17 forks source link

validate macro input at entry point #57

Open pickx opened 1 year ago

pickx commented 1 year ago

if macro input is invalid, we go straight to unreachable, so something like this

#[bitsize(5)]
union A {
    B,
}

would panic with "entered unreachable code: should have already been validated". syn::parse_macro_input! seems like a more sanitary way to do this.

hecatia-elegua commented 1 year ago

Ah so that's the usecase, but why not just use parse2's error then? This also breaks the proc macro structure I've argued for in the blog post, we still want parsing to be done inside. Sorry that this basically means redoing the whole changeset.

hecatia-elegua commented 1 year ago

Right I think I hated parse_macro_input! because it won't take procmacro2_TokenStream. So first I would want to know what parse2 -> log/compile error says vs parse_macro_input

pickx commented 1 year ago

Right I think I hated parse_macro_input! because it won't take procmacro2_TokenStream. So first I would want to know what parse2 -> log/compile error says vs parse_macro_input

yeah that's why I kept it in lib.rs, so we don't get a mix of proc_macro::TokenStream and proc_macro2::TokenStream in the same file.

since this is always an error (and not bilge-specific) than presumably you'd want to not print anything, so the actual compile errors are the only thing the user sees

Sorry that this basically means redoing the whole changeset.

np, I have no strong feelings about this one

hecatia-elegua commented 1 year ago

I dunno. Keeping parsing inside would be nice. I just tried around a bit and this would be the most sane version of it: https://github.com/hecatia-elegua/bilge/compare/main...invalid-syntax