-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
RFC: Introduce concat_bytes!()
to join [u8]
and byte str
analogous to concat!
for str
#2509
Conversation
I’d like to see the Motivation section expanded. Why is this useful? Consider describing use cases and adding examples. Currently this section only paraphrases the summary. The RFC’s title and motivation section mention “byte If this is added, I’d prefer it to be a separate macro. For that separate macro, the name |
@SimonSapin sounds reasonable!
Will expand. I can definitely see the case where someone would want to do
The confusion seems to be around "byte char" (
Very reasonable. It would be easy enough to point people in the right direction when extending the current error.
Works for me. The discoverability issue could be handled when someone attempts to use |
This comment has been minimized.
This comment has been minimized.
I agree with @SimonSapin's objection; I think this should use a separate macro Apart from that, though, I'd love to see this. |
In general I agree with the suggestion of making the type with Edit: I guess you could require a dummy |
I think this should have identical behaviour to string concat - ie emit |
Well, |
Maybe, to avoid this confusion, |
My point is that |
@jsgf sounds reasonable for |
That would be one way to define it and it’s not too terrible but:
I would prefer |
For some reason I though arbitrary slices couldn't be
Given that the |
This is exactly the kind of confusion I’d prefer to avoid. We could have the proc macro inspect Unicode strings and reject those that contain non-ASCII characters, but at that point why not reject Unicode strings entirely and suggest using byte strings instead? |
@SimonSapin I'm ok with rejecting unicode strings, as long as we suggest the appropriate hex representation of values outside of the ascii range, as this seems like something easy to include and very useful for end users. |
Sure, making a custom error message (that mentions UTF-8) for this case sounds good. |
This comment has been minimized.
This comment has been minimized.
I'd love to see this capability in the stdlib. My motivation (which I don't think was mentioned yet) is building null-terminated strings at compile-time, for C interop. macro_rules! zstr {
($str:literal) => {
concat_bytes!($str, b"\0");
};
}
zstr!(b"abc") == b"abc\0" |
You can do that already with normal strings. I use a null_str! macro myself |
Very true! That only works with UTF-8 strings though. I'm unfortunately working with Windows-1252. I guess that was an important detail. |
@nikomatsakis, @Mark-Simulacrum, and I talked about this one today. We generally think this is a good idea. We feel that, while as a builtin macro this is in the lang team's scope, we'd be comfortable with the @rust-lang/libs team evaluating this as if it were not a builtin macro (in which case it would be entirely within the scope of libs). I do think this should be a separate macro like |
I'm happy to start an FCP on behalf of the libs team once the RFC text is updated to use |
I'm interested in moving this forward. Should I open a PR on @estebank's branch to update the RFC text? |
This LGTM. Although, I don't think I'd mind seeing string/char literals supported in |
@rfcbot concern argument types With Considering this, I have two small related concerns about the types of arguments to accept:
|
|
@SimonSapin Ah thanks for that. I'm totally fine with that. |
Oh sorry, I got confused with other macros whose expansion includes expression arguments. The point of this one is to expand to a single literal, so it needs to parse the token of its arguments which therefore can’t be arbitrary expressions. |
@SimonSapin Ah, maybe that was why I thought the |
I’d prefer for the conversion and choice of encoding to be explicit when converting Unicode to bytes (even if the conversion is only type-level because the memory representation happens to match), but my pre-Rust-1.0 proposal to rename |
Actually no, I don't see how that could possibly work. |
Yeah I share the sentiment. I think my retort would just be that it would otherwise be not possible to mix non-UTF-8 with UTF-8 via the nice syntax of Unicode strings. For me personally, I think that might outweigh the desire for encoding explicitness. But I do not feel that strongly about this at all. |
Is now a good time to also rename the file from |
We discussed this in today's @rust-lang/libs meeting, and came to a resolution on the question of integer literals: We'd like to reject bare integer literals, and only allow arrays of integer literals. So, It would also be nice to have a diagnostic with a suggestion, that suggests wrapping a series of integer literals with square brackets. So, |
Minor issue that doesn't need to block acceptance of the RFC, but recently there have been some discussions about whether or not new macros ought to be properly namespaced rather than just being effectively added to the prelude outright (I'm not even sure if macro namespacing existed or was mature when this RFC was originally written). Is this new item useful enough that it should live in the prelude, or should it rather be, say, |
@m-ou-se Is your concern resolved with the latest revision? |
Usually that's done by whoever merges the RFC after the FCP is finished. But feel free to rename it yourself, to save that person one step in the rfc-merging process. ^^
Yes @rfcbot resolve argument types
I'd personally prefer for this macro to accept regular string literals for UTF-8, but we can always add that later if that turns out to be useful, as it'd be backwards compatible. |
🔔 This is now entering its final comment period, as per the review above. 🔔 |
The final comment period, with a disposition to merge, as per the review above, is now complete. As the automated representative of the governance process, I would like to thank the author for their work and everyone else who contributed. The RFC will be merged soon. |
Ping @joshtriplett |
🎉 This is now tracked in rust-lang/rust#87555 |
This RFC appears to contain a contradiction:
And then later
|
Rendered