From c6643b50ea7290daf0a9f0e33d1f27c6f52796ce Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Le=C3=B3n=20Orell=20Valerian=20Liehr?= Date: Tue, 4 Jul 2023 19:40:48 +0200 Subject: [PATCH] Revert the lexing of c_str_literals --- compiler/rustc_lexer/src/lib.rs | 7 ---- .../rfcs/rfc-3348-c-string-literals/basic.rs | 4 +- .../rfc-3348-c-string-literals/basic.stderr | 25 ++++++++++++ .../rfcs/rfc-3348-c-string-literals/gate.rs | 6 ++- .../rfc-3348-c-string-literals/gate.stderr | 35 ++++++++++------ .../rfc-3348-c-string-literals/no-nuls.rs | Bin 565 -> 760 bytes .../rfc-3348-c-string-literals/no-nuls.stderr | Bin 674 -> 4477 bytes .../rfc-3348-c-string-literals/non-ascii.rs | 4 +- .../non-ascii.stderr | 38 ++++++++++++++++++ 9 files changed, 96 insertions(+), 23 deletions(-) create mode 100644 tests/ui/rfcs/rfc-3348-c-string-literals/basic.stderr create mode 100644 tests/ui/rfcs/rfc-3348-c-string-literals/non-ascii.stderr diff --git a/compiler/rustc_lexer/src/lib.rs b/compiler/rustc_lexer/src/lib.rs index d511d2b1280..29335a8c0f4 100644 --- a/compiler/rustc_lexer/src/lib.rs +++ b/compiler/rustc_lexer/src/lib.rs @@ -367,13 +367,6 @@ impl Cursor<'_> { Some(|terminated| Byte { terminated }), ), - // c-string literal, raw c-string literal or identifier. - 'c' => self.c_or_byte_string( - |terminated| CStr { terminated }, - |n_hashes| RawCStr { n_hashes }, - None, - ), - // Identifier (this should be checked after other variant that can // start as identifier). c if is_id_start(c) => self.ident_or_unknown_prefix(), diff --git a/tests/ui/rfcs/rfc-3348-c-string-literals/basic.rs b/tests/ui/rfcs/rfc-3348-c-string-literals/basic.rs index e4b07ab8108..3fc5fd481ea 100644 --- a/tests/ui/rfcs/rfc-3348-c-string-literals/basic.rs +++ b/tests/ui/rfcs/rfc-3348-c-string-literals/basic.rs @@ -1,4 +1,6 @@ -// run-pass +// FIXME(c_str_literals): This should be `run-pass` +// known-bug: #113333 +// edition: 2021 #![feature(c_str_literals)] diff --git a/tests/ui/rfcs/rfc-3348-c-string-literals/basic.stderr b/tests/ui/rfcs/rfc-3348-c-string-literals/basic.stderr new file mode 100644 index 00000000000..571c319d8c5 --- /dev/null +++ b/tests/ui/rfcs/rfc-3348-c-string-literals/basic.stderr @@ -0,0 +1,25 @@ +error: prefix `c` is unknown + --> $DIR/basic.rs:8:27 + | +LL | assert_eq!(b"test\0", c"test".to_bytes_with_nul()); + | ^ unknown prefix + | + = note: prefixed identifiers and literals are reserved since Rust 2021 +help: consider inserting whitespace here + | +LL | assert_eq!(b"test\0", c "test".to_bytes_with_nul()); + | + + +error: no rules expected the token `"test"` + --> $DIR/basic.rs:8:28 + | +LL | assert_eq!(b"test\0", c"test".to_bytes_with_nul()); + | -^^^^^ + | | + | no rules expected this token in macro call + | help: missing comma here + | + = note: while trying to match sequence start + +error: aborting due to 2 previous errors + diff --git a/tests/ui/rfcs/rfc-3348-c-string-literals/gate.rs b/tests/ui/rfcs/rfc-3348-c-string-literals/gate.rs index b27da26ed23..ddd6d9a25da 100644 --- a/tests/ui/rfcs/rfc-3348-c-string-literals/gate.rs +++ b/tests/ui/rfcs/rfc-3348-c-string-literals/gate.rs @@ -1,4 +1,6 @@ // gate-test-c_str_literals +// known-bug: #113333 +// edition: 2021 macro_rules! m { ($t:tt) => {} @@ -6,8 +8,8 @@ macro_rules! m { fn main() { c"foo"; - //~^ ERROR: `c".."` literals are experimental + // FIXME(c_str_literals): This should be ``c".."` literals are experimental` m!(c"test"); - //~^ ERROR: `c".."` literals are experimental + // FIXME(c_str_literals): This should be ``c".."` literals are experimental` } diff --git a/tests/ui/rfcs/rfc-3348-c-string-literals/gate.stderr b/tests/ui/rfcs/rfc-3348-c-string-literals/gate.stderr index bc0c537aada..8de36ca4a6e 100644 --- a/tests/ui/rfcs/rfc-3348-c-string-literals/gate.stderr +++ b/tests/ui/rfcs/rfc-3348-c-string-literals/gate.stderr @@ -1,21 +1,32 @@ -error[E0658]: `c".."` literals are experimental - --> $DIR/gate.rs:8:5 +error: prefix `c` is unknown + --> $DIR/gate.rs:10:5 | LL | c"foo"; - | ^^^^^^ + | ^ unknown prefix | - = note: see issue #105723 for more information - = help: add `#![feature(c_str_literals)]` to the crate attributes to enable + = note: prefixed identifiers and literals are reserved since Rust 2021 +help: consider inserting whitespace here + | +LL | c "foo"; + | + -error[E0658]: `c".."` literals are experimental - --> $DIR/gate.rs:11:8 +error: prefix `c` is unknown + --> $DIR/gate.rs:13:8 | LL | m!(c"test"); - | ^^^^^^^ + | ^ unknown prefix | - = note: see issue #105723 for more information - = help: add `#![feature(c_str_literals)]` to the crate attributes to enable + = note: prefixed identifiers and literals are reserved since Rust 2021 +help: consider inserting whitespace here + | +LL | m!(c "test"); + | + -error: aborting due to 2 previous errors +error: expected one of `!`, `.`, `::`, `;`, `?`, `{`, `}`, or an operator, found `"foo"` + --> $DIR/gate.rs:10:6 + | +LL | c"foo"; + | ^^^^^ expected one of 8 possible tokens + +error: aborting due to 3 previous errors -For more information about this error, try `rustc --explain E0658`. diff --git a/tests/ui/rfcs/rfc-3348-c-string-literals/no-nuls.rs b/tests/ui/rfcs/rfc-3348-c-string-literals/no-nuls.rs index 7bc6097f124aabfded4a9e9791611cfe4fbf9f78..96945f125da71a9097f6f26c75a328f097448568 100644 GIT binary patch literal 760 zcmdPbSIExGFVE9WDowXiP&PC)Ha0fq($`l=P01|D%+Iq@FfuSQG<`$GxLZeedMMI^e z#Hyr3Q%h69)=r_i)|#u9i%U5=IW1ko&Cw^=RWlZp21-(kOR%K@w0KK~yFFP6DSVP4 megeld*mgw?a5~b2BqW3oBn_YoGbo{pfXzk|1lgepayC2KHOUmsPK3``XR b4h8Zs1u+!{1~}BnLe&&0;WA}1JJUx1Ypx{o diff --git a/tests/ui/rfcs/rfc-3348-c-string-literals/no-nuls.stderr b/tests/ui/rfcs/rfc-3348-c-string-literals/no-nuls.stderr index ff9006f6f97f1be7eed18d188e8c30ba2075743e..2226c7aa6a9ae9efc3b3cf7ce2270d90518dba9d 100644 GIT binary patch literal 4477 zcmYc-D#|aiQYa`&P0OrMNJvgl$ShVU&CAZqFVEvrP|(%2Q&4g74ARfb*Uc-fn=o^10`#)Ac(6F2QvX`E?5Rc*ec}Zm!!h1OHEP8Oi9fv z$xO>kEh<(>%u7+o$t+1NO3W!%NGwWKC`v6(EhyV&d)2(Oi3+L$jmEFEh@>(OIIk*$Sg@ME=WvHRmey!N(EVo>`VnTcPeOeagh-K zh6dO|ptRb+pmvCa0)|`34GCi`A;B;-0s+ODKyxX!P$(jzL@>0( z42B{llmLz!tYt!x0;)q5umu7UVPJ$M4A6?3!5RcqDi)1Li$!P+X>5p@A5c@-;7tlB zxt7elU~GiN|0AzhG{#apjcM3^ zauFXF7Z<01?i>q+g8bs*%%q%Dg_8X2)VyMNw;Ww1jT~-dX+>?9Cnn`X#w1coLB3Kj UGzSfalx60Z7At_q9E!QP0I=mZZ2$lO literal 674 zcmYc-D#|aiQphXK$x%qoNGwWBE=esaR>;g#a8@WTDay=CSIEgMNi9muDON}#|q zFHtBiEhxw@DoIV@Qc%#%h$~-%_-I^Dz-AQGUrlIP^jVZ@lmKz0D)ws z7y~71upo%5pr8;J$HhepyUnrLU0Q8mP>XJVTpX?3U}%8F5e#Vd)5iOT##pS5sW89@ veVX~*4ATKcN;o~An3P{s0!m~lrKt)f`3j~A1x2Z4nfax~3gFaH%*6!&x?#zt diff --git a/tests/ui/rfcs/rfc-3348-c-string-literals/non-ascii.rs b/tests/ui/rfcs/rfc-3348-c-string-literals/non-ascii.rs index 82e8e2090d7..066505c23df 100644 --- a/tests/ui/rfcs/rfc-3348-c-string-literals/non-ascii.rs +++ b/tests/ui/rfcs/rfc-3348-c-string-literals/non-ascii.rs @@ -1,4 +1,6 @@ -// run-pass +// FIXME(c_str_literals): This should be `run-pass` +// known-bug: #113333 +// edition: 2021 #![feature(c_str_literals)] diff --git a/tests/ui/rfcs/rfc-3348-c-string-literals/non-ascii.stderr b/tests/ui/rfcs/rfc-3348-c-string-literals/non-ascii.stderr new file mode 100644 index 00000000000..47361fb61d2 --- /dev/null +++ b/tests/ui/rfcs/rfc-3348-c-string-literals/non-ascii.stderr @@ -0,0 +1,38 @@ +error: prefix `c` is unknown + --> $DIR/non-ascii.rs:9:9 + | +LL | c"\xEF\x80🦀\u{1F980}".to_bytes_with_nul(), + | ^ unknown prefix + | + = note: prefixed identifiers and literals are reserved since Rust 2021 +help: consider inserting whitespace here + | +LL | c "\xEF\x80🦀\u{1F980}".to_bytes_with_nul(), + | + + +error: out of range hex escape + --> $DIR/non-ascii.rs:9:11 + | +LL | c"\xEF\x80🦀\u{1F980}".to_bytes_with_nul(), + | ^^^^ must be a character in the range [\x00-\x7f] + +error: out of range hex escape + --> $DIR/non-ascii.rs:9:15 + | +LL | c"\xEF\x80🦀\u{1F980}".to_bytes_with_nul(), + | ^^^^ must be a character in the range [\x00-\x7f] + +error: no rules expected the token `"\xEF\x80🦀\u{1F980}"` + --> $DIR/non-ascii.rs:9:10 + | +LL | c"\xEF\x80🦀\u{1F980}".to_bytes_with_nul(), + | -^^^^^^^^^^^^^^^^^^^^ + | | + | no rules expected this token in macro call + | help: missing comma here + | +note: while trying to match `,` + --> $SRC_DIR/core/src/macros/mod.rs:LL:COL + +error: aborting due to 4 previous errors +