Skip to content

Commit

Permalink
Auto merge of rust-lang#119528 - wesleywiser:revert_117472, r=nnether…
Browse files Browse the repository at this point in the history
…cote

[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.
  • Loading branch information
bors committed Jan 10, 2024
2 parents 650745c + b2d48ca commit 3a3478e
Show file tree
Hide file tree
Showing 24 changed files with 96 additions and 45 deletions.
1 change: 1 addition & 0 deletions compiler/rustc_ast_passes/src/feature_gate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -515,6 +515,7 @@ 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
Original file line number Diff line number Diff line change
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(_, _)) => {
// Avoid ambiguity in handling of terminal `NUL` by refusing to
// concatenate C string literals as bytes.
// FIXME(c_str_literals): should concatenation of C string literals
// include the null bytes in the end?
cx.emit_err(errors::ConcatCStrLit { span: span });
}
Ok(ast::LitKind::Char(_)) => {
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_codegen_llvm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#![feature(rustdoc_internals)]
#![doc(rust_logo)]
#![doc(html_root_url = "https://doc.rust-lang.org/nightly/nightly-rustc/")]
#![cfg_attr(bootstrap, feature(c_str_literals))]
#![feature(c_str_literals)]
#![feature(exact_size_is_empty)]
#![feature(extern_types)]
#![feature(hash_raw_entry)]
Expand Down
2 changes: 0 additions & 2 deletions compiler/rustc_feature/src/accepted.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,6 @@ declare_features! (
(accepted, bindings_after_at, "1.56.0", Some(65490)),
/// Allows empty structs and enum variants with braces.
(accepted, braced_empty_structs, "1.8.0", Some(29720)),
/// Allows `c"foo"` literals.
(accepted, c_str_literals, "1.76.0", Some(105723)),
/// Allows `#[cfg_attr(predicate, multiple, attributes, here)]`.
(accepted, cfg_attr_multi, "1.33.0", Some(54881)),
/// Allows the use of `#[cfg(doctest)]`, set when rustdoc is collecting doctests.
Expand Down
2 changes: 2 additions & 0 deletions compiler/rustc_feature/src/unstable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -359,6 +359,8 @@ declare_features! (
(unstable, async_fn_track_caller, "1.73.0", Some(110011)),
/// Allows builtin # foo() syntax
(unstable, builtin_syntax, "1.71.0", Some(110680)),
/// Allows `c"foo"` literals.
(unstable, c_str_literals, "1.71.0", Some(105723)),
/// Treat `extern "C"` function as nounwind.
(unstable, c_unwind, "1.52.0", Some(74990)),
/// Allows using C-variadics.
Expand Down
3 changes: 3 additions & 0 deletions compiler/rustc_parse/src/lexer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,9 @@ 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
2 changes: 1 addition & 1 deletion library/std/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@
//
// Library features (core):
// tidy-alphabetical-start
#![cfg_attr(bootstrap, feature(c_str_literals))]
#![feature(c_str_literals)]
#![feature(char_internals)]
#![feature(core_intrinsics)]
#![feature(core_io_borrowed_buf)]
Expand Down
2 changes: 1 addition & 1 deletion src/doc/edition-guide
2 changes: 1 addition & 1 deletion src/doc/reference
1 change: 1 addition & 0 deletions src/tools/clippy/tests/ui/needless_raw_string.fixed
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#![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: 1 addition & 0 deletions src/tools/clippy/tests/ui/needless_raw_string.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#![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
14 changes: 7 additions & 7 deletions src/tools/clippy/tests/ui/needless_raw_string.stderr
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
error: unnecessary raw string literal
--> $DIR/needless_raw_string.rs:5:5
--> $DIR/needless_raw_string.rs:6:5
|
LL | r#"aaa"#;
| ^^^^^^^^
Expand All @@ -13,7 +13,7 @@ LL + "aaa";
|

error: unnecessary raw string literal
--> $DIR/needless_raw_string.rs:8:5
--> $DIR/needless_raw_string.rs:9:5
|
LL | br#"aaa"#;
| ^^^^^^^^^
Expand All @@ -25,7 +25,7 @@ LL + b"aaa";
|

error: unnecessary raw string literal
--> $DIR/needless_raw_string.rs:11:5
--> $DIR/needless_raw_string.rs:12:5
|
LL | cr#"aaa"#;
| ^^^^^^^^^
Expand All @@ -37,7 +37,7 @@ LL + c"aaa";
|

error: unnecessary raw string literal
--> $DIR/needless_raw_string.rs:15:5
--> $DIR/needless_raw_string.rs:16:5
|
LL | / r#"
LL | | a
Expand All @@ -56,7 +56,7 @@ LL ~ ";
|

error: unnecessary raw string literal
--> $DIR/needless_raw_string.rs:21:5
--> $DIR/needless_raw_string.rs:22:5
|
LL | r"no hashes";
| ^^^^^^^^^^^^
Expand All @@ -68,7 +68,7 @@ LL + "no hashes";
|

error: unnecessary raw string literal
--> $DIR/needless_raw_string.rs:22:5
--> $DIR/needless_raw_string.rs:23:5
|
LL | br"no hashes";
| ^^^^^^^^^^^^^
Expand All @@ -80,7 +80,7 @@ LL + b"no hashes";
|

error: unnecessary raw string literal
--> $DIR/needless_raw_string.rs:23:5
--> $DIR/needless_raw_string.rs:24:5
|
LL | cr"no hashes";
| ^^^^^^^^^^^^^
Expand Down
1 change: 1 addition & 0 deletions src/tools/clippy/tests/ui/needless_raw_string_hashes.fixed
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#![allow(clippy::no_effect, unused)]
#![warn(clippy::needless_raw_string_hashes)]
#![feature(c_str_literals)]

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

fn main() {
r#"\aaa"#;
Expand Down
30 changes: 15 additions & 15 deletions src/tools/clippy/tests/ui/needless_raw_string_hashes.stderr
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
error: unnecessary hashes around raw string literal
--> $DIR/needless_raw_string_hashes.rs:5:5
--> $DIR/needless_raw_string_hashes.rs:6:5
|
LL | r#"\aaa"#;
| ^^^^^^^^^
Expand All @@ -13,7 +13,7 @@ LL + r"\aaa";
|

error: unnecessary hashes around raw string literal
--> $DIR/needless_raw_string_hashes.rs:6:5
--> $DIR/needless_raw_string_hashes.rs:7:5
|
LL | r##"Hello "world"!"##;
| ^^^^^^^^^^^^^^^^^^^^^
Expand All @@ -25,7 +25,7 @@ LL + r#"Hello "world"!"#;
|

error: unnecessary hashes around raw string literal
--> $DIR/needless_raw_string_hashes.rs:7:5
--> $DIR/needless_raw_string_hashes.rs:8:5
|
LL | r######" "### "## "# "######;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Expand All @@ -37,7 +37,7 @@ LL + r####" "### "## "# "####;
|

error: unnecessary hashes around raw string literal
--> $DIR/needless_raw_string_hashes.rs:8:5
--> $DIR/needless_raw_string_hashes.rs:9:5
|
LL | r######" "aa" "# "## "######;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Expand All @@ -49,7 +49,7 @@ LL + r###" "aa" "# "## "###;
|

error: unnecessary hashes around raw string literal
--> $DIR/needless_raw_string_hashes.rs:9:5
--> $DIR/needless_raw_string_hashes.rs:10:5
|
LL | br#"\aaa"#;
| ^^^^^^^^^^
Expand All @@ -61,7 +61,7 @@ LL + br"\aaa";
|

error: unnecessary hashes around raw string literal
--> $DIR/needless_raw_string_hashes.rs:10:5
--> $DIR/needless_raw_string_hashes.rs:11:5
|
LL | br##"Hello "world"!"##;
| ^^^^^^^^^^^^^^^^^^^^^^
Expand All @@ -73,7 +73,7 @@ LL + br#"Hello "world"!"#;
|

error: unnecessary hashes around raw string literal
--> $DIR/needless_raw_string_hashes.rs:11:5
--> $DIR/needless_raw_string_hashes.rs:12:5
|
LL | br######" "### "## "# "######;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Expand All @@ -85,7 +85,7 @@ LL + br####" "### "## "# "####;
|

error: unnecessary hashes around raw string literal
--> $DIR/needless_raw_string_hashes.rs:12:5
--> $DIR/needless_raw_string_hashes.rs:13:5
|
LL | br######" "aa" "# "## "######;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Expand All @@ -97,7 +97,7 @@ LL + br###" "aa" "# "## "###;
|

error: unnecessary hashes around raw string literal
--> $DIR/needless_raw_string_hashes.rs:13:5
--> $DIR/needless_raw_string_hashes.rs:14:5
|
LL | cr#"\aaa"#;
| ^^^^^^^^^^
Expand All @@ -109,7 +109,7 @@ LL + cr"\aaa";
|

error: unnecessary hashes around raw string literal
--> $DIR/needless_raw_string_hashes.rs:14:5
--> $DIR/needless_raw_string_hashes.rs:15:5
|
LL | cr##"Hello "world"!"##;
| ^^^^^^^^^^^^^^^^^^^^^^
Expand All @@ -121,7 +121,7 @@ LL + cr#"Hello "world"!"#;
|

error: unnecessary hashes around raw string literal
--> $DIR/needless_raw_string_hashes.rs:15:5
--> $DIR/needless_raw_string_hashes.rs:16:5
|
LL | cr######" "### "## "# "######;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Expand All @@ -133,7 +133,7 @@ LL + cr####" "### "## "# "####;
|

error: unnecessary hashes around raw string literal
--> $DIR/needless_raw_string_hashes.rs:16:5
--> $DIR/needless_raw_string_hashes.rs:17:5
|
LL | cr######" "aa" "# "## "######;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Expand All @@ -145,7 +145,7 @@ LL + cr###" "aa" "# "## "###;
|

error: unnecessary hashes around raw string literal
--> $DIR/needless_raw_string_hashes.rs:18:5
--> $DIR/needless_raw_string_hashes.rs:19:5
|
LL | / r#"
LL | | \a
Expand All @@ -164,7 +164,7 @@ LL ~ ";
|

error: unnecessary hashes around raw string literal
--> $DIR/needless_raw_string_hashes.rs:24:5
--> $DIR/needless_raw_string_hashes.rs:25:5
|
LL | r###"rust"###;
| ^^^^^^^^^^^^^
Expand All @@ -176,7 +176,7 @@ LL + r"rust";
|

error: unnecessary hashes around raw string literal
--> $DIR/needless_raw_string_hashes.rs:25:5
--> $DIR/needless_raw_string_hashes.rs:26:5
|
LL | r#"hello world"#;
| ^^^^^^^^^^^^^^^^
Expand Down
2 changes: 2 additions & 0 deletions tests/ui-fulldeps/stable-mir/check_allocation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#![feature(assert_matches)]
#![feature(control_flow_enum)]
#![feature(ascii_char, ascii_char_variants)]
#![feature(c_str_literals)]

extern crate rustc_hir;
extern crate rustc_middle;
Expand Down Expand Up @@ -239,6 +240,7 @@ fn generate_input(path: &str) -> std::io::Result<()> {
file,
r#"
#![feature(core_intrinsics)]
#![feature(c_str_literals)]
use std::intrinsics::type_id;
static LEN: usize = 2;
Expand Down
1 change: 1 addition & 0 deletions tests/ui/proc-macro/literal-to-string.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// check-pass
// edition: 2021
#![feature(c_str_literals)]

// aux-build: print-tokens.rs
extern crate print_tokens;
Expand Down
Loading

0 comments on commit 3a3478e

Please sign in to comment.