Skip to content

Commit b4ccc53

Browse files
committed
Clarify all nuls are disallowed.
1 parent 534349c commit b4ccc53

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

text/3348-c-str-literal.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ In Rust 2021, we reserved prefixes for (string) literals, so let's make use of t
2222

2323
`c"abc"` is a [`&CStr`](https://doc.rust-lang.org/stable/core/ffi/struct.CStr.html). A nul byte (`b'\0'`) is appended to it in memory and the result is a `&CStr`.
2424

25-
All escape codes and characters accepted by `""` and `b""` literals are accepted, except the nul byte (`\0`).
25+
All escape codes and characters accepted by `""` and `b""` literals are accepted, except nul bytes.
2626
So, both UTF-8 and non-UTF-8 data can co-exist in a C string. E.g. `c"hello\x80我叫\u{1F980}"`.
2727

2828
The raw string literal variant is prefixed with `cr`. For example, `cr"\"` and `cr##"Hello "world"!"##`. (Just like `r""` and `br""`.)
@@ -34,6 +34,8 @@ Two new [string literal types](https://doc.rust-lang.org/reference/tokens.html#c
3434

3535
Accepted escape codes: [Quote](https://doc.rust-lang.org/reference/tokens.html#quote-escapes) & [Unicode](https://doc.rust-lang.org/reference/tokens.html#unicode-escapes) & [Byte](https://doc.rust-lang.org/reference/tokens.html#byte-escapes).
3636

37+
Nul bytes are disallowed, whether as escape code or source character (e.g. `"\0"`, `"\x00"`, `"\u{0}"` or `"␀"`).
38+
3739
Unicode characters are accepted and encoded as UTF-8. That is, `c"🦀"`, `c"\u{1F980}"` and `c"\xf0\x9f\xa6\x80"` are all accepted and equivalent.
3840

3941
The type of the expression is [`&core::ffi::CStr`](https://doc.rust-lang.org/stable/core/ffi/struct.CStr.html). So, the `CStr` type will have to become a lang item.

0 commit comments

Comments
 (0)