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

Can't set a default value for bool args in derive macro #16

Closed
parasyte opened this issue Aug 6, 2023 · 2 comments · Fixed by #27
Closed

Can't set a default value for bool args in derive macro #16

parasyte opened this issue Aug 6, 2023 · 2 comments · Fixed by #27
Labels
bug Something isn't working

Comments

@parasyte
Copy link
Owner

parasyte commented Aug 6, 2023

Boolean values true and false are not literals. They are idents: https://dev-doc.rust-lang.org/beta/proc_macro/struct.Literal.html

(emphasis added)

A literal string ("hello"), byte string (b"hello"), character ('a'), byte character (b'a'), an integer or floating point number with or without a suffix (1, 1u8, 2.3, 2.3f32). Boolean literals like true and false do not belong here, they are Idents.

The bug is here:

default = Some(stream.as_lit()?);

It needs a fallback to check for true and false idents if the token is not a literal.

@parasyte parasyte added the bug Something isn't working label Aug 6, 2023
@parasyte
Copy link
Owner Author

String has the same kind of problem. The derive macro passes a string literal, but it wants a heap-allocated String. It needs to call .to_string() on whatever is provided in the #[default(...)] attribute.

@parasyte
Copy link
Owner Author

And PathBuf, too! Something like try_into() or parse() might work for all of these?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant