Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

validate macro input at entry point #57

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

Conversation

pickx
Copy link
Collaborator

@pickx pickx commented Jul 17, 2023

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
Copy link
Owner

hecatia-elegua commented Jul 17, 2023

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
Copy link
Owner

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
Copy link
Collaborator Author

pickx commented Jul 17, 2023

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
Copy link
Owner

I dunno.
Keeping parsing inside would be nice. I just tried around a bit and this would be the most sane version of it: main...invalid-syntax

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants