summaryrefslogtreecommitdiffstats
path: root/tests/ui/rfcs/rfc-3348-c-string-literals
diff options
context:
space:
mode:
Diffstat (limited to 'tests/ui/rfcs/rfc-3348-c-string-literals')
-rw-r--r--tests/ui/rfcs/rfc-3348-c-string-literals/basic.rs9
-rw-r--r--tests/ui/rfcs/rfc-3348-c-string-literals/basic.stderr25
-rw-r--r--tests/ui/rfcs/rfc-3348-c-string-literals/edition-2015-2018-lexing.rs24
-rw-r--r--tests/ui/rfcs/rfc-3348-c-string-literals/gate.rs15
-rw-r--r--tests/ui/rfcs/rfc-3348-c-string-literals/gate.stderr32
-rw-r--r--tests/ui/rfcs/rfc-3348-c-string-literals/no-nuls.rsbin0 -> 760 bytes
-rw-r--r--tests/ui/rfcs/rfc-3348-c-string-literals/no-nuls.stderrbin0 -> 4477 bytes
-rw-r--r--tests/ui/rfcs/rfc-3348-c-string-literals/non-ascii.rs12
-rw-r--r--tests/ui/rfcs/rfc-3348-c-string-literals/non-ascii.stderr38
9 files changed, 155 insertions, 0 deletions
diff --git a/tests/ui/rfcs/rfc-3348-c-string-literals/basic.rs b/tests/ui/rfcs/rfc-3348-c-string-literals/basic.rs
new file mode 100644
index 000000000..3fc5fd481
--- /dev/null
+++ b/tests/ui/rfcs/rfc-3348-c-string-literals/basic.rs
@@ -0,0 +1,9 @@
+// FIXME(c_str_literals): This should be `run-pass`
+// known-bug: #113333
+// edition: 2021
+
+#![feature(c_str_literals)]
+
+fn main() {
+ assert_eq!(b"test\0", c"test".to_bytes_with_nul());
+}
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 000000000..571c319d8
--- /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/edition-2015-2018-lexing.rs b/tests/ui/rfcs/rfc-3348-c-string-literals/edition-2015-2018-lexing.rs
new file mode 100644
index 000000000..2a4cd6004
--- /dev/null
+++ b/tests/ui/rfcs/rfc-3348-c-string-literals/edition-2015-2018-lexing.rs
@@ -0,0 +1,24 @@
+// Regression test for issue #113235.
+
+// check-pass
+// revisions: edition2015 edition2018
+//[edition2015] edition: 2015
+//[edition2018] edition: 2018
+
+// Make sure that in pre-2021 editions we continue to parse the snippet
+// `c"hello"` as an identifier followed by a (normal) string literal and
+// allow the code below to compile.
+// Prefixes including `c` as used by C string literals are only reserved
+// in edition 2021 and onward.
+//
+// Consider checking out rust-2021/reserved-prefixes-migration.rs as well.
+
+macro_rules! parse {
+ (c $e:expr) => {
+ $e
+ };
+}
+
+fn main() {
+ let _: &'static str = parse!(c"hello");
+}
diff --git a/tests/ui/rfcs/rfc-3348-c-string-literals/gate.rs b/tests/ui/rfcs/rfc-3348-c-string-literals/gate.rs
new file mode 100644
index 000000000..ddd6d9a25
--- /dev/null
+++ b/tests/ui/rfcs/rfc-3348-c-string-literals/gate.rs
@@ -0,0 +1,15 @@
+// gate-test-c_str_literals
+// known-bug: #113333
+// edition: 2021
+
+macro_rules! m {
+ ($t:tt) => {}
+}
+
+fn main() {
+ c"foo";
+ // FIXME(c_str_literals): This should be ``c".."` literals are experimental`
+
+ m!(c"test");
+ // 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
new file mode 100644
index 000000000..8de36ca4a
--- /dev/null
+++ b/tests/ui/rfcs/rfc-3348-c-string-literals/gate.stderr
@@ -0,0 +1,32 @@
+error: prefix `c` is unknown
+ --> $DIR/gate.rs:10:5
+ |
+LL | c"foo";
+ | ^ unknown prefix
+ |
+ = note: prefixed identifiers and literals are reserved since Rust 2021
+help: consider inserting whitespace here
+ |
+LL | c "foo";
+ | +
+
+error: prefix `c` is unknown
+ --> $DIR/gate.rs:13:8
+ |
+LL | m!(c"test");
+ | ^ unknown prefix
+ |
+ = note: prefixed identifiers and literals are reserved since Rust 2021
+help: consider inserting whitespace here
+ |
+LL | m!(c "test");
+ | +
+
+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
+
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
new file mode 100644
index 000000000..96945f125
--- /dev/null
+++ b/tests/ui/rfcs/rfc-3348-c-string-literals/no-nuls.rs
Binary files differ
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
new file mode 100644
index 000000000..2226c7aa6
--- /dev/null
+++ b/tests/ui/rfcs/rfc-3348-c-string-literals/no-nuls.stderr
Binary files differ
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
new file mode 100644
index 000000000..066505c23
--- /dev/null
+++ b/tests/ui/rfcs/rfc-3348-c-string-literals/non-ascii.rs
@@ -0,0 +1,12 @@
+// FIXME(c_str_literals): This should be `run-pass`
+// known-bug: #113333
+// edition: 2021
+
+#![feature(c_str_literals)]
+
+fn main() {
+ assert_eq!(
+ c"\xEF\x80🦀\u{1F980}".to_bytes_with_nul(),
+ &[0xEF, 0x80, 0xF0, 0x9F, 0xA6, 0x80, 0xF0, 0x9F, 0xA6, 0x80, 0x00],
+ );
+}
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 000000000..47361fb61
--- /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
+