-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
Add cstr!
macro.
#101607
Add cstr!
macro.
#101607
Conversation
Hey! It looks like you've submitted a new PR for the library teams! If this PR contains changes to any Examples of
|
r? @scottmcm (rust-highfive has picked a reviewer for you, use r? to override) |
2e6842e
to
d29166e
Compare
This comment has been minimized.
This comment has been minimized.
067749f
to
48a4823
Compare
This comment has been minimized.
This comment has been minimized.
b31e960
to
a4ddd84
Compare
This comment has been minimized.
This comment has been minimized.
cb7e64d
to
686b7e4
Compare
This comment has been minimized.
This comment has been minimized.
c997c8f
to
25f5b36
Compare
This comment has been minimized.
This comment has been minimized.
25f5b36
to
50c9a6b
Compare
dceba0b
to
b57f302
Compare
21ccb84
to
7addd28
Compare
Making some functions const and adding |
Generally yes, but the macro only works if the functions are |
1af3a94
to
0303ec3
Compare
This comment has been minimized.
This comment has been minimized.
0303ec3
to
44e14ed
Compare
This comment has been minimized.
This comment has been minimized.
44e14ed
to
c7ff977
Compare
This comment has been minimized.
This comment has been minimized.
c7ff977
to
7b9f9e5
Compare
Nominating for lang team discussion, to discuss if we should add something like This would allow the tokenizer to know something is a C string, such that escape sequences like \0 can be an error, and we can allow invalid unicode like \x80. |
Such checking can also happen in a proc macro, if the tokenizer is made tolerant of invalid characters, and the "valid unicode" check is turned into a post-parsing error. I'm one of the fans of rust-lang/rfcs#3267 :). Any capability built into the language is one that libraries can't customize. |
I'd still like to get inferred-type literals, since we want it for all kinds of things (like |
IMO, it feels pretty weird for us to have a macro here rather than just have There's probably missing const features (e.g., you can't insert the |
I've grepped the compiler for usages of the Looking over all of the ecosystem, it seems that the macro is used in "only" 224 files: https://grep.app/search?q=cstr%21&filter[lang][0]=Rust |
As another data point, I previously used the This crate has a similar function The bulk of my work involves oxidizing a C codebase. I would very much like easy and linenoise-free CStr construction in source code, especially in const and static contexts. |
This is also my use-case for this macro.
|
We discussed this in today's @rust-lang/lang meeting. We are potentially interested in doing this in the future, but we don't expect to do so on a soon enough timeframe to warrant discouraging the libs team from adding this macro. Go ahead and add it if in the libs team's judgement people want it and would use it. We might add a native lang construct later, but the macro can always map to that. |
With “this” referring to
So is anything still blocking this from being merged now? |
I've opened rust-lang/rfcs#3348 to try make that happen sooner. This PR adds a bunch of relatively hard to maintain (and hard to optimize) code to the standard library, so I'd very much prefer built in support for C string literals. |
Looks like RFC 3348 is going to get accepted; closing this in favor of |
Simplify `const` `memchr`. Extracted from rust-lang/rust#101607. Removes the need for `const_eval_select`.
Simplify `const` `memchr`. Extracted from rust-lang/rust#101607. Removes the need for `const_eval_select`.
This adds a
cstr!
macro for easily creating&'static Cstr
.ACP: rust-lang/libs-team#103