Skip to content

Commit c4cf95c

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 c4cf95c

File tree

24 files changed

+96
-45
lines changed

24 files changed

+96
-45
lines changed

compiler/rustc_ast_passes/src/feature_gate.rs

+1
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

+2-2
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

+1-1
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

-2
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

+2
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

+3
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

+1-1
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

+1
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";

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

+1
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
r#"aaa"#;

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

+7-7
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error: unnecessary raw string literal
2-
--> $DIR/needless_raw_string.rs:5:5
2+
--> $DIR/needless_raw_string.rs:6:5
33
|
44
LL | r#"aaa"#;
55
| ^^^^^^^^
@@ -13,7 +13,7 @@ LL + "aaa";
1313
|
1414

1515
error: unnecessary raw string literal
16-
--> $DIR/needless_raw_string.rs:8:5
16+
--> $DIR/needless_raw_string.rs:9:5
1717
|
1818
LL | br#"aaa"#;
1919
| ^^^^^^^^^
@@ -25,7 +25,7 @@ LL + b"aaa";
2525
|
2626

2727
error: unnecessary raw string literal
28-
--> $DIR/needless_raw_string.rs:11:5
28+
--> $DIR/needless_raw_string.rs:12:5
2929
|
3030
LL | cr#"aaa"#;
3131
| ^^^^^^^^^
@@ -37,7 +37,7 @@ LL + c"aaa";
3737
|
3838

3939
error: unnecessary raw string literal
40-
--> $DIR/needless_raw_string.rs:15:5
40+
--> $DIR/needless_raw_string.rs:16:5
4141
|
4242
LL | / r#"
4343
LL | | a
@@ -56,7 +56,7 @@ LL ~ ";
5656
|
5757

5858
error: unnecessary raw string literal
59-
--> $DIR/needless_raw_string.rs:21:5
59+
--> $DIR/needless_raw_string.rs:22:5
6060
|
6161
LL | r"no hashes";
6262
| ^^^^^^^^^^^^
@@ -68,7 +68,7 @@ LL + "no hashes";
6868
|
6969

7070
error: unnecessary raw string literal
71-
--> $DIR/needless_raw_string.rs:22:5
71+
--> $DIR/needless_raw_string.rs:23:5
7272
|
7373
LL | br"no hashes";
7474
| ^^^^^^^^^^^^^
@@ -80,7 +80,7 @@ LL + b"no hashes";
8080
|
8181

8282
error: unnecessary raw string literal
83-
--> $DIR/needless_raw_string.rs:23:5
83+
--> $DIR/needless_raw_string.rs:24:5
8484
|
8585
LL | cr"no hashes";
8686
| ^^^^^^^^^^^^^

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

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

45
fn main() {
56
r"\aaa";

src/tools/clippy/tests/ui/needless_raw_string_hashes.rs

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

45
fn main() {
56
r#"\aaa"#;

src/tools/clippy/tests/ui/needless_raw_string_hashes.stderr

+15-15
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error: unnecessary hashes around raw string literal
2-
--> $DIR/needless_raw_string_hashes.rs:5:5
2+
--> $DIR/needless_raw_string_hashes.rs:6:5
33
|
44
LL | r#"\aaa"#;
55
| ^^^^^^^^^
@@ -13,7 +13,7 @@ LL + r"\aaa";
1313
|
1414

1515
error: unnecessary hashes around raw string literal
16-
--> $DIR/needless_raw_string_hashes.rs:6:5
16+
--> $DIR/needless_raw_string_hashes.rs:7:5
1717
|
1818
LL | r##"Hello "world"!"##;
1919
| ^^^^^^^^^^^^^^^^^^^^^
@@ -25,7 +25,7 @@ LL + r#"Hello "world"!"#;
2525
|
2626

2727
error: unnecessary hashes around raw string literal
28-
--> $DIR/needless_raw_string_hashes.rs:7:5
28+
--> $DIR/needless_raw_string_hashes.rs:8:5
2929
|
3030
LL | r######" "### "## "# "######;
3131
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -37,7 +37,7 @@ LL + r####" "### "## "# "####;
3737
|
3838

3939
error: unnecessary hashes around raw string literal
40-
--> $DIR/needless_raw_string_hashes.rs:8:5
40+
--> $DIR/needless_raw_string_hashes.rs:9:5
4141
|
4242
LL | r######" "aa" "# "## "######;
4343
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -49,7 +49,7 @@ LL + r###" "aa" "# "## "###;
4949
|
5050

5151
error: unnecessary hashes around raw string literal
52-
--> $DIR/needless_raw_string_hashes.rs:9:5
52+
--> $DIR/needless_raw_string_hashes.rs:10:5
5353
|
5454
LL | br#"\aaa"#;
5555
| ^^^^^^^^^^
@@ -61,7 +61,7 @@ LL + br"\aaa";
6161
|
6262

6363
error: unnecessary hashes around raw string literal
64-
--> $DIR/needless_raw_string_hashes.rs:10:5
64+
--> $DIR/needless_raw_string_hashes.rs:11:5
6565
|
6666
LL | br##"Hello "world"!"##;
6767
| ^^^^^^^^^^^^^^^^^^^^^^
@@ -73,7 +73,7 @@ LL + br#"Hello "world"!"#;
7373
|
7474

7575
error: unnecessary hashes around raw string literal
76-
--> $DIR/needless_raw_string_hashes.rs:11:5
76+
--> $DIR/needless_raw_string_hashes.rs:12:5
7777
|
7878
LL | br######" "### "## "# "######;
7979
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -85,7 +85,7 @@ LL + br####" "### "## "# "####;
8585
|
8686

8787
error: unnecessary hashes around raw string literal
88-
--> $DIR/needless_raw_string_hashes.rs:12:5
88+
--> $DIR/needless_raw_string_hashes.rs:13:5
8989
|
9090
LL | br######" "aa" "# "## "######;
9191
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -97,7 +97,7 @@ LL + br###" "aa" "# "## "###;
9797
|
9898

9999
error: unnecessary hashes around raw string literal
100-
--> $DIR/needless_raw_string_hashes.rs:13:5
100+
--> $DIR/needless_raw_string_hashes.rs:14:5
101101
|
102102
LL | cr#"\aaa"#;
103103
| ^^^^^^^^^^
@@ -109,7 +109,7 @@ LL + cr"\aaa";
109109
|
110110

111111
error: unnecessary hashes around raw string literal
112-
--> $DIR/needless_raw_string_hashes.rs:14:5
112+
--> $DIR/needless_raw_string_hashes.rs:15:5
113113
|
114114
LL | cr##"Hello "world"!"##;
115115
| ^^^^^^^^^^^^^^^^^^^^^^
@@ -121,7 +121,7 @@ LL + cr#"Hello "world"!"#;
121121
|
122122

123123
error: unnecessary hashes around raw string literal
124-
--> $DIR/needless_raw_string_hashes.rs:15:5
124+
--> $DIR/needless_raw_string_hashes.rs:16:5
125125
|
126126
LL | cr######" "### "## "# "######;
127127
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -133,7 +133,7 @@ LL + cr####" "### "## "# "####;
133133
|
134134

135135
error: unnecessary hashes around raw string literal
136-
--> $DIR/needless_raw_string_hashes.rs:16:5
136+
--> $DIR/needless_raw_string_hashes.rs:17:5
137137
|
138138
LL | cr######" "aa" "# "## "######;
139139
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -145,7 +145,7 @@ LL + cr###" "aa" "# "## "###;
145145
|
146146

147147
error: unnecessary hashes around raw string literal
148-
--> $DIR/needless_raw_string_hashes.rs:18:5
148+
--> $DIR/needless_raw_string_hashes.rs:19:5
149149
|
150150
LL | / r#"
151151
LL | | \a
@@ -164,7 +164,7 @@ LL ~ ";
164164
|
165165

166166
error: unnecessary hashes around raw string literal
167-
--> $DIR/needless_raw_string_hashes.rs:24:5
167+
--> $DIR/needless_raw_string_hashes.rs:25:5
168168
|
169169
LL | r###"rust"###;
170170
| ^^^^^^^^^^^^^
@@ -176,7 +176,7 @@ LL + r"rust";
176176
|
177177

178178
error: unnecessary hashes around raw string literal
179-
--> $DIR/needless_raw_string_hashes.rs:25:5
179+
--> $DIR/needless_raw_string_hashes.rs:26:5
180180
|
181181
LL | r#"hello world"#;
182182
| ^^^^^^^^^^^^^^^^

tests/ui-fulldeps/stable-mir/check_allocation.rs

+2
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#![feature(assert_matches)]
1313
#![feature(control_flow_enum)]
1414
#![feature(ascii_char, ascii_char_variants)]
15+
#![feature(c_str_literals)]
1516

1617
extern crate rustc_hir;
1718
extern crate rustc_middle;
@@ -239,6 +240,7 @@ fn generate_input(path: &str) -> std::io::Result<()> {
239240
file,
240241
r#"
241242
#![feature(core_intrinsics)]
243+
#![feature(c_str_literals)]
242244
use std::intrinsics::type_id;
243245
244246
static LEN: usize = 2;

tests/ui/proc-macro/literal-to-string.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
// check-pass
22
// edition: 2021
3+
#![feature(c_str_literals)]
34

45
// aux-build: print-tokens.rs
56
extern crate print_tokens;

0 commit comments

Comments
 (0)