-
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
Tracking Issue for c"…"
string literals
#105723
Comments
w.r.t.
IIRC, C23 accepted N2653, which defines Assuming I'm correct that N2653 was accepted, it probably makes sense to define Rust's To be explicit, this is not intended to argue that Note that The presence of UTF-8 literals being Footnotes
|
Yeah,
I think it was possible before, and will still be in C23: "Any hexadecimal escape sequence or octal escape sequence specified in a |
I do want to note a couple things in the alternatives:
|
@CAD97 @dead-claudia Would you be willing to open issues for these points and add the |
Created #106479 for my first point. The second point's not likely to be relevant before a PR, and there's really not much to discuss there. |
I don't think there would be anything about that change that should block this, it would just have to be updated whenever CStr becomes thin. The change itself is blocked, I think #81513 would solve it, but it is still quite young. Seems like there hasn't been much discussion on the topic recently anyway - #59905 is the only issue I could find, but it's pretty unofficial and stale |
…r-errors Implement RFC 3348, `c"foo"` literals RFC: rust-lang/rfcs#3348 Tracking issue: rust-lang#105723
…r-errors Implement RFC 3348, `c"foo"` literals RFC: rust-lang/rfcs#3348 Tracking issue: rust-lang#105723
…r-errors Implement RFC 3348, `c"foo"` literals RFC: rust-lang/rfcs#3348 Tracking issue: rust-lang#105723
…r-errors Implement RFC 3348, `c"foo"` literals RFC: rust-lang/rfcs#3348 Tracking issue: rust-lang#105723
|
I updated the summary comment with recent history.
|
…ilstrieb Stabilize C string literals RFC: https://rust-lang.github.io/rfcs/3348-c-str-literal.html Tracking issue: rust-lang#105723 Documentation PR (reference manual): rust-lang/reference#1423 # Stabilization report Stabilizes C string and raw C string literals (`c"..."` and `cr#"..."#`), which are expressions of type [`&CStr`](https://doc.rust-lang.org/stable/core/ffi/struct.CStr.html). Both new literals require Rust edition 2021 or later. ```rust const HELLO: &core::ffi::CStr = c"Hello, world!"; ``` C strings may contain any byte other than `NUL` (`b'\x00'`), and their in-memory representation is guaranteed to end with `NUL`. ## Implementation Originally implemented by PR rust-lang#108801, which was reverted due to unintentional changes to lexer behavior in Rust editions < 2021. The current implementation landed in PR rust-lang#113476, which restricts C string literals to Rust edition >= 2021. ## Resolutions to open questions from the RFC * Adding C character literals (`c'.'`) of type `c_char` is not part of this feature. * Support for `c"..."` literals does not prevent `c'.'` literals from being added in the future. * C string literals should not be blocked on making `&CStr` a thin pointer. * It's possible to declare constant expressions of type `&'static CStr` in stable Rust (as of v1.59), so C string literals are not adding additional coupling on the internal representation of `CStr`. * The unstable `concat_bytes!` macro should not accept `c"..."` literals. * C strings have two equally valid `&[u8]` representations (with or without terminal `NUL`), so allowing them to be used in `concat_bytes!` would be ambiguous. * Adding a type to represent C strings containing valid UTF-8 is not part of this feature. * Support for a hypothetical `&Utf8CStr` may be explored in the future, should such a type be added to Rust.
Stabilize C string literals RFC: https://rust-lang.github.io/rfcs/3348-c-str-literal.html Tracking issue: rust-lang/rust#105723 Documentation PR (reference manual): rust-lang/reference#1423 # Stabilization report Stabilizes C string and raw C string literals (`c"..."` and `cr#"..."#`), which are expressions of type [`&CStr`](https://doc.rust-lang.org/stable/core/ffi/struct.CStr.html). Both new literals require Rust edition 2021 or later. ```rust const HELLO: &core::ffi::CStr = c"Hello, world!"; ``` C strings may contain any byte other than `NUL` (`b'\x00'`), and their in-memory representation is guaranteed to end with `NUL`. ## Implementation Originally implemented by PR rust-lang/rust#108801, which was reverted due to unintentional changes to lexer behavior in Rust editions < 2021. The current implementation landed in PR rust-lang/rust#113476, which restricts C string literals to Rust edition >= 2021. ## Resolutions to open questions from the RFC * Adding C character literals (`c'.'`) of type `c_char` is not part of this feature. * Support for `c"..."` literals does not prevent `c'.'` literals from being added in the future. * C string literals should not be blocked on making `&CStr` a thin pointer. * It's possible to declare constant expressions of type `&'static CStr` in stable Rust (as of v1.59), so C string literals are not adding additional coupling on the internal representation of `CStr`. * The unstable `concat_bytes!` macro should not accept `c"..."` literals. * C strings have two equally valid `&[u8]` representations (with or without terminal `NUL`), so allowing them to be used in `concat_bytes!` would be ambiguous. * Adding a type to represent C strings containing valid UTF-8 is not part of this feature. * Support for a hypothetical `&Utf8CStr` may be explored in the future, should such a type be added to Rust.
Closing this as per the merged stabilization PR: #117472 |
Stabilize C string literals RFC: https://rust-lang.github.io/rfcs/3348-c-str-literal.html Tracking issue: rust-lang/rust#105723 Documentation PR (reference manual): rust-lang/reference#1423 # Stabilization report Stabilizes C string and raw C string literals (`c"..."` and `cr#"..."#`), which are expressions of type [`&CStr`](https://doc.rust-lang.org/stable/core/ffi/struct.CStr.html). Both new literals require Rust edition 2021 or later. ```rust const HELLO: &core::ffi::CStr = c"Hello, world!"; ``` C strings may contain any byte other than `NUL` (`b'\x00'`), and their in-memory representation is guaranteed to end with `NUL`. ## Implementation Originally implemented by PR rust-lang/rust#108801, which was reverted due to unintentional changes to lexer behavior in Rust editions < 2021. The current implementation landed in PR rust-lang/rust#113476, which restricts C string literals to Rust edition >= 2021. ## Resolutions to open questions from the RFC * Adding C character literals (`c'.'`) of type `c_char` is not part of this feature. * Support for `c"..."` literals does not prevent `c'.'` literals from being added in the future. * C string literals should not be blocked on making `&CStr` a thin pointer. * It's possible to declare constant expressions of type `&'static CStr` in stable Rust (as of v1.59), so C string literals are not adding additional coupling on the internal representation of `CStr`. * The unstable `concat_bytes!` macro should not accept `c"..."` literals. * C strings have two equally valid `&[u8]` representations (with or without terminal `NUL`), so allowing them to be used in `concat_bytes!` would be ambiguous. * Adding a type to represent C strings containing valid UTF-8 is not part of this feature. * Support for a hypothetical `&Utf8CStr` may be explored in the future, should such a type be added to Rust.
Stabilization is reverted in #119528, so probably this should be open again? |
@rustbot labels +I-lang-nominated Nominating to discuss and ensure we're OK with the restabilization that will occur automatically if we take no action. |
Was this fully stabilized for rust-1.77.0_beta? I am failing to bootstrap the beta from the beta tarball with: |
@stefson Yes, it was fully stabilized in 1.77. If you are unable to determine your issue, I would suggest opening a new issue with the exact reproduction steps and commands to run. I'm going to close this issue as the revert only happened on the old beta branch (1.76), and is on track as stabilized in the new beta branch (1.77). |
error[E0658]: `c".."` literals are experimental --> src/bar.rs:61:13 | 61 | c"i3bar-river".into(), | ^^^^^^^^^^^^^^ | = note: see issue #105723 <rust-lang/rust#105723> for more information error[E0658]: `c".."` literals are experimental --> src/wm_info_provider/river.rs:118:33 | 118 | PointerBtn::Left => c"set-focused-tags", | ^^^^^^^^^^^^^^^^^^^ | = note: see issue #105723 <rust-lang/rust#105723> for more information error[E0658]: `c".."` literals are experimental --> src/wm_info_provider/river.rs:119:34 | 119 | PointerBtn::Right => c"toggle-focused-tags", | ^^^^^^^^^^^^^^^^^^^^^^ | = note: see issue #105723 <rust-lang/rust#105723> for more information Reported by: pkg-fallout (direct commit to 2024Q1 as 73941e6 is missing on the branch)
Stabilize C string literals RFC: https://rust-lang.github.io/rfcs/3348-c-str-literal.html Tracking issue: rust-lang/rust#105723 Documentation PR (reference manual): rust-lang/reference#1423 # Stabilization report Stabilizes C string and raw C string literals (`c"..."` and `cr#"..."#`), which are expressions of type [`&CStr`](https://doc.rust-lang.org/stable/core/ffi/struct.CStr.html). Both new literals require Rust edition 2021 or later. ```rust const HELLO: &core::ffi::CStr = c"Hello, world!"; ``` C strings may contain any byte other than `NUL` (`b'\x00'`), and their in-memory representation is guaranteed to end with `NUL`. ## Implementation Originally implemented by PR rust-lang/rust#108801, which was reverted due to unintentional changes to lexer behavior in Rust editions < 2021. The current implementation landed in PR rust-lang/rust#113476, which restricts C string literals to Rust edition >= 2021. ## Resolutions to open questions from the RFC * Adding C character literals (`c'.'`) of type `c_char` is not part of this feature. * Support for `c"..."` literals does not prevent `c'.'` literals from being added in the future. * C string literals should not be blocked on making `&CStr` a thin pointer. * It's possible to declare constant expressions of type `&'static CStr` in stable Rust (as of v1.59), so C string literals are not adding additional coupling on the internal representation of `CStr`. * The unstable `concat_bytes!` macro should not accept `c"..."` literals. * C strings have two equally valid `&[u8]` representations (with or without terminal `NUL`), so allowing them to be used in `concat_bytes!` would be ambiguous. * Adding a type to represent C strings containing valid UTF-8 is not part of this feature. * Support for a hypothetical `&Utf8CStr` may be explored in the future, should such a type be added to Rust.
Stabilize C string literals RFC: https://rust-lang.github.io/rfcs/3348-c-str-literal.html Tracking issue: rust-lang/rust#105723 Documentation PR (reference manual): rust-lang/reference#1423 # Stabilization report Stabilizes C string and raw C string literals (`c"..."` and `cr#"..."#`), which are expressions of type [`&CStr`](https://doc.rust-lang.org/stable/core/ffi/struct.CStr.html). Both new literals require Rust edition 2021 or later. ```rust const HELLO: &core::ffi::CStr = c"Hello, world!"; ``` C strings may contain any byte other than `NUL` (`b'\x00'`), and their in-memory representation is guaranteed to end with `NUL`. ## Implementation Originally implemented by PR rust-lang/rust#108801, which was reverted due to unintentional changes to lexer behavior in Rust editions < 2021. The current implementation landed in PR rust-lang/rust#113476, which restricts C string literals to Rust edition >= 2021. ## Resolutions to open questions from the RFC * Adding C character literals (`c'.'`) of type `c_char` is not part of this feature. * Support for `c"..."` literals does not prevent `c'.'` literals from being added in the future. * C string literals should not be blocked on making `&CStr` a thin pointer. * It's possible to declare constant expressions of type `&'static CStr` in stable Rust (as of v1.59), so C string literals are not adding additional coupling on the internal representation of `CStr`. * The unstable `concat_bytes!` macro should not accept `c"..."` literals. * C strings have two equally valid `&[u8]` representations (with or without terminal `NUL`), so allowing them to be used in `concat_bytes!` would be ambiguous. * Adding a type to represent C strings containing valid UTF-8 is not part of this feature. * Support for a hypothetical `&Utf8CStr` may be explored in the future, should such a type be added to Rust.
sevctl 0.4.3 was refusing to compile on Ubuntu 22.04 and 24.02 because of some deps. This happened in the Github CI This prevented the build of package and the testing inside the CI Solution: Update sevctl to 0.6.0 Error logs Compiling structopt-derive v0.4.18 error[E0658]: `c".."` literals are experimental --> /root/.cargo/registry/src/index.crates.io-6f17d22bba15001f/kvm-ioctls-0.19.0/src/ioctls/system.rs:99:24 | 99 | let kvm_path = c"/dev/kvm"; | ^^^^^^^^^^^ | = note: see issue #105723 <rust-lang/rust#105723> for more information error[E0658]: `c".."` literals are experimental --> /root/.cargo/registry/src/index.crates.io-6f17d22bba15001f/kvm-ioctls-0.19.0/src/ioctls/system.rs:744:24 | 744 | let kvm_path = c"/dev/kvm"; | ^^^^^^^^^^^ | = note: see issue #105723 <rust-lang/rust#105723> for more information For more information about this error, try `rustc --explain E0658`. The following warnings were emitted during compilation: warning: kvm-ioctls@0.19.0: cargo:rustc-check-cfg requires -Zcheck-cfg flag error: could not compile `kvm-ioctls` (lib) due to 2 previous errors warning: build failed, waiting for other jobs to finish... error: failed to compile `sevctl v0.4.3 (https://github.com/virtee/sevctl.git?rev=c41c9172be013d6f10b9e1d7286fcb021805d5a5#c41c9172)`, intermediate artifacts can be found at `/tmp/cargo-installXhERbT`. To reuse those artifacts with a future compilation, set the environment variable `CARGO_TARGET_DIR` to that path. make: *** [Makefile:51: target/bin/sevctl] Error 101 make: *** [Makefile:89: all-podman-ubuntu-2204] Error 2
sevctl 0.4.3 was refusing to compile on Ubuntu 22.04 and 24.02 because of some deps. This happened in the Github CI This prevented the build of package and the testing inside the CI Solution: Update sevctl to 0.6.0 Error logs Compiling structopt-derive v0.4.18 error[E0658]: `c".."` literals are experimental --> /root/.cargo/registry/src/index.crates.io-6f17d22bba15001f/kvm-ioctls-0.19.0/src/ioctls/system.rs:99:24 | 99 | let kvm_path = c"/dev/kvm"; | ^^^^^^^^^^^ | = note: see issue #105723 <rust-lang/rust#105723> for more information error[E0658]: `c".."` literals are experimental --> /root/.cargo/registry/src/index.crates.io-6f17d22bba15001f/kvm-ioctls-0.19.0/src/ioctls/system.rs:744:24 | 744 | let kvm_path = c"/dev/kvm"; | ^^^^^^^^^^^ | = note: see issue #105723 <rust-lang/rust#105723> for more information For more information about this error, try `rustc --explain E0658`. The following warnings were emitted during compilation: warning: kvm-ioctls@0.19.0: cargo:rustc-check-cfg requires -Zcheck-cfg flag error: could not compile `kvm-ioctls` (lib) due to 2 previous errors warning: build failed, waiting for other jobs to finish... error: failed to compile `sevctl v0.4.3 (https://github.com/virtee/sevctl.git?rev=c41c9172be013d6f10b9e1d7286fcb021805d5a5#c41c9172)`, intermediate artifacts can be found at `/tmp/cargo-installXhERbT`. To reuse those artifacts with a future compilation, set the environment variable `CARGO_TARGET_DIR` to that path. make: *** [Makefile:51: target/bin/sevctl] Error 101 make: *** [Makefile:89: all-podman-ubuntu-2204] Error 2
sevctl 0.4.3 was refusing to compile on Ubuntu 22.04 and 24.02 because of some deps. This happened in the Github CI This prevented the build of package and the testing inside the CI Solution: Update sevctl to 0.6.0 Error logs Compiling structopt-derive v0.4.18 error[E0658]: `c".."` literals are experimental --> /root/.cargo/registry/src/index.crates.io-6f17d22bba15001f/kvm-ioctls-0.19.0/src/ioctls/system.rs:99:24 | 99 | let kvm_path = c"/dev/kvm"; | ^^^^^^^^^^^ | = note: see issue #105723 <rust-lang/rust#105723> for more information error[E0658]: `c".."` literals are experimental --> /root/.cargo/registry/src/index.crates.io-6f17d22bba15001f/kvm-ioctls-0.19.0/src/ioctls/system.rs:744:24 | 744 | let kvm_path = c"/dev/kvm"; | ^^^^^^^^^^^ | = note: see issue #105723 <rust-lang/rust#105723> for more information For more information about this error, try `rustc --explain E0658`. The following warnings were emitted during compilation: warning: kvm-ioctls@0.19.0: cargo:rustc-check-cfg requires -Zcheck-cfg flag error: could not compile `kvm-ioctls` (lib) due to 2 previous errors warning: build failed, waiting for other jobs to finish... error: failed to compile `sevctl v0.4.3 (https://github.com/virtee/sevctl.git?rev=c41c9172be013d6f10b9e1d7286fcb021805d5a5#c41c9172)`, intermediate artifacts can be found at `/tmp/cargo-installXhERbT`. To reuse those artifacts with a future compilation, set the environment variable `CARGO_TARGET_DIR` to that path. make: *** [Makefile:51: target/bin/sevctl] Error 101 make: *** [Makefile:89: all-podman-ubuntu-2204] Error 2
This is a tracking issue for the RFC "
c"…"
string literals" (rust-lang/rfcs#3348).The feature gate for the issue is
#![feature(c_str_literals)]
.Steps / History
c"foo"
literals #108801c"…"
literals are handled incorrectly by proc_macro::Literal #112820c"…"
string literals #113334c"…"
string literals with backward compatibility in mind #113333Unresolved Questions
c'…'
C character literals? (u8
,i8
,c_char
, or something more flexible?)&CStr
a thin pointer before stabilizing this? (If so, how?)concat_bytes
macro accept C string literals? (If so, should it evaluate to a C string or byte string?)c"..."
string literals support? (comment 1, comment 2)The text was updated successfully, but these errors were encountered: