Skip to content

Commit 0f41bc2

Browse files
committed
Stabilize C string literals
1 parent a395214 commit 0f41bc2

19 files changed

+41
-90
lines changed

compiler/rustc_ast_passes/src/feature_gate.rs

-1
Original file line numberDiff line numberDiff line change
@@ -536,7 +536,6 @@ pub fn check_crate(krate: &ast::Crate, sess: &Session, features: &Features) {
536536
}
537537
};
538538
}
539-
gate_all!(c_str_literals, "`c\"..\"` literals are experimental");
540539
gate_all!(
541540
if_let_guard,
542541
"`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-
// FIXME(c_str_literals): should concatenation of C string literals
23-
// include the null bytes in the end?
22+
// Avoid ambiguity in handling of terminal `NUL` by refusing to
23+
// concatenate C string literals as bytes.
2424
cx.emit_err(errors::ConcatCStrLit { span: span });
2525
}
2626
Ok(ast::LitKind::Char(_)) => {

compiler/rustc_feature/src/accepted.rs

+2
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,8 @@ declare_features! (
7777
(accepted, bindings_after_at, "1.56.0", Some(65490), None),
7878
/// Allows empty structs and enum variants with braces.
7979
(accepted, braced_empty_structs, "1.8.0", Some(29720), None),
80+
/// Allows `c"foo"` literals.
81+
(accepted, c_str_literals, "CURRENT_RUSTC_VERSION", Some(105723), None),
8082
/// Allows `#[cfg_attr(predicate, multiple, attributes, here)]`.
8183
(accepted, cfg_attr_multi, "1.33.0", Some(54881), None),
8284
/// 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
@@ -346,8 +346,6 @@ declare_features! (
346346
(unstable, async_fn_track_caller, "1.73.0", Some(110011), None),
347347
/// Allows builtin # foo() syntax
348348
(unstable, builtin_syntax, "1.71.0", Some(110680), None),
349-
/// Allows `c"foo"` literals.
350-
(unstable, c_str_literals, "1.71.0", Some(105723), None),
351349
/// Treat `extern "C"` function as nounwind.
352350
(unstable, c_unwind, "1.52.0", Some(74990), None),
353351
/// Allows using C-variadics.

compiler/rustc_parse/src/lexer/mod.rs

-3
Original file line numberDiff line numberDiff line change
@@ -221,9 +221,6 @@ impl<'a> StringReader<'a> {
221221
rustc_lexer::TokenKind::Literal { kind, suffix_start } => {
222222
let suffix_start = start + BytePos(suffix_start);
223223
let (kind, symbol) = self.cook_lexer_literal(start, suffix_start, kind);
224-
if let token::LitKind::CStr | token::LitKind::CStrRaw(_) = kind {
225-
self.sess.gated_spans.gate(sym::c_str_literals, self.mk_sp(start, self.pos));
226-
}
227224
let suffix = if suffix_start < self.pos {
228225
let string = self.str_from(suffix_start);
229226
if string == "_" {

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

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

54
fn main() {
65
"aaa";

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

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

54
fn main() {
65
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:6:5
2+
--> $DIR/needless_raw_string.rs:5: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:9:5
16+
--> $DIR/needless_raw_string.rs:8: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:12:5
28+
--> $DIR/needless_raw_string.rs:11: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:16:5
40+
--> $DIR/needless_raw_string.rs:15: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:22:5
59+
--> $DIR/needless_raw_string.rs:21: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:23:5
71+
--> $DIR/needless_raw_string.rs:22: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:24:5
83+
--> $DIR/needless_raw_string.rs:23: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,6 +1,5 @@
11
#![allow(clippy::no_effect, unused)]
22
#![warn(clippy::needless_raw_string_hashes)]
3-
#![feature(c_str_literals)]
43

54
fn main() {
65
r"\aaa";

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

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

54
fn main() {
65
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:6:5
2+
--> $DIR/needless_raw_string_hashes.rs:5: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:7:5
16+
--> $DIR/needless_raw_string_hashes.rs:6: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:8:5
28+
--> $DIR/needless_raw_string_hashes.rs:7: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:9:5
40+
--> $DIR/needless_raw_string_hashes.rs:8: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:10:5
52+
--> $DIR/needless_raw_string_hashes.rs:9: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:11:5
64+
--> $DIR/needless_raw_string_hashes.rs:10: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:12:5
76+
--> $DIR/needless_raw_string_hashes.rs:11: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:13:5
88+
--> $DIR/needless_raw_string_hashes.rs:12: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:14:5
100+
--> $DIR/needless_raw_string_hashes.rs:13: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:15:5
112+
--> $DIR/needless_raw_string_hashes.rs:14: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:16:5
124+
--> $DIR/needless_raw_string_hashes.rs:15: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:17:5
136+
--> $DIR/needless_raw_string_hashes.rs:16: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:19:5
148+
--> $DIR/needless_raw_string_hashes.rs:18: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:25:5
167+
--> $DIR/needless_raw_string_hashes.rs:24: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:26:5
179+
--> $DIR/needless_raw_string_hashes.rs:25:5
180180
|
181181
LL | r#"hello world"#;
182182
| ^^^^^^^^^^^^^^^^

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

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

54
// aux-build: print-tokens.rs
65
extern crate print_tokens;

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

+15-15
Original file line numberDiff line numberDiff line change
@@ -3,91 +3,91 @@ TokenStream [
33
kind: Integer,
44
symbol: "1",
55
suffix: None,
6-
span: #0 bytes(172..173),
6+
span: #0 bytes(144..145),
77
},
88
Literal {
99
kind: Integer,
1010
symbol: "17",
1111
suffix: Some("u8"),
12-
span: #0 bytes(182..186),
12+
span: #0 bytes(154..158),
1313
},
1414
Literal {
1515
kind: Float,
1616
symbol: "42.",
1717
suffix: None,
18-
span: #0 bytes(195..198),
18+
span: #0 bytes(167..170),
1919
},
2020
Literal {
2121
kind: Float,
2222
symbol: "3.14",
2323
suffix: Some("f32"),
24-
span: #0 bytes(207..214),
24+
span: #0 bytes(179..186),
2525
},
2626
Literal {
2727
kind: Byte,
2828
symbol: "a",
2929
suffix: None,
30-
span: #0 bytes(223..227),
30+
span: #0 bytes(195..199),
3131
},
3232
Literal {
3333
kind: Byte,
3434
symbol: "\xFF",
3535
suffix: None,
36-
span: #0 bytes(236..243),
36+
span: #0 bytes(208..215),
3737
},
3838
Literal {
3939
kind: Char,
4040
symbol: "c",
4141
suffix: None,
42-
span: #0 bytes(252..255),
42+
span: #0 bytes(224..227),
4343
},
4444
Literal {
4545
kind: Char,
4646
symbol: "\x32",
4747
suffix: None,
48-
span: #0 bytes(264..270),
48+
span: #0 bytes(236..242),
4949
},
5050
Literal {
5151
kind: Str,
5252
symbol: "\\"str\\"",
5353
suffix: None,
54-
span: #0 bytes(279..288),
54+
span: #0 bytes(251..260),
5555
},
5656
Literal {
5757
kind: StrRaw(1),
5858
symbol: "\"raw\" str",
5959
suffix: None,
60-
span: #0 bytes(297..311),
60+
span: #0 bytes(269..283),
6161
},
6262
Literal {
6363
kind: StrRaw(3),
6464
symbol: "very ##\"raw\"## str",
6565
suffix: None,
66-
span: #0 bytes(320..347),
66+
span: #0 bytes(292..319),
6767
},
6868
Literal {
6969
kind: ByteStr,
7070
symbol: "\\"byte\\" str",
7171
suffix: None,
72-
span: #0 bytes(356..371),
72+
span: #0 bytes(328..343),
7373
},
7474
Literal {
7575
kind: ByteStrRaw(1),
7676
symbol: "\"raw\" \"byte\" str",
7777
suffix: None,
78-
span: #0 bytes(380..402),
78+
span: #0 bytes(352..374),
7979
},
8080
Literal {
8181
kind: CStr,
8282
symbol: "\\"c\\" str",
8383
suffix: None,
84-
span: #0 bytes(411..423),
84+
span: #0 bytes(383..395),
8585
},
8686
Literal {
8787
kind: CStrRaw(1),
8888
symbol: "\"raw\" \"c\" str",
8989
suffix: None,
90-
span: #0 bytes(432..451),
90+
span: #0 bytes(404..423),
9191
},
9292
]
9393
1
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
// run-pass
22
// edition: 2021
33

4-
#![feature(c_str_literals)]
5-
64
fn main() {
75
assert_eq!(b"test\0", c"test".to_bytes_with_nul());
86
}

0 commit comments

Comments
 (0)