about summary refs log tree commit diff
path: root/tests/ui
diff options
context:
space:
mode:
authorDylan DPC <99973273+Dylan-DPC@users.noreply.github.com>2023-05-05 18:40:33 +0530
committerGitHub <noreply@github.com>2023-05-05 18:40:33 +0530
commit4891f02cff9a282df96b368b2f3f8151a78e9676 (patch)
treec9716f2b0c42263e0d44273ad5acd5bd5a338701 /tests/ui
parent3502e483213ad42468700b409ab4a4ecdd8ddf2c (diff)
parentd30c6681751b10a14265e09e5f74f39d2a32e641 (diff)
downloadrust-4891f02cff9a282df96b368b2f3f8151a78e9676.tar.gz
rust-4891f02cff9a282df96b368b2f3f8151a78e9676.zip
Rollup merge of #108801 - fee1-dead-contrib:c-str, r=compiler-errors
Implement RFC 3348, `c"foo"` literals

RFC: https://github.com/rust-lang/rfcs/pull/3348
Tracking issue: #105723
Diffstat (limited to 'tests/ui')
-rw-r--r--tests/ui/rfcs/rfc-3348-c-string-literals/basic.rs7
-rw-r--r--tests/ui/rfcs/rfc-3348-c-string-literals/gate.rs13
-rw-r--r--tests/ui/rfcs/rfc-3348-c-string-literals/gate.stderr21
-rw-r--r--tests/ui/rfcs/rfc-3348-c-string-literals/no-nuls.rsbin0 -> 565 bytes
-rw-r--r--tests/ui/rfcs/rfc-3348-c-string-literals/no-nuls.stderrbin0 -> 674 bytes
-rw-r--r--tests/ui/rfcs/rfc-3348-c-string-literals/non-ascii.rs10
6 files changed, 51 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 00000000000..e4b07ab8108
--- /dev/null
+++ b/tests/ui/rfcs/rfc-3348-c-string-literals/basic.rs
@@ -0,0 +1,7 @@
+// run-pass
+
+#![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/gate.rs b/tests/ui/rfcs/rfc-3348-c-string-literals/gate.rs
new file mode 100644
index 00000000000..b27da26ed23
--- /dev/null
+++ b/tests/ui/rfcs/rfc-3348-c-string-literals/gate.rs
@@ -0,0 +1,13 @@
+// gate-test-c_str_literals
+
+macro_rules! m {
+    ($t:tt) => {}
+}
+
+fn main() {
+    c"foo";
+    //~^ ERROR: `c".."` literals are experimental
+
+    m!(c"test");
+    //~^ ERROR: `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 00000000000..bc0c537aada
--- /dev/null
+++ b/tests/ui/rfcs/rfc-3348-c-string-literals/gate.stderr
@@ -0,0 +1,21 @@
+error[E0658]: `c".."` literals are experimental
+  --> $DIR/gate.rs:8:5
+   |
+LL |     c"foo";
+   |     ^^^^^^
+   |
+   = note: see issue #105723 <https://github.com/rust-lang/rust/issues/105723> for more information
+   = help: add `#![feature(c_str_literals)]` to the crate attributes to enable
+
+error[E0658]: `c".."` literals are experimental
+  --> $DIR/gate.rs:11:8
+   |
+LL |     m!(c"test");
+   |        ^^^^^^^
+   |
+   = note: see issue #105723 <https://github.com/rust-lang/rust/issues/105723> for more information
+   = help: add `#![feature(c_str_literals)]` to the crate attributes to enable
+
+error: aborting due to 2 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
new file mode 100644
index 00000000000..7bc6097f124
--- /dev/null
+++ b/tests/ui/rfcs/rfc-3348-c-string-literals/no-nuls.rs
Binary files differdiff --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 00000000000..ff9006f6f97
--- /dev/null
+++ b/tests/ui/rfcs/rfc-3348-c-string-literals/no-nuls.stderr
Binary files differdiff --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 00000000000..82e8e2090d7
--- /dev/null
+++ b/tests/ui/rfcs/rfc-3348-c-string-literals/non-ascii.rs
@@ -0,0 +1,10 @@
+// run-pass
+
+#![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],
+    );
+}