Skip to content

validate macro input at entry point#57

Open
pickx wants to merge 1 commit into
mainfrom
parse_macro_input
Open

validate macro input at entry point#57
pickx wants to merge 1 commit into
mainfrom
parse_macro_input

Conversation

@pickx
Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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

@pickx pickx force-pushed the parse_macro_input branch from c562d5e to 4e5c550 Compare July 17, 2023 20:29
@hecatia-elegua
Copy link
Copy Markdown
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