rust/compiler
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
..
rustc Clean up rustc_*/Cargo.toml. 2023-10-30 08:46:02 +11:00
rustc_abi Fix clippy::needless_borrow in the compiler 2023-11-21 20:13:40 +01:00
rustc_arena Bump cfg(bootstrap)s 2023-11-15 19:41:28 -05:00
rustc_ast Rollup merge of #118157 - Nadrieril:never_pat-feature-gate, r=compiler-errors 2023-11-29 12:34:47 +01:00
rustc_ast_lowering Rollup merge of #118157 - Nadrieril:never_pat-feature-gate, r=compiler-errors 2023-11-29 12:34:47 +01:00
rustc_ast_passes Auto merge of #117472 - jmillikin:stable-c-str-literals, r=Nilstrieb 2023-12-01 13:33:55 +00:00
rustc_ast_pretty Rollup merge of #118157 - Nadrieril:never_pat-feature-gate, r=compiler-errors 2023-11-29 12:34:47 +01:00
rustc_attr Detect and reject malformed repr(Rust) hints 2023-11-27 12:29:21 +01:00
rustc_baked_icu_data Bump cfg(bootstrap)s 2023-11-15 19:41:28 -05:00
rustc_borrowck Auto merge of #118216 - lqd:constraint-generation-non-non, r=matthewjasper 2023-12-01 11:33:43 +00:00
rustc_builtin_macros Auto merge of #117472 - jmillikin:stable-c-str-literals, r=Nilstrieb 2023-12-01 13:33:55 +00:00
rustc_codegen_cranelift Auto merge of #118279 - bjorn3:sync_cg_clif-2023-11-25, r=bjorn3 2023-11-25 13:08:29 +00:00
rustc_codegen_gcc Use rustc_fluent_macro::fluent_messages! directly. 2023-11-26 08:38:40 +11:00
rustc_codegen_llvm Auto merge of #116892 - ojeda:rethunk, r=wesleywiser 2023-11-30 22:10:30 +00:00
rustc_codegen_ssa Auto merge of #118472 - nnethercote:rustc_session, r=bjorn3 2023-12-01 00:08:04 +00:00
rustc_const_eval Auto merge of #118482 - RalfJung:interpret-local-type, r=WaffleLapkin 2023-12-01 04:08:22 +00:00
rustc_data_structures Avoid an unnecessary by_ref. 2023-11-28 14:32:40 +11:00
rustc_driver Bump cfg(bootstrap)s 2023-11-15 19:41:28 -05:00
rustc_driver_impl Auto merge of #118472 - nnethercote:rustc_session, r=bjorn3 2023-12-01 00:08:04 +00:00
rustc_error_codes Yeet E0744 2023-11-28 20:40:38 +00:00
rustc_error_messages Remove rustc_error_messages/messages.ftl. 2023-11-26 08:37:27 +11:00
rustc_errors Use rustc_fluent_macro::fluent_messages! directly. 2023-11-26 08:38:40 +11:00
rustc_expand Use rustc_fluent_macro::fluent_messages! directly. 2023-11-26 08:38:40 +11:00
rustc_feature Auto merge of #117472 - jmillikin:stable-c-str-literals, r=Nilstrieb 2023-12-01 13:33:55 +00:00
rustc_fluent_macro Add a useful comment. 2023-11-26 08:38:02 +11:00
rustc_fs_util Clean up rustc_*/Cargo.toml. 2023-10-30 08:46:02 +11:00
rustc_graphviz remove unused pub fn 2023-11-23 14:11:02 +03:00
rustc_hir Rollup merge of #118157 - Nadrieril:never_pat-feature-gate, r=compiler-errors 2023-11-29 12:34:47 +01:00
rustc_hir_analysis Rollup merge of #118157 - Nadrieril:never_pat-feature-gate, r=compiler-errors 2023-11-29 12:34:47 +01:00
rustc_hir_pretty Add never_patterns feature gate 2023-11-29 03:58:29 +01:00
rustc_hir_typeck Rollup merge of #118453 - estebank:priv-fields, r=compiler-errors 2023-11-30 09:28:25 +01:00
rustc_incremental Remove unused field from IncrCompSession. 2023-12-01 08:00:56 +11:00
rustc_index Replace no_ord_impl with orderable. 2023-11-22 18:38:17 +11:00
rustc_index_macros Put backticks around some attributes in doc comments. 2023-11-27 09:37:01 +11:00
rustc_infer Rollup merge of #118269 - compiler-errors:poly, r=wesleywiser 2023-11-29 04:23:22 +01:00
rustc_interface Add -Zfunction-return={keep,thunk-extern} option 2023-11-30 20:21:31 +01:00
rustc_lexer Clean up rustc_*/Cargo.toml. 2023-10-30 08:46:02 +11:00
rustc_lint Rollup merge of #118157 - Nadrieril:never_pat-feature-gate, r=compiler-errors 2023-11-29 12:34:47 +01:00
rustc_lint_defs Remove --check-cfg checking of --cfg args 2023-11-18 12:21:58 +01:00
rustc_llvm Add -Zfunction-return={keep,thunk-extern} option 2023-11-30 20:21:31 +01:00
rustc_log rustc_log: provide a way to init logging based on the values, not names, of the env vars 2023-11-11 15:24:33 +01:00
rustc_macros Unify HashStable implementations 2023-11-21 05:49:45 +00:00
rustc_metadata Auto merge of #118472 - nnethercote:rustc_session, r=bjorn3 2023-12-01 00:08:04 +00:00
rustc_middle Auto merge of #118379 - compiler-errors:const-params-for-partialeq, r=fee1-dead 2023-11-30 05:24:53 +00:00
rustc_mir_build Auto merge of #118379 - compiler-errors:const-params-for-partialeq, r=fee1-dead 2023-11-30 05:24:53 +00:00
rustc_mir_dataflow Rollup merge of #118288 - compiler-errors:is_some_and, r=lqd,dtolnay 2023-11-25 17:23:34 -05:00
rustc_mir_transform Rollup merge of #118426 - aDotInTheVoid:const-wat, r=compiler-errors,cjgillot 2023-11-29 12:34:50 +01:00
rustc_monomorphize merge DefKind::Coroutine into DefKind::Closure 2023-11-26 21:05:08 +08:00
rustc_parse Auto merge of #117472 - jmillikin:stable-c-str-literals, r=Nilstrieb 2023-12-01 13:33:55 +00:00
rustc_parse_format Auto merge of #117819 - fmease:rustc_parse_format-stable-rustc, r=Nilstrieb 2023-11-15 14:55:35 +00:00
rustc_passes Rollup merge of #118157 - Nadrieril:never_pat-feature-gate, r=compiler-errors 2023-11-29 12:34:47 +01:00
rustc_privacy Rollup merge of #118311 - bvanjoi:merge_coroutinue_into_closure, r=petrochenkov 2023-11-26 15:44:54 +01:00
rustc_query_impl QueryContext: rename try_collect_active_jobs -> collect_active_jobs and change it's return type from Option<QueryMap> to QueryMap 2023-11-27 18:13:15 +03:00
rustc_query_system Auto merge of #118348 - Mark-Simulacrum:feature-code-size, r=compiler-errors 2023-11-29 02:45:36 +00:00
rustc_resolve generic_const_exprs: suggest to add the feature, not use it 2023-11-30 20:59:51 +01:00
rustc_serialize Call FileEncoder::finish in rmeta encoding 2023-11-22 22:49:22 -05:00
rustc_session Auto merge of #118472 - nnethercote:rustc_session, r=bjorn3 2023-12-01 00:08:04 +00:00
rustc_smir Change SwitchTarget representation 2023-11-30 11:45:34 -08:00
rustc_span Enable link-arg link kind inside of #[link] attribute 2023-11-30 08:26:13 -08:00
rustc_symbol_mangling merge DefKind::Coroutine into DefKind::Closure 2023-11-26 21:05:08 +08:00
rustc_target Pass +forced-atomics feature for riscv32{i,im,imc}-unknown-none-elf 2023-11-28 10:39:37 +09:00
rustc_trait_selection Auto merge of #117805 - estebank:arg-fn-mismatch, r=petrochenkov 2023-11-30 20:12:53 +00:00
rustc_traits Auto merge of #118120 - compiler-errors:closure-kind, r=lcnr 2023-11-22 21:09:01 +00:00
rustc_transmute Update itertools to 0.11. 2023-11-22 08:13:21 +11:00
rustc_ty_utils resolve: Feed the def_kind query immediately on DefId creation 2023-11-28 15:39:31 +03:00
rustc_type_ir Auto merge of #118120 - compiler-errors:closure-kind, r=lcnr 2023-11-22 21:09:01 +00:00
stable_mir Fix SwitchTarget pretty print 2023-11-30 11:45:34 -08:00