Skip to content

Commit 3a3478e

Browse files
committed
Auto merge of rust-lang#119528 - wesleywiser:revert_117472, r=nnethercote
[beta] Revert rust-lang#117472: Stabilize C string literals Based on discussion in [#t-lang](https://rust-lang.zulipchat.com/#narrow/stream/213817-t-lang/topic/rfc.203349.3A.20mixed.20utf8.20literals), revert the stabilization of C string literals in Rust 1.76. I also reverted rust-lang#118566 as it uses the newly stabilized C string literals in various places.
2 parents 650745c + b2d48ca commit 3a3478e

File tree

24 files changed

+96
-45
lines changed

24 files changed

+96
-45
lines changed

compiler/rustc_ast_passes/src/feature_gate.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -515,6 +515,7 @@ pub fn check_crate(krate: &ast::Crate, sess: &Session, features: &Features) {
515515
}
516516
};
517517
}
518+
gate_all!(c_str_literals, "`c\"..\"` literals are experimental");
518519
gate_all!(
519520
if_let_guard,
520521
"`if let` guards are experimental",

compiler/rustc_builtin_macros/src/concat_bytes.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ fn invalid_type_err(
1919
let snippet = cx.sess.source_map().span_to_snippet(span).ok();
2020
match ast::LitKind::from_token_lit(token_lit) {
2121
Ok(ast::LitKind::CStr(_, _)) => {
22-
// Avoid ambiguity in handling of terminal `NUL` by refusing to
23-
// concatenate C string literals as bytes.
22+
// FIXME(c_str_literals): should concatenation of C string literals
23+
// include the null bytes in the end?
2424
cx.emit_err(errors::ConcatCStrLit { span: span });
2525
}
2626
Ok(ast::LitKind::Char(_)) => {

compiler/rustc_codegen_llvm/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
#![feature(rustdoc_internals)]
99
#![doc(rust_logo)]
1010
#![doc(html_root_url = "https://doc.rust-lang.org/nightly/nightly-rustc/")]
11-
#![cfg_attr(bootstrap, feature(c_str_literals))]
11+
#![feature(c_str_literals)]
1212
#![feature(exact_size_is_empty)]
1313
#![feature(extern_types)]
1414
#![feature(hash_raw_entry)]

compiler/rustc_feature/src/accepted.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,6 @@ declare_features! (
7676
(accepted, bindings_after_at, "1.56.0", Some(65490)),
7777
/// Allows empty structs and enum variants with braces.
7878
(accepted, braced_empty_structs, "1.8.0", Some(29720)),
79-
/// Allows `c"foo"` literals.
80-
(accepted, c_str_literals, "1.76.0", Some(105723)),
8179
/// Allows `#[cfg_attr(predicate, multiple, attributes, here)]`.
8280
(accepted, cfg_attr_multi, "1.33.0", Some(54881)),
8381
/// Allows the use of `#[cfg(doctest)]`, set when rustdoc is collecting doctests.

compiler/rustc_feature/src/unstable.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -359,6 +359,8 @@ declare_features! (
359359
(unstable, async_fn_track_caller, "1.73.0", Some(110011)),
360360
/// Allows builtin # foo() syntax
361361
(unstable, builtin_syntax, "1.71.0", Some(110680)),
362+
/// Allows `c"foo"` literals.
363+
(unstable, c_str_literals, "1.71.0", Some(105723)),
362364
/// Treat `extern "C"` function as nounwind.
363365
(unstable, c_unwind, "1.52.0", Some(74990)),
364366
/// Allows using C-variadics.

compiler/rustc_parse/src/lexer/mod.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,9 @@ impl<'a> StringReader<'a> {
223223
rustc_lexer::TokenKind::Literal { kind, suffix_start } => {
224224
let suffix_start = start + BytePos(suffix_start);
225225
let (kind, symbol) = self.cook_lexer_literal(start, suffix_start, kind);
226+
if let token::LitKind::CStr | token::LitKind::CStrRaw(_) = kind {
227+
self.sess.gated_spans.gate(sym::c_str_literals, self.mk_sp(start, self.pos));
228+
}
226229
let suffix = if suffix_start < self.pos {
227230
let string = self.str_from(suffix_start);
228231
if string == "_" {

library/std/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -308,7 +308,7 @@
308308
//
309309
// Library features (core):
310310
// tidy-alphabetical-start
311-
#![cfg_attr(bootstrap, feature(c_str_literals))]
311+
#![feature(c_str_literals)]
312312
#![feature(char_internals)]
313313
#![feature(core_intrinsics)]
314314
#![feature(core_io_borrowed_buf)]

src/tools/clippy/tests/ui/needless_raw_string.fixed

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#![allow(clippy::needless_raw_string_hashes, clippy::no_effect, unused)]
22
#![warn(clippy::needless_raw_strings)]
3+
#![feature(c_str_literals)]
34

45
fn main() {
56
"aaa";

0 commit comments

Comments
 (0)