Skip to content

Commit

Permalink
Stabilize C string literals
Browse files Browse the repository at this point in the history
  • Loading branch information
jmillikin committed Nov 1, 2023
1 parent a395214 commit 56fe3f9
Show file tree
Hide file tree
Showing 17 changed files with 19 additions and 68 deletions.
1 change: 0 additions & 1 deletion compiler/rustc_ast_passes/src/feature_gate.rs
Expand Up @@ -536,7 +536,6 @@ pub fn check_crate(krate: &ast::Crate, sess: &Session, features: &Features) {
}
};
}
gate_all!(c_str_literals, "`c\"..\"` literals are experimental");
gate_all!(
if_let_guard,
"`if let` guards are experimental",
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_builtin_macros/src/concat_bytes.rs
Expand Up @@ -19,8 +19,8 @@ fn invalid_type_err(
let snippet = cx.sess.source_map().span_to_snippet(span).ok();
match ast::LitKind::from_token_lit(token_lit) {
Ok(ast::LitKind::CStr(_, _)) => {
// FIXME(c_str_literals): should concatenation of C string literals
// include the null bytes in the end?
// Avoid ambiguity in handling of terminal `NUL` by refusing to
// concatenate C string literals as bytes.
cx.emit_err(errors::ConcatCStrLit { span: span });
}
Ok(ast::LitKind::Char(_)) => {
Expand Down
2 changes: 2 additions & 0 deletions compiler/rustc_feature/src/accepted.rs
Expand Up @@ -77,6 +77,8 @@ declare_features! (
(accepted, bindings_after_at, "1.56.0", Some(65490), None),
/// Allows empty structs and enum variants with braces.
(accepted, braced_empty_structs, "1.8.0", Some(29720), None),
/// Allows `c"foo"` literals.
(accepted, c_str_literals, "CURRENT_RUSTC_VERSION", Some(105723), None),
/// Allows `#[cfg_attr(predicate, multiple, attributes, here)]`.
(accepted, cfg_attr_multi, "1.33.0", Some(54881), None),
/// Allows the use of `#[cfg(doctest)]`, set when rustdoc is collecting doctests.
Expand Down
2 changes: 0 additions & 2 deletions compiler/rustc_feature/src/unstable.rs
Expand Up @@ -346,8 +346,6 @@ declare_features! (
(unstable, async_fn_track_caller, "1.73.0", Some(110011), None),
/// Allows builtin # foo() syntax
(unstable, builtin_syntax, "1.71.0", Some(110680), None),
/// Allows `c"foo"` literals.
(unstable, c_str_literals, "1.71.0", Some(105723), None),
/// Treat `extern "C"` function as nounwind.
(unstable, c_unwind, "1.52.0", Some(74990), None),
/// Allows using C-variadics.
Expand Down
3 changes: 0 additions & 3 deletions compiler/rustc_parse/src/lexer/mod.rs
Expand Up @@ -221,9 +221,6 @@ impl<'a> StringReader<'a> {
rustc_lexer::TokenKind::Literal { kind, suffix_start } => {
let suffix_start = start + BytePos(suffix_start);
let (kind, symbol) = self.cook_lexer_literal(start, suffix_start, kind);
if let token::LitKind::CStr | token::LitKind::CStrRaw(_) = kind {
self.sess.gated_spans.gate(sym::c_str_literals, self.mk_sp(start, self.pos));
}
let suffix = if suffix_start < self.pos {
let string = self.str_from(suffix_start);
if string == "_" {
Expand Down
1 change: 0 additions & 1 deletion src/tools/clippy/tests/ui/needless_raw_string.fixed
@@ -1,6 +1,5 @@
#![allow(clippy::needless_raw_string_hashes, clippy::no_effect, unused)]
#![warn(clippy::needless_raw_strings)]
#![feature(c_str_literals)]

fn main() {
"aaa";
Expand Down
1 change: 0 additions & 1 deletion src/tools/clippy/tests/ui/needless_raw_string.rs
@@ -1,6 +1,5 @@
#![allow(clippy::needless_raw_string_hashes, clippy::no_effect, unused)]
#![warn(clippy::needless_raw_strings)]
#![feature(c_str_literals)]

fn main() {
r#"aaa"#;
Expand Down
1 change: 0 additions & 1 deletion src/tools/clippy/tests/ui/needless_raw_string_hashes.fixed
@@ -1,6 +1,5 @@
#![allow(clippy::no_effect, unused)]
#![warn(clippy::needless_raw_string_hashes)]
#![feature(c_str_literals)]

fn main() {
r"\aaa";
Expand Down
1 change: 0 additions & 1 deletion src/tools/clippy/tests/ui/needless_raw_string_hashes.rs
@@ -1,6 +1,5 @@
#![allow(clippy::no_effect, unused)]
#![warn(clippy::needless_raw_string_hashes)]
#![feature(c_str_literals)]

fn main() {
r#"\aaa"#;
Expand Down
1 change: 0 additions & 1 deletion tests/ui/proc-macro/literal-to-string.rs
@@ -1,6 +1,5 @@
// check-pass
// edition: 2021
#![feature(c_str_literals)]

// aux-build: print-tokens.rs
extern crate print_tokens;
Expand Down
30 changes: 15 additions & 15 deletions tests/ui/proc-macro/literal-to-string.stdout
Expand Up @@ -3,91 +3,91 @@ TokenStream [
kind: Integer,
symbol: "1",
suffix: None,
span: #0 bytes(172..173),
span: #0 bytes(144..145),
},
Literal {
kind: Integer,
symbol: "17",
suffix: Some("u8"),
span: #0 bytes(182..186),
span: #0 bytes(154..158),
},
Literal {
kind: Float,
symbol: "42.",
suffix: None,
span: #0 bytes(195..198),
span: #0 bytes(167..170),
},
Literal {
kind: Float,
symbol: "3.14",
suffix: Some("f32"),
span: #0 bytes(207..214),
span: #0 bytes(179..186),
},
Literal {
kind: Byte,
symbol: "a",
suffix: None,
span: #0 bytes(223..227),
span: #0 bytes(195..199),
},
Literal {
kind: Byte,
symbol: "\xFF",
suffix: None,
span: #0 bytes(236..243),
span: #0 bytes(208..215),
},
Literal {
kind: Char,
symbol: "c",
suffix: None,
span: #0 bytes(252..255),
span: #0 bytes(224..227),
},
Literal {
kind: Char,
symbol: "\x32",
suffix: None,
span: #0 bytes(264..270),
span: #0 bytes(236..242),
},
Literal {
kind: Str,
symbol: "\\"str\\"",
suffix: None,
span: #0 bytes(279..288),
span: #0 bytes(251..260),
},
Literal {
kind: StrRaw(1),
symbol: "\"raw\" str",
suffix: None,
span: #0 bytes(297..311),
span: #0 bytes(269..283),
},
Literal {
kind: StrRaw(3),
symbol: "very ##\"raw\"## str",
suffix: None,
span: #0 bytes(320..347),
span: #0 bytes(292..319),
},
Literal {
kind: ByteStr,
symbol: "\\"byte\\" str",
suffix: None,
span: #0 bytes(356..371),
span: #0 bytes(328..343),
},
Literal {
kind: ByteStrRaw(1),
symbol: "\"raw\" \"byte\" str",
suffix: None,
span: #0 bytes(380..402),
span: #0 bytes(352..374),
},
Literal {
kind: CStr,
symbol: "\\"c\\" str",
suffix: None,
span: #0 bytes(411..423),
span: #0 bytes(383..395),
},
Literal {
kind: CStrRaw(1),
symbol: "\"raw\" \"c\" str",
suffix: None,
span: #0 bytes(432..451),
span: #0 bytes(404..423),
},
]
1
Expand Down
2 changes: 0 additions & 2 deletions tests/ui/rfcs/rfc-3348-c-string-literals/basic.rs
@@ -1,8 +1,6 @@
// run-pass
// edition: 2021

#![feature(c_str_literals)]

fn main() {
assert_eq!(b"test\0", c"test".to_bytes_with_nul());
}
15 changes: 0 additions & 15 deletions tests/ui/rfcs/rfc-3348-c-string-literals/gate.rs

This file was deleted.

21 changes: 0 additions & 21 deletions tests/ui/rfcs/rfc-3348-c-string-literals/gate.stderr

This file was deleted.

Binary file modified tests/ui/rfcs/rfc-3348-c-string-literals/no-nuls.rs
Binary file not shown.
Binary file modified tests/ui/rfcs/rfc-3348-c-string-literals/no-nuls.stderr
Binary file not shown.
2 changes: 0 additions & 2 deletions tests/ui/rfcs/rfc-3348-c-string-literals/non-ascii.rs
@@ -1,8 +1,6 @@
// run-pass
// edition: 2021

#![feature(c_str_literals)]

fn main() {
assert_eq!(
c"\xEF\x80🦀\u{1F980}".to_bytes_with_nul(),
Expand Down

0 comments on commit 56fe3f9

Please sign in to comment.