rust/src
bors 63d16b5a98 Auto merge of #117472 - jmillikin:stable-c-str-literals, r=Nilstrieb
Stabilize C string literals

RFC: https://rust-lang.github.io/rfcs/3348-c-str-literal.html

Tracking issue: https://github.com/rust-lang/rust/issues/105723

Documentation PR (reference manual): https://github.com/rust-lang/reference/pull/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 https://github.com/rust-lang/rust/pull/108801, which was reverted due to unintentional changes to lexer behavior in Rust editions < 2021.

The current implementation landed in PR https://github.com/rust-lang/rust/pull/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.
2023-12-01 13:33:55 +00:00
..
bootstrap Auto merge of #118132 - onur-ozkan:stdlib-assertion-status-to-compiletest, r=wesleywiser 2023-11-29 17:41:27 +00:00
ci Auto merge of #117947 - Dirbaio:drop-llvm-15, r=cuviper 2023-11-27 21:54:03 +00:00
doc Auto merge of #116892 - ojeda:rethunk, r=wesleywiser 2023-11-30 22:10:30 +00:00
etc Auto merge of #115274 - bjorn3:tidy_improvements, r=davidtwco 2023-11-04 02:28:17 +00:00
librustdoc Rollup merge of #118483 - notriddle:notriddle/fmt-newline, r=GuillaumeGomez 2023-12-01 13:47:42 +09:00
llvm-project@7738295178 Update to LLVM 17.0.5 2023-11-14 12:06:30 +01:00
rustdoc-json-types rustdoc-json: Rename typedef to type alias 2023-08-21 14:02:34 -07:00
tools Auto merge of #117472 - jmillikin:stable-c-str-literals, r=Nilstrieb 2023-12-01 13:33:55 +00:00
README.md
stage0.json Bump stage0 to latest 2023-11-15 19:40:51 -05:00
version Bump nightly version 2023-11-11 11:29:33 -05:00

This directory contains some source code for the Rust project, including:

  • The bootstrapping build system
  • Various submodules for tools, like cargo, tidy, etc.

For more information on how various parts of the compiler work, see the rustc dev guide.