Skip to content

Commit dedc455

Browse files
fmeaseMark-Simulacrum
authored andcommitted
Revert the lexing of c_str_literals
1 parent 892a91f commit dedc455

File tree

9 files changed

+96
-23
lines changed

9 files changed

+96
-23
lines changed

compiler/rustc_lexer/src/lib.rs

-7
Original file line numberDiff line numberDiff line change
@@ -367,13 +367,6 @@ impl Cursor<'_> {
367367
Some(|terminated| Byte { terminated }),
368368
),
369369

370-
// c-string literal, raw c-string literal or identifier.
371-
'c' => self.c_or_byte_string(
372-
|terminated| CStr { terminated },
373-
|n_hashes| RawCStr { n_hashes },
374-
None,
375-
),
376-
377370
// Identifier (this should be checked after other variant that can
378371
// start as identifier).
379372
c if is_id_start(c) => self.ident_or_unknown_prefix(),

tests/ui/rfcs/rfc-3348-c-string-literals/basic.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
// run-pass
1+
// FIXME(c_str_literals): This should be `run-pass`
2+
// known-bug: #113333
3+
// edition: 2021
24

35
#![feature(c_str_literals)]
46

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
error: prefix `c` is unknown
2+
--> $DIR/basic.rs:8:27
3+
|
4+
LL | assert_eq!(b"test\0", c"test".to_bytes_with_nul());
5+
| ^ unknown prefix
6+
|
7+
= note: prefixed identifiers and literals are reserved since Rust 2021
8+
help: consider inserting whitespace here
9+
|
10+
LL | assert_eq!(b"test\0", c "test".to_bytes_with_nul());
11+
| +
12+
13+
error: no rules expected the token `"test"`
14+
--> $DIR/basic.rs:8:28
15+
|
16+
LL | assert_eq!(b"test\0", c"test".to_bytes_with_nul());
17+
| -^^^^^
18+
| |
19+
| no rules expected this token in macro call
20+
| help: missing comma here
21+
|
22+
= note: while trying to match sequence start
23+
24+
error: aborting due to 2 previous errors
25+
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
// gate-test-c_str_literals
2+
// known-bug: #113333
3+
// edition: 2021
24

35
macro_rules! m {
46
($t:tt) => {}
57
}
68

79
fn main() {
810
c"foo";
9-
//~^ ERROR: `c".."` literals are experimental
11+
// FIXME(c_str_literals): This should be ``c".."` literals are experimental`
1012

1113
m!(c"test");
12-
//~^ ERROR: `c".."` literals are experimental
14+
// FIXME(c_str_literals): This should be ``c".."` literals are experimental`
1315
}

tests/ui/rfcs/rfc-3348-c-string-literals/gate.stderr

+23-12
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,32 @@
1-
error[E0658]: `c".."` literals are experimental
2-
--> $DIR/gate.rs:8:5
1+
error: prefix `c` is unknown
2+
--> $DIR/gate.rs:10:5
33
|
44
LL | c"foo";
5-
| ^^^^^^
5+
| ^ unknown prefix
66
|
7-
= note: see issue #105723 <https://github.com/rust-lang/rust/issues/105723> for more information
8-
= help: add `#![feature(c_str_literals)]` to the crate attributes to enable
7+
= note: prefixed identifiers and literals are reserved since Rust 2021
8+
help: consider inserting whitespace here
9+
|
10+
LL | c "foo";
11+
| +
912

10-
error[E0658]: `c".."` literals are experimental
11-
--> $DIR/gate.rs:11:8
13+
error: prefix `c` is unknown
14+
--> $DIR/gate.rs:13:8
1215
|
1316
LL | m!(c"test");
14-
| ^^^^^^^
17+
| ^ unknown prefix
18+
|
19+
= note: prefixed identifiers and literals are reserved since Rust 2021
20+
help: consider inserting whitespace here
1521
|
16-
= note: see issue #105723 <https://github.com/rust-lang/rust/issues/105723> for more information
17-
= help: add `#![feature(c_str_literals)]` to the crate attributes to enable
22+
LL | m!(c "test");
23+
| +
24+
25+
error: expected one of `!`, `.`, `::`, `;`, `?`, `{`, `}`, or an operator, found `"foo"`
26+
--> $DIR/gate.rs:10:6
27+
|
28+
LL | c"foo";
29+
| ^^^^^ expected one of 8 possible tokens
1830

19-
error: aborting due to 2 previous errors
31+
error: aborting due to 3 previous errors
2032

21-
For more information about this error, try `rustc --explain E0658`.
195 Bytes
Binary file not shown.
Binary file not shown.

tests/ui/rfcs/rfc-3348-c-string-literals/non-ascii.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
// run-pass
1+
// FIXME(c_str_literals): This should be `run-pass`
2+
// known-bug: #113333
3+
// edition: 2021
24

35
#![feature(c_str_literals)]
46

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
error: prefix `c` is unknown
2+
--> $DIR/non-ascii.rs:9:9
3+
|
4+
LL | c"\xEF\x80🦀\u{1F980}".to_bytes_with_nul(),
5+
| ^ unknown prefix
6+
|
7+
= note: prefixed identifiers and literals are reserved since Rust 2021
8+
help: consider inserting whitespace here
9+
|
10+
LL | c "\xEF\x80🦀\u{1F980}".to_bytes_with_nul(),
11+
| +
12+
13+
error: out of range hex escape
14+
--> $DIR/non-ascii.rs:9:11
15+
|
16+
LL | c"\xEF\x80🦀\u{1F980}".to_bytes_with_nul(),
17+
| ^^^^ must be a character in the range [\x00-\x7f]
18+
19+
error: out of range hex escape
20+
--> $DIR/non-ascii.rs:9:15
21+
|
22+
LL | c"\xEF\x80🦀\u{1F980}".to_bytes_with_nul(),
23+
| ^^^^ must be a character in the range [\x00-\x7f]
24+
25+
error: no rules expected the token `"\xEF\x80🦀\u{1F980}"`
26+
--> $DIR/non-ascii.rs:9:10
27+
|
28+
LL | c"\xEF\x80🦀\u{1F980}".to_bytes_with_nul(),
29+
| -^^^^^^^^^^^^^^^^^^^^
30+
| |
31+
| no rules expected this token in macro call
32+
| help: missing comma here
33+
|
34+
note: while trying to match `,`
35+
--> $SRC_DIR/core/src/macros/mod.rs:LL:COL
36+
37+
error: aborting due to 4 previous errors
38+

0 commit comments

Comments
 (0)