-
Notifications
You must be signed in to change notification settings - Fork 766
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
emit c-string literals on Rust 1.77 or later #4269
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, much appreciated!
A few small thoughts, otherwise looks great to me 👍
LitCStr(LitCStr), | ||
// There is currently no way to `concat!` c-string literals, we fallback to the `c_str!` macro in | ||
// this case. | ||
Tokens(TokenStream), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed I think this case will have to stick around for the foreseeable future, but I think we would at least eventually be able to just use something like CStr::from_bytes_with_nul
(which is const since 1.72).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
... or maybe #4270 is good enough for now :)
Co-authored-by: mejrs <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks :)
This emits c-string literals where possible when on Rust 1.77 or later.
Since we are not allowed to emit these literals on earlier Rust versions, we need to have the conditional compilation on the macro code itself, so I added a
build.rs
to emit the requiredcfg
s.We also have the case for
doc
attributes including macro invocations, since there is currently no way toconcat!
c-string literals, this case falls back to thec_str!
macroCloses #4261