diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-17 12:19:13 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-17 12:19:13 +0000 |
commit | 218caa410aa38c29984be31a5229b9fa717560ee (patch) | |
tree | c54bd55eeb6e4c508940a30e94c0032fbd45d677 /tests/ui/include-macros | |
parent | Releasing progress-linux version 1.67.1+dfsg1-1~progress7.99u1. (diff) | |
download | rustc-218caa410aa38c29984be31a5229b9fa717560ee.tar.xz rustc-218caa410aa38c29984be31a5229b9fa717560ee.zip |
Merging upstream version 1.68.2+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'tests/ui/include-macros')
-rw-r--r-- | tests/ui/include-macros/auxiliary/same-file-in-two-crates-aux.rs | 4 | ||||
-rw-r--r-- | tests/ui/include-macros/data.bin | 2 | ||||
-rw-r--r-- | tests/ui/include-macros/file.txt | 0 | ||||
-rw-r--r-- | tests/ui/include-macros/mismatched-types.rs | 4 | ||||
-rw-r--r-- | tests/ui/include-macros/mismatched-types.stderr | 27 | ||||
-rw-r--r-- | tests/ui/include-macros/normalization.rs | 12 | ||||
-rw-r--r-- | tests/ui/include-macros/same-file-in-two-crates.rs | 21 |
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 000000000..7b680bce4 --- /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 000000000..ce4e0b831 --- /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 000000000..e69de29bb --- /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 000000000..83fa378a3 --- /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 000000000..a408877af --- /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 000000000..889f08e60 --- /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 000000000..f49efa2cf --- /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"); |