about summary refs log tree commit diff
path: root/tests/ui/include-macros
diff options
context:
space:
mode:
Diffstat (limited to 'tests/ui/include-macros')
-rw-r--r--tests/ui/include-macros/auxiliary/same-file-in-two-crates-aux.rs4
-rw-r--r--tests/ui/include-macros/data.bin2
-rw-r--r--tests/ui/include-macros/file.txt0
-rw-r--r--tests/ui/include-macros/mismatched-types.rs4
-rw-r--r--tests/ui/include-macros/mismatched-types.stderr27
-rw-r--r--tests/ui/include-macros/normalization.rs12
-rw-r--r--tests/ui/include-macros/same-file-in-two-crates.rs21
7 files changed, 70 insertions, 0 deletions
diff --git a/tests/ui/include-macros/auxiliary/same-file-in-two-crates-aux.rs b/tests/ui/include-macros/auxiliary/same-file-in-two-crates-aux.rs
new file mode 100644
index 00000000000..7b680bce49e
--- /dev/null
+++ b/tests/ui/include-macros/auxiliary/same-file-in-two-crates-aux.rs
@@ -0,0 +1,4 @@
+#[inline]
+pub fn some_function() -> u32 {
+    1
+}
diff --git a/tests/ui/include-macros/data.bin b/tests/ui/include-macros/data.bin
new file mode 100644
index 00000000000..ce4e0b8311a
--- /dev/null
+++ b/tests/ui/include-macros/data.bin
@@ -0,0 +1,2 @@
+This file starts with BOM.

+Lines are separated by \r\n.

diff --git a/tests/ui/include-macros/file.txt b/tests/ui/include-macros/file.txt
new file mode 100644
index 00000000000..e69de29bb2d
--- /dev/null
+++ b/tests/ui/include-macros/file.txt
diff --git a/tests/ui/include-macros/mismatched-types.rs b/tests/ui/include-macros/mismatched-types.rs
new file mode 100644
index 00000000000..83fa378a3ae
--- /dev/null
+++ b/tests/ui/include-macros/mismatched-types.rs
@@ -0,0 +1,4 @@
+fn main() {
+    let b: &[u8] = include_str!("file.txt");    //~ ERROR mismatched types
+    let s: &str = include_bytes!("file.txt");   //~ ERROR mismatched types
+}
diff --git a/tests/ui/include-macros/mismatched-types.stderr b/tests/ui/include-macros/mismatched-types.stderr
new file mode 100644
index 00000000000..a408877afb6
--- /dev/null
+++ b/tests/ui/include-macros/mismatched-types.stderr
@@ -0,0 +1,27 @@
+error[E0308]: mismatched types
+  --> $DIR/mismatched-types.rs:2:20
+   |
+LL |     let b: &[u8] = include_str!("file.txt");
+   |            -----   ^^^^^^^^^^^^^^^^^^^^^^^^ expected slice `[u8]`, found `str`
+   |            |
+   |            expected due to this
+   |
+   = note: expected reference `&[u8]`
+              found reference `&'static str`
+   = note: this error originates in the macro `include_str` (in Nightly builds, run with -Z macro-backtrace for more info)
+
+error[E0308]: mismatched types
+  --> $DIR/mismatched-types.rs:3:19
+   |
+LL |     let s: &str = include_bytes!("file.txt");
+   |            ----   ^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `str`, found array `[u8; 0]`
+   |            |
+   |            expected due to this
+   |
+   = note: expected reference `&str`
+              found reference `&'static [u8; 0]`
+   = note: this error originates in the macro `include_bytes` (in Nightly builds, run with -Z macro-backtrace for more info)
+
+error: aborting due to 2 previous errors
+
+For more information about this error, try `rustc --explain E0308`.
diff --git a/tests/ui/include-macros/normalization.rs b/tests/ui/include-macros/normalization.rs
new file mode 100644
index 00000000000..889f08e606e
--- /dev/null
+++ b/tests/ui/include-macros/normalization.rs
@@ -0,0 +1,12 @@
+// run-pass
+
+fn main() {
+    assert_eq!(
+        &include_bytes!("data.bin")[..],
+        &b"\xEF\xBB\xBFThis file starts with BOM.\r\nLines are separated by \\r\\n.\r\n"[..],
+    );
+    assert_eq!(
+        include_str!("data.bin"),
+        "\u{FEFF}This file starts with BOM.\r\nLines are separated by \\r\\n.\r\n",
+    );
+}
diff --git a/tests/ui/include-macros/same-file-in-two-crates.rs b/tests/ui/include-macros/same-file-in-two-crates.rs
new file mode 100644
index 00000000000..f49efa2cf8a
--- /dev/null
+++ b/tests/ui/include-macros/same-file-in-two-crates.rs
@@ -0,0 +1,21 @@
+// This test makes sure that the compiler can handle the same source file to be
+// part of the local crate *and* an upstream crate. This can happen, for example,
+// when there is some auto-generated code that is part of both a library and an
+// accompanying integration test.
+//
+// The test uses include!() to include a source file that is also part of
+// an upstream crate.
+//
+// This is a regression test for https://github.com/rust-lang/rust/issues/85955.
+
+// check-pass
+// compile-flags: --crate-type=rlib
+// aux-build:same-file-in-two-crates-aux.rs
+extern crate same_file_in_two_crates_aux;
+
+pub fn foo() -> u32 {
+    same_file_in_two_crates_aux::some_function() +
+    some_function()
+}
+
+include!("./auxiliary/same-file-in-two-crates-aux.rs");