summaryrefslogtreecommitdiffstats
path: root/tests/ui/test-attrs
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 12:19:03 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 12:19:03 +0000
commit64d98f8ee037282c35007b64c2649055c56af1db (patch)
tree5492bcf97fce41ee1c0b1cc2add283f3e66cdab0 /tests/ui/test-attrs
parentAdding debian version 1.67.1+dfsg1-1. (diff)
downloadrustc-64d98f8ee037282c35007b64c2649055c56af1db.tar.xz
rustc-64d98f8ee037282c35007b64c2649055c56af1db.zip
Merging upstream version 1.68.2+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'tests/ui/test-attrs')
-rw-r--r--tests/ui/test-attrs/auxiliary/test_macro.rs4
-rw-r--r--tests/ui/test-attrs/decl-macro-test.rs22
-rw-r--r--tests/ui/test-attrs/inaccessible-test-modules.rs9
-rw-r--r--tests/ui/test-attrs/inaccessible-test-modules.stderr20
-rw-r--r--tests/ui/test-attrs/issue-16597-empty.rs5
-rw-r--r--tests/ui/test-attrs/issue-16597.rs10
-rw-r--r--tests/ui/test-attrs/issue-20823.rs5
-rw-r--r--tests/ui/test-attrs/issue-36768.rs9
-rw-r--r--tests/ui/test-attrs/issue-52557.rs30
-rw-r--r--tests/ui/test-attrs/issue-53675-a-test-called-panic.rs36
-rw-r--r--tests/ui/test-attrs/run-unexported-tests.rs12
-rw-r--r--tests/ui/test-attrs/test-attr-non-associated-functions.rs25
-rw-r--r--tests/ui/test-attrs/test-attr-non-associated-functions.stderr20
-rw-r--r--tests/ui/test-attrs/test-cant-be-shadowed.rs13
-rw-r--r--tests/ui/test-attrs/test-filter-multiple.rs17
-rw-r--r--tests/ui/test-attrs/test-filter-multiple.run.stdout7
-rw-r--r--tests/ui/test-attrs/test-fn-signature-verification-for-explicit-return-type.rs13
-rw-r--r--tests/ui/test-attrs/test-main-not-dead-attr.rs9
-rw-r--r--tests/ui/test-attrs/test-main-not-dead.rs6
-rw-r--r--tests/ui/test-attrs/test-on-not-fn.rs80
-rw-r--r--tests/ui/test-attrs/test-on-not-fn.stderr173
-rw-r--r--tests/ui/test-attrs/test-panic-abort-disabled.rs20
-rw-r--r--tests/ui/test-attrs/test-panic-abort-disabled.stderr4
-rw-r--r--tests/ui/test-attrs/test-panic-abort-nocapture.rs41
-rw-r--r--tests/ui/test-attrs/test-panic-abort-nocapture.run.stderr9
-rw-r--r--tests/ui/test-attrs/test-panic-abort-nocapture.run.stdout23
-rw-r--r--tests/ui/test-attrs/test-panic-abort.rs50
-rw-r--r--tests/ui/test-attrs/test-panic-abort.run.stdout30
-rw-r--r--tests/ui/test-attrs/test-panic-while-printing.rs24
-rw-r--r--tests/ui/test-attrs/test-passed-wasm.rs20
-rw-r--r--tests/ui/test-attrs/test-passed-wasm.run.stdout7
-rw-r--r--tests/ui/test-attrs/test-passed.rs21
-rw-r--r--tests/ui/test-attrs/test-passed.run.stdout7
-rw-r--r--tests/ui/test-attrs/test-runner-hides-buried-main.rs15
-rw-r--r--tests/ui/test-attrs/test-runner-hides-main.rs5
-rw-r--r--tests/ui/test-attrs/test-runner-hides-start.rs7
-rw-r--r--tests/ui/test-attrs/test-should-fail-good-message.rs14
-rw-r--r--tests/ui/test-attrs/test-should-panic-attr.rs36
-rw-r--r--tests/ui/test-attrs/test-should-panic-attr.stderr34
-rw-r--r--tests/ui/test-attrs/test-thread-capture.rs33
-rw-r--r--tests/ui/test-attrs/test-thread-capture.run.stdout21
-rw-r--r--tests/ui/test-attrs/test-thread-nocapture.rs33
-rw-r--r--tests/ui/test-attrs/test-thread-nocapture.run.stderr2
-rw-r--r--tests/ui/test-attrs/test-thread-nocapture.run.stdout20
-rw-r--r--tests/ui/test-attrs/test-type.rs27
-rw-r--r--tests/ui/test-attrs/test-type.run.stdout8
-rw-r--r--tests/ui/test-attrs/test-vs-cfg-test.rs9
-rw-r--r--tests/ui/test-attrs/test-warns-dead-code.rs7
-rw-r--r--tests/ui/test-attrs/test-warns-dead-code.stderr14
49 files changed, 1066 insertions, 0 deletions
diff --git a/tests/ui/test-attrs/auxiliary/test_macro.rs b/tests/ui/test-attrs/auxiliary/test_macro.rs
new file mode 100644
index 000000000..60a98ab6a
--- /dev/null
+++ b/tests/ui/test-attrs/auxiliary/test_macro.rs
@@ -0,0 +1,4 @@
+#[macro_export]
+macro_rules! test {
+ () => {};
+}
diff --git a/tests/ui/test-attrs/decl-macro-test.rs b/tests/ui/test-attrs/decl-macro-test.rs
new file mode 100644
index 000000000..fcbe9f49e
--- /dev/null
+++ b/tests/ui/test-attrs/decl-macro-test.rs
@@ -0,0 +1,22 @@
+// Check that declarative macros can declare tests
+
+// check-pass
+// compile-flags: --test
+
+#![feature(decl_macro)]
+
+macro create_test() {
+ #[test]
+ fn test() {}
+}
+
+macro create_module_test() {
+ mod x {
+ #[test]
+ fn test() {}
+ }
+}
+
+create_test!();
+create_test!();
+create_module_test!();
diff --git a/tests/ui/test-attrs/inaccessible-test-modules.rs b/tests/ui/test-attrs/inaccessible-test-modules.rs
new file mode 100644
index 000000000..f5b347937
--- /dev/null
+++ b/tests/ui/test-attrs/inaccessible-test-modules.rs
@@ -0,0 +1,9 @@
+// compile-flags:--test
+
+// the `--test` harness creates modules with these textual names, but
+// they should be inaccessible from normal code.
+use main as x; //~ ERROR unresolved import `main`
+use test as y; //~ ERROR unresolved import `test`
+
+#[test]
+fn baz() {}
diff --git a/tests/ui/test-attrs/inaccessible-test-modules.stderr b/tests/ui/test-attrs/inaccessible-test-modules.stderr
new file mode 100644
index 000000000..7635f579d
--- /dev/null
+++ b/tests/ui/test-attrs/inaccessible-test-modules.stderr
@@ -0,0 +1,20 @@
+error[E0432]: unresolved import `main`
+ --> $DIR/inaccessible-test-modules.rs:5:5
+ |
+LL | use main as x;
+ | ^^^^^^^^^ no `main` in the root
+
+error[E0432]: unresolved import `test`
+ --> $DIR/inaccessible-test-modules.rs:6:5
+ |
+LL | use test as y;
+ | ^^^^^^^^^ no `test` in the root
+ |
+help: consider importing this module instead
+ |
+LL | use test::test as y;
+ | ~~~~~~~~~~~~~~~
+
+error: aborting due to 2 previous errors
+
+For more information about this error, try `rustc --explain E0432`.
diff --git a/tests/ui/test-attrs/issue-16597-empty.rs b/tests/ui/test-attrs/issue-16597-empty.rs
new file mode 100644
index 000000000..2bdd08575
--- /dev/null
+++ b/tests/ui/test-attrs/issue-16597-empty.rs
@@ -0,0 +1,5 @@
+// run-pass
+// compile-flags:--test
+
+// This verifies that the test generation doesn't crash when we have
+// no tests - for more information, see PR #16892.
diff --git a/tests/ui/test-attrs/issue-16597.rs b/tests/ui/test-attrs/issue-16597.rs
new file mode 100644
index 000000000..35769bfc1
--- /dev/null
+++ b/tests/ui/test-attrs/issue-16597.rs
@@ -0,0 +1,10 @@
+// run-pass
+#![allow(unused_imports)]
+// compile-flags:--test
+
+mod tests {
+ use super::*;
+
+ #[test]
+ pub fn test(){}
+}
diff --git a/tests/ui/test-attrs/issue-20823.rs b/tests/ui/test-attrs/issue-20823.rs
new file mode 100644
index 000000000..9e209d5d3
--- /dev/null
+++ b/tests/ui/test-attrs/issue-20823.rs
@@ -0,0 +1,5 @@
+// run-pass
+// compile-flags: --test
+
+#[test]
+pub fn foo() {}
diff --git a/tests/ui/test-attrs/issue-36768.rs b/tests/ui/test-attrs/issue-36768.rs
new file mode 100644
index 000000000..f671cbc82
--- /dev/null
+++ b/tests/ui/test-attrs/issue-36768.rs
@@ -0,0 +1,9 @@
+// run-pass
+// compile-flags:--test
+#![deny(private_in_public)]
+
+#[test] fn foo() {}
+mod foo {}
+
+#[test] fn core() {}
+extern crate core;
diff --git a/tests/ui/test-attrs/issue-52557.rs b/tests/ui/test-attrs/issue-52557.rs
new file mode 100644
index 000000000..09f7a8c51
--- /dev/null
+++ b/tests/ui/test-attrs/issue-52557.rs
@@ -0,0 +1,30 @@
+// run-pass
+#![allow(unused_imports)]
+// This test checks for namespace pollution by private tests.
+// Tests used to marked as public causing name conflicts with normal
+// functions only in test builds.
+
+// compile-flags: --test
+
+mod a {
+ pub fn foo() -> bool {
+ true
+ }
+}
+
+mod b {
+ #[test]
+ fn foo() {
+ local_name(); // ensure the local name still works
+ }
+
+ #[test]
+ fn local_name() {}
+}
+
+use a::*;
+use b::*;
+
+pub fn conflict() {
+ let _: bool = foo();
+}
diff --git a/tests/ui/test-attrs/issue-53675-a-test-called-panic.rs b/tests/ui/test-attrs/issue-53675-a-test-called-panic.rs
new file mode 100644
index 000000000..e57303898
--- /dev/null
+++ b/tests/ui/test-attrs/issue-53675-a-test-called-panic.rs
@@ -0,0 +1,36 @@
+// rust-lang/rust#53675: At one point the compiler errored when a test
+// named `panic` used the `assert!` macro in expression position.
+
+// check-pass
+// compile-flags: --test
+
+mod in_expression_position {
+ #[test]
+ fn panic() {
+ assert!(true)
+ }
+}
+
+mod in_statement_position {
+ #[test]
+ fn panic() {
+ assert!(true);
+ }
+}
+
+mod what_if_we_use_panic_directly_in_expr {
+ #[test]
+ #[should_panic]
+ fn panic() {
+ panic!("in expr")
+ }
+}
+
+
+mod what_if_we_use_panic_directly_in_stmt {
+ #[test]
+ #[should_panic]
+ fn panic() {
+ panic!("in stmt");
+ }
+}
diff --git a/tests/ui/test-attrs/run-unexported-tests.rs b/tests/ui/test-attrs/run-unexported-tests.rs
new file mode 100644
index 000000000..f533a3ef8
--- /dev/null
+++ b/tests/ui/test-attrs/run-unexported-tests.rs
@@ -0,0 +1,12 @@
+// run-fail
+// compile-flags:--test
+// check-stdout
+
+mod m {
+ pub fn exported() {}
+
+ #[test]
+ fn unexported() {
+ panic!("ran an unexported test");
+ }
+}
diff --git a/tests/ui/test-attrs/test-attr-non-associated-functions.rs b/tests/ui/test-attrs/test-attr-non-associated-functions.rs
new file mode 100644
index 000000000..31e567c39
--- /dev/null
+++ b/tests/ui/test-attrs/test-attr-non-associated-functions.rs
@@ -0,0 +1,25 @@
+// #[test] attribute is not allowed on associated functions or methods
+// reworded error message
+// compile-flags:--test
+
+struct A {}
+
+impl A {
+ #[test]
+ fn new() -> A {
+ //~^ ERROR `#[test]` attribute is only allowed on non associated functions
+ A {}
+ }
+ #[test]
+ fn recovery_witness() -> A {
+ //~^ ERROR `#[test]` attribute is only allowed on non associated functions
+ A {}
+ }
+}
+
+#[test]
+fn test() {
+ let _ = A::new();
+}
+
+fn main() {}
diff --git a/tests/ui/test-attrs/test-attr-non-associated-functions.stderr b/tests/ui/test-attrs/test-attr-non-associated-functions.stderr
new file mode 100644
index 000000000..a81b8f398
--- /dev/null
+++ b/tests/ui/test-attrs/test-attr-non-associated-functions.stderr
@@ -0,0 +1,20 @@
+error: `#[test]` attribute is only allowed on non associated functions
+ --> $DIR/test-attr-non-associated-functions.rs:9:5
+ |
+LL | / fn new() -> A {
+LL | |
+LL | | A {}
+LL | | }
+ | |_____^
+
+error: `#[test]` attribute is only allowed on non associated functions
+ --> $DIR/test-attr-non-associated-functions.rs:14:5
+ |
+LL | / fn recovery_witness() -> A {
+LL | |
+LL | | A {}
+LL | | }
+ | |_____^
+
+error: aborting due to 2 previous errors
+
diff --git a/tests/ui/test-attrs/test-cant-be-shadowed.rs b/tests/ui/test-attrs/test-cant-be-shadowed.rs
new file mode 100644
index 000000000..831372d45
--- /dev/null
+++ b/tests/ui/test-attrs/test-cant-be-shadowed.rs
@@ -0,0 +1,13 @@
+// build-pass (FIXME(62277): could be check-pass?)
+// aux-build:test_macro.rs
+// compile-flags:--test
+
+#[macro_use] extern crate test_macro;
+
+#[test]
+fn foo(){}
+
+macro_rules! test { () => () }
+
+#[test]
+fn bar() {}
diff --git a/tests/ui/test-attrs/test-filter-multiple.rs b/tests/ui/test-attrs/test-filter-multiple.rs
new file mode 100644
index 000000000..04dd83b7f
--- /dev/null
+++ b/tests/ui/test-attrs/test-filter-multiple.rs
@@ -0,0 +1,17 @@
+// run-pass
+// compile-flags: --test
+// run-flags: --test-threads=1 test1 test2
+// check-run-results
+// normalize-stdout-test "finished in \d+\.\d+s" -> "finished in $$TIME"
+// ignore-emscripten no threads support
+
+#[test]
+fn test1() {}
+
+#[test]
+fn test2() {}
+
+#[test]
+fn test3() {
+ panic!("this should not run");
+}
diff --git a/tests/ui/test-attrs/test-filter-multiple.run.stdout b/tests/ui/test-attrs/test-filter-multiple.run.stdout
new file mode 100644
index 000000000..1aa684ed5
--- /dev/null
+++ b/tests/ui/test-attrs/test-filter-multiple.run.stdout
@@ -0,0 +1,7 @@
+
+running 2 tests
+test test1 ... ok
+test test2 ... ok
+
+test result: ok. 2 passed; 0 failed; 0 ignored; 0 measured; 1 filtered out; finished in $TIME
+
diff --git a/tests/ui/test-attrs/test-fn-signature-verification-for-explicit-return-type.rs b/tests/ui/test-attrs/test-fn-signature-verification-for-explicit-return-type.rs
new file mode 100644
index 000000000..585874e27
--- /dev/null
+++ b/tests/ui/test-attrs/test-fn-signature-verification-for-explicit-return-type.rs
@@ -0,0 +1,13 @@
+// run-pass
+// needs-unwind (#73509)
+
+#![feature(test)]
+
+// compile-flags: --test
+extern crate test;
+
+#[bench]
+pub fn bench_explicit_return_type(_: &mut ::test::Bencher) -> () {}
+
+#[test]
+pub fn test_explicit_return_type() -> () {}
diff --git a/tests/ui/test-attrs/test-main-not-dead-attr.rs b/tests/ui/test-attrs/test-main-not-dead-attr.rs
new file mode 100644
index 000000000..0b2a9a354
--- /dev/null
+++ b/tests/ui/test-attrs/test-main-not-dead-attr.rs
@@ -0,0 +1,9 @@
+// run-pass
+// compile-flags: --test
+
+#![feature(rustc_attrs)]
+
+#![deny(dead_code)]
+
+#[rustc_main]
+fn foo() { panic!(); }
diff --git a/tests/ui/test-attrs/test-main-not-dead.rs b/tests/ui/test-attrs/test-main-not-dead.rs
new file mode 100644
index 000000000..30a9c85e3
--- /dev/null
+++ b/tests/ui/test-attrs/test-main-not-dead.rs
@@ -0,0 +1,6 @@
+// run-pass
+// compile-flags: --test
+
+#![deny(dead_code)]
+
+fn main() { panic!(); }
diff --git a/tests/ui/test-attrs/test-on-not-fn.rs b/tests/ui/test-attrs/test-on-not-fn.rs
new file mode 100644
index 000000000..a460480af
--- /dev/null
+++ b/tests/ui/test-attrs/test-on-not-fn.rs
@@ -0,0 +1,80 @@
+// compile-flags: --test
+
+#[test] //~ ERROR: the `#[test]` attribute may only be used on a non-associated function
+mod test {}
+
+#[test] //~ ERROR: the `#[test]` attribute may only be used on a non-associated function
+mod loooooooooooooong_teeeeeeeeeest {
+ /*
+ this is a comment
+ this comment goes on for a very long time
+ this is to pad out the span for this module for a long time
+ Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut
+ labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco
+ laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in
+ voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat
+ non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
+ */
+}
+
+#[test] //~ ERROR: the `#[test]` attribute may only be used on a non-associated function
+extern "C" {}
+
+#[test] //~ ERROR: the `#[test]` attribute may only be used on a non-associated function
+trait Foo {}
+
+#[test] //~ ERROR: the `#[test]` attribute may only be used on a non-associated function
+impl Foo for i32 {}
+
+#[test] //~ ERROR: the `#[test]` attribute may only be used on a non-associated function
+const FOO: i32 = -1_i32;
+
+#[test] //~ ERROR: the `#[test]` attribute may only be used on a non-associated function
+static BAR: u64 = 10_000_u64;
+
+#[test] //~ ERROR: the `#[test]` attribute may only be used on a non-associated function
+enum MyUnit {
+ Unit,
+}
+
+#[test] //~ ERROR: the `#[test]` attribute may only be used on a non-associated function
+struct NewI32(i32);
+
+#[test] //~ ERROR: the `#[test]` attribute may only be used on a non-associated function
+union Spooky {
+ x: i32,
+ y: u32,
+}
+
+#[repr(C, align(64))]
+#[test] //~ ERROR: the `#[test]` attribute may only be used on a non-associated function
+#[derive(Copy, Clone, Debug)]
+struct MoreAttrs {
+ a: i32,
+ b: u64,
+}
+
+macro_rules! foo {
+ () => {};
+}
+
+#[test] //~ WARN: the `#[test]` attribute may only be used on a non-associated function
+foo!();
+
+// make sure it doesn't erroneously trigger on a real test
+#[test]
+fn real_test() {
+ assert_eq!(42_i32, 42_i32);
+}
+
+// make sure it works with cfg test
+#[cfg(test)]
+mod real_tests {
+ #[cfg(test)]
+ fn foo() {}
+
+ #[test]
+ fn bar() {
+ foo();
+ }
+}
diff --git a/tests/ui/test-attrs/test-on-not-fn.stderr b/tests/ui/test-attrs/test-on-not-fn.stderr
new file mode 100644
index 000000000..fc2c5f62b
--- /dev/null
+++ b/tests/ui/test-attrs/test-on-not-fn.stderr
@@ -0,0 +1,173 @@
+error: the `#[test]` attribute may only be used on a non-associated function
+ --> $DIR/test-on-not-fn.rs:3:1
+ |
+LL | #[test]
+ | ^^^^^^^ the `#[test]` macro causes a function to be run on a test and has no effect on non-functions
+LL | mod test {}
+ | ----------- expected a non-associated function, found a module
+ |
+help: replace with conditional compilation to make the item only exist when tests are being run
+ |
+LL | #[cfg(test)]
+ | ~~~~~~~~~~~~
+
+error: the `#[test]` attribute may only be used on a non-associated function
+ --> $DIR/test-on-not-fn.rs:6:1
+ |
+LL | #[test]
+ | ^^^^^^^ the `#[test]` macro causes a function to be run on a test and has no effect on non-functions
+LL | / mod loooooooooooooong_teeeeeeeeeest {
+LL | | /*
+LL | | this is a comment
+LL | | this comment goes on for a very long time
+... |
+LL | | */
+LL | | }
+ | |_- expected a non-associated function, found a module
+ |
+help: replace with conditional compilation to make the item only exist when tests are being run
+ |
+LL | #[cfg(test)]
+ | ~~~~~~~~~~~~
+
+error: the `#[test]` attribute may only be used on a non-associated function
+ --> $DIR/test-on-not-fn.rs:20:1
+ |
+LL | #[test]
+ | ^^^^^^^ the `#[test]` macro causes a function to be run on a test and has no effect on non-functions
+LL | extern "C" {}
+ | ------------- expected a non-associated function, found an extern block
+ |
+help: replace with conditional compilation to make the item only exist when tests are being run
+ |
+LL | #[cfg(test)]
+ | ~~~~~~~~~~~~
+
+error: the `#[test]` attribute may only be used on a non-associated function
+ --> $DIR/test-on-not-fn.rs:23:1
+ |
+LL | #[test]
+ | ^^^^^^^ the `#[test]` macro causes a function to be run on a test and has no effect on non-functions
+LL | trait Foo {}
+ | ------------ expected a non-associated function, found a trait
+ |
+help: replace with conditional compilation to make the item only exist when tests are being run
+ |
+LL | #[cfg(test)]
+ | ~~~~~~~~~~~~
+
+error: the `#[test]` attribute may only be used on a non-associated function
+ --> $DIR/test-on-not-fn.rs:26:1
+ |
+LL | #[test]
+ | ^^^^^^^ the `#[test]` macro causes a function to be run on a test and has no effect on non-functions
+LL | impl Foo for i32 {}
+ | ------------------- expected a non-associated function, found an implementation
+ |
+help: replace with conditional compilation to make the item only exist when tests are being run
+ |
+LL | #[cfg(test)]
+ | ~~~~~~~~~~~~
+
+error: the `#[test]` attribute may only be used on a non-associated function
+ --> $DIR/test-on-not-fn.rs:29:1
+ |
+LL | #[test]
+ | ^^^^^^^ the `#[test]` macro causes a function to be run on a test and has no effect on non-functions
+LL | const FOO: i32 = -1_i32;
+ | ------------------------ expected a non-associated function, found a constant item
+ |
+help: replace with conditional compilation to make the item only exist when tests are being run
+ |
+LL | #[cfg(test)]
+ | ~~~~~~~~~~~~
+
+error: the `#[test]` attribute may only be used on a non-associated function
+ --> $DIR/test-on-not-fn.rs:32:1
+ |
+LL | #[test]
+ | ^^^^^^^ the `#[test]` macro causes a function to be run on a test and has no effect on non-functions
+LL | static BAR: u64 = 10_000_u64;
+ | ----------------------------- expected a non-associated function, found a static item
+ |
+help: replace with conditional compilation to make the item only exist when tests are being run
+ |
+LL | #[cfg(test)]
+ | ~~~~~~~~~~~~
+
+error: the `#[test]` attribute may only be used on a non-associated function
+ --> $DIR/test-on-not-fn.rs:35:1
+ |
+LL | #[test]
+ | ^^^^^^^ the `#[test]` macro causes a function to be run on a test and has no effect on non-functions
+LL | / enum MyUnit {
+LL | | Unit,
+LL | | }
+ | |_- expected a non-associated function, found an enum
+ |
+help: replace with conditional compilation to make the item only exist when tests are being run
+ |
+LL | #[cfg(test)]
+ | ~~~~~~~~~~~~
+
+error: the `#[test]` attribute may only be used on a non-associated function
+ --> $DIR/test-on-not-fn.rs:40:1
+ |
+LL | #[test]
+ | ^^^^^^^ the `#[test]` macro causes a function to be run on a test and has no effect on non-functions
+LL | struct NewI32(i32);
+ | ------------------- expected a non-associated function, found a struct
+ |
+help: replace with conditional compilation to make the item only exist when tests are being run
+ |
+LL | #[cfg(test)]
+ | ~~~~~~~~~~~~
+
+error: the `#[test]` attribute may only be used on a non-associated function
+ --> $DIR/test-on-not-fn.rs:43:1
+ |
+LL | #[test]
+ | ^^^^^^^ the `#[test]` macro causes a function to be run on a test and has no effect on non-functions
+LL | / union Spooky {
+LL | | x: i32,
+LL | | y: u32,
+LL | | }
+ | |_- expected a non-associated function, found a union
+ |
+help: replace with conditional compilation to make the item only exist when tests are being run
+ |
+LL | #[cfg(test)]
+ | ~~~~~~~~~~~~
+
+error: the `#[test]` attribute may only be used on a non-associated function
+ --> $DIR/test-on-not-fn.rs:50:1
+ |
+LL | #[test]
+ | ^^^^^^^ the `#[test]` macro causes a function to be run on a test and has no effect on non-functions
+LL | #[derive(Copy, Clone, Debug)]
+LL | / struct MoreAttrs {
+LL | | a: i32,
+LL | | b: u64,
+LL | | }
+ | |_- expected a non-associated function, found a struct
+ |
+help: replace with conditional compilation to make the item only exist when tests are being run
+ |
+LL | #[cfg(test)]
+ | ~~~~~~~~~~~~
+
+warning: the `#[test]` attribute may only be used on a non-associated function
+ --> $DIR/test-on-not-fn.rs:61:1
+ |
+LL | #[test]
+ | ^^^^^^^ the `#[test]` macro causes a function to be run on a test and has no effect on non-functions
+LL | foo!();
+ | ------- expected a non-associated function, found an item macro invocation
+ |
+help: replace with conditional compilation to make the item only exist when tests are being run
+ |
+LL | #[cfg(test)]
+ | ~~~~~~~~~~~~
+
+error: aborting due to 11 previous errors; 1 warning emitted
+
diff --git a/tests/ui/test-attrs/test-panic-abort-disabled.rs b/tests/ui/test-attrs/test-panic-abort-disabled.rs
new file mode 100644
index 000000000..874dbdb42
--- /dev/null
+++ b/tests/ui/test-attrs/test-panic-abort-disabled.rs
@@ -0,0 +1,20 @@
+// error-pattern:building tests with panic=abort is not supported
+// no-prefer-dynamic
+// compile-flags: --test -Cpanic=abort -Zpanic-abort-tests=no
+// run-flags: --test-threads=1
+
+// ignore-wasm no panic or subprocess support
+// ignore-emscripten no panic or subprocess support
+
+#![cfg(test)]
+
+#[test]
+fn it_works() {
+ assert_eq!(1 + 1, 2);
+}
+
+#[test]
+#[should_panic]
+fn it_panics() {
+ assert_eq!(1 + 1, 4);
+}
diff --git a/tests/ui/test-attrs/test-panic-abort-disabled.stderr b/tests/ui/test-attrs/test-panic-abort-disabled.stderr
new file mode 100644
index 000000000..9c65c7360
--- /dev/null
+++ b/tests/ui/test-attrs/test-panic-abort-disabled.stderr
@@ -0,0 +1,4 @@
+error: building tests with panic=abort is not supported without `-Zpanic_abort_tests`
+
+error: aborting due to previous error
+
diff --git a/tests/ui/test-attrs/test-panic-abort-nocapture.rs b/tests/ui/test-attrs/test-panic-abort-nocapture.rs
new file mode 100644
index 000000000..af530cc1a
--- /dev/null
+++ b/tests/ui/test-attrs/test-panic-abort-nocapture.rs
@@ -0,0 +1,41 @@
+// no-prefer-dynamic
+// compile-flags: --test -Cpanic=abort -Zpanic_abort_tests
+// run-flags: --test-threads=1 --nocapture
+// run-fail
+// check-run-results
+// exec-env:RUST_BACKTRACE=0
+// normalize-stdout-test "finished in \d+\.\d+s" -> "finished in $$TIME"
+
+// ignore-wasm no panic or subprocess support
+// ignore-emscripten no panic or subprocess support
+// ignore-sgx no subprocess support
+
+#![cfg(test)]
+
+use std::io::Write;
+
+#[test]
+fn it_works() {
+ println!("about to succeed");
+ assert_eq!(1 + 1, 2);
+}
+
+#[test]
+#[should_panic]
+fn it_panics() {
+ println!("about to panic");
+ assert_eq!(1 + 1, 4);
+}
+
+#[test]
+fn it_fails() {
+ println!("about to fail");
+ assert_eq!(1 + 1, 4);
+}
+
+#[test]
+fn it_writes_to_stdio() {
+ println!("hello, world");
+ writeln!(std::io::stdout(), "testing123").unwrap();
+ writeln!(std::io::stderr(), "testing321").unwrap();
+}
diff --git a/tests/ui/test-attrs/test-panic-abort-nocapture.run.stderr b/tests/ui/test-attrs/test-panic-abort-nocapture.run.stderr
new file mode 100644
index 000000000..727e9691c
--- /dev/null
+++ b/tests/ui/test-attrs/test-panic-abort-nocapture.run.stderr
@@ -0,0 +1,9 @@
+thread 'main' panicked at 'assertion failed: `(left == right)`
+ left: `2`,
+ right: `4`', $DIR/test-panic-abort-nocapture.rs:33:5
+note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
+thread 'main' panicked at 'assertion failed: `(left == right)`
+ left: `2`,
+ right: `4`', $DIR/test-panic-abort-nocapture.rs:27:5
+note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
+testing321
diff --git a/tests/ui/test-attrs/test-panic-abort-nocapture.run.stdout b/tests/ui/test-attrs/test-panic-abort-nocapture.run.stdout
new file mode 100644
index 000000000..8a91732a7
--- /dev/null
+++ b/tests/ui/test-attrs/test-panic-abort-nocapture.run.stdout
@@ -0,0 +1,23 @@
+
+running 4 tests
+test it_fails ... about to fail
+FAILED
+test it_panics - should panic ... about to panic
+ok
+test it_works ... about to succeed
+ok
+test it_writes_to_stdio ... hello, world
+testing123
+ok
+
+failures:
+
+---- it_fails stdout ----
+---- it_fails stderr ----
+
+
+failures:
+ it_fails
+
+test result: FAILED. 3 passed; 1 failed; 0 ignored; 0 measured; 0 filtered out; finished in $TIME
+
diff --git a/tests/ui/test-attrs/test-panic-abort.rs b/tests/ui/test-attrs/test-panic-abort.rs
new file mode 100644
index 000000000..931b7993c
--- /dev/null
+++ b/tests/ui/test-attrs/test-panic-abort.rs
@@ -0,0 +1,50 @@
+// no-prefer-dynamic
+// compile-flags: --test -Cpanic=abort -Zpanic_abort_tests
+// run-flags: --test-threads=1
+// run-fail
+// check-run-results
+// exec-env:RUST_BACKTRACE=0
+// normalize-stdout-test "finished in \d+\.\d+s" -> "finished in $$TIME"
+
+// ignore-wasm no panic or subprocess support
+// ignore-emscripten no panic or subprocess support
+// ignore-sgx no subprocess support
+
+#![cfg(test)]
+
+use std::io::Write;
+use std::env;
+
+#[test]
+fn it_works() {
+ assert_eq!(1 + 1, 2);
+}
+
+#[test]
+#[should_panic]
+fn it_panics() {
+ assert_eq!(1 + 1, 4);
+}
+
+#[test]
+fn it_fails() {
+ println!("hello, world");
+ writeln!(std::io::stdout(), "testing123").unwrap();
+ writeln!(std::io::stderr(), "testing321").unwrap();
+ assert_eq!(1 + 1, 5);
+}
+
+#[test]
+fn it_exits() {
+ std::process::exit(123);
+}
+
+#[test]
+fn no_residual_environment() {
+ for (key, _) in env::vars() {
+ // Look for keys like __RUST_TEST_INVOKE.
+ if key.contains("TEST_INVOKE") {
+ panic!("shouldn't have '{}' in environment", key);
+ }
+ }
+}
diff --git a/tests/ui/test-attrs/test-panic-abort.run.stdout b/tests/ui/test-attrs/test-panic-abort.run.stdout
new file mode 100644
index 000000000..f608a8cdc
--- /dev/null
+++ b/tests/ui/test-attrs/test-panic-abort.run.stdout
@@ -0,0 +1,30 @@
+
+running 5 tests
+test it_exits ... FAILED
+test it_fails ... FAILED
+test it_panics - should panic ... ok
+test it_works ... ok
+test no_residual_environment ... ok
+
+failures:
+
+---- it_exits stdout ----
+---- it_exits stderr ----
+note: got unexpected return code 123
+---- it_fails stdout ----
+hello, world
+testing123
+---- it_fails stderr ----
+testing321
+thread 'main' panicked at 'assertion failed: `(left == right)`
+ left: `2`,
+ right: `5`', $DIR/test-panic-abort.rs:34:5
+note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
+
+
+failures:
+ it_exits
+ it_fails
+
+test result: FAILED. 3 passed; 2 failed; 0 ignored; 0 measured; 0 filtered out; finished in $TIME
+
diff --git a/tests/ui/test-attrs/test-panic-while-printing.rs b/tests/ui/test-attrs/test-panic-while-printing.rs
new file mode 100644
index 000000000..033c8beb4
--- /dev/null
+++ b/tests/ui/test-attrs/test-panic-while-printing.rs
@@ -0,0 +1,24 @@
+// compile-flags:--test
+// run-pass
+// needs-unwind
+
+use std::fmt;
+use std::fmt::{Display, Formatter};
+
+pub struct A(Vec<u32>);
+
+impl Display for A {
+ fn fmt(&self, _f: &mut Formatter<'_>) -> fmt::Result {
+ self.0[0];
+ Ok(())
+ }
+}
+
+#[test]
+fn main() {
+ let result = std::panic::catch_unwind(|| {
+ let a = A(vec![]);
+ eprintln!("{}", a);
+ });
+ assert!(result.is_err());
+}
diff --git a/tests/ui/test-attrs/test-passed-wasm.rs b/tests/ui/test-attrs/test-passed-wasm.rs
new file mode 100644
index 000000000..578aa4b17
--- /dev/null
+++ b/tests/ui/test-attrs/test-passed-wasm.rs
@@ -0,0 +1,20 @@
+// no-prefer-dynamic
+// compile-flags: --test
+// run-flags: --test-threads=1
+// run-pass
+// check-run-results
+// only-wasm32
+
+// Tests the output of the test harness with only passed tests.
+
+#![cfg(test)]
+
+#[test]
+fn it_works() {
+ assert_eq!(1 + 1, 2);
+}
+
+#[test]
+fn it_works_too() {
+ assert_eq!(1 * 0, 0);
+}
diff --git a/tests/ui/test-attrs/test-passed-wasm.run.stdout b/tests/ui/test-attrs/test-passed-wasm.run.stdout
new file mode 100644
index 000000000..c3005a779
--- /dev/null
+++ b/tests/ui/test-attrs/test-passed-wasm.run.stdout
@@ -0,0 +1,7 @@
+
+running 2 tests
+test it_works ... ok
+test it_works_too ... ok
+
+test result: ok. 2 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out
+
diff --git a/tests/ui/test-attrs/test-passed.rs b/tests/ui/test-attrs/test-passed.rs
new file mode 100644
index 000000000..f65f00030
--- /dev/null
+++ b/tests/ui/test-attrs/test-passed.rs
@@ -0,0 +1,21 @@
+// no-prefer-dynamic
+// compile-flags: --test
+// run-flags: --test-threads=1
+// run-pass
+// check-run-results
+// normalize-stdout-test "finished in \d+\.\d+s" -> "finished in $$TIME"
+// ignore-wasm32 no support for `Instant`
+
+// Tests the output of the test harness with only passed tests.
+
+#![cfg(test)]
+
+#[test]
+fn it_works() {
+ assert_eq!(1 + 1, 2);
+}
+
+#[test]
+fn it_works_too() {
+ assert_eq!(1 * 0, 0);
+}
diff --git a/tests/ui/test-attrs/test-passed.run.stdout b/tests/ui/test-attrs/test-passed.run.stdout
new file mode 100644
index 000000000..17f70d607
--- /dev/null
+++ b/tests/ui/test-attrs/test-passed.run.stdout
@@ -0,0 +1,7 @@
+
+running 2 tests
+test it_works ... ok
+test it_works_too ... ok
+
+test result: ok. 2 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in $TIME
+
diff --git a/tests/ui/test-attrs/test-runner-hides-buried-main.rs b/tests/ui/test-attrs/test-runner-hides-buried-main.rs
new file mode 100644
index 000000000..346aa868e
--- /dev/null
+++ b/tests/ui/test-attrs/test-runner-hides-buried-main.rs
@@ -0,0 +1,15 @@
+// run-pass
+// compile-flags: --test
+
+#![feature(rustc_attrs)]
+
+#![allow(dead_code)]
+
+mod a {
+ fn b() {
+ (|| {
+ #[rustc_main]
+ fn c() { panic!(); }
+ })();
+ }
+}
diff --git a/tests/ui/test-attrs/test-runner-hides-main.rs b/tests/ui/test-attrs/test-runner-hides-main.rs
new file mode 100644
index 000000000..0de1d64f0
--- /dev/null
+++ b/tests/ui/test-attrs/test-runner-hides-main.rs
@@ -0,0 +1,5 @@
+// run-pass
+// compile-flags:--test
+// Building as a test runner means that a synthetic main will be run,
+// not ours
+pub fn main() { panic!(); }
diff --git a/tests/ui/test-attrs/test-runner-hides-start.rs b/tests/ui/test-attrs/test-runner-hides-start.rs
new file mode 100644
index 000000000..56212bb6f
--- /dev/null
+++ b/tests/ui/test-attrs/test-runner-hides-start.rs
@@ -0,0 +1,7 @@
+// run-pass
+// compile-flags: --test
+
+#![feature(start)]
+
+#[start]
+fn start(_: isize, _: *const *const u8) -> isize { panic!(); }
diff --git a/tests/ui/test-attrs/test-should-fail-good-message.rs b/tests/ui/test-attrs/test-should-fail-good-message.rs
new file mode 100644
index 000000000..83519c452
--- /dev/null
+++ b/tests/ui/test-attrs/test-should-fail-good-message.rs
@@ -0,0 +1,14 @@
+// run-pass
+// needs-unwind
+// compile-flags: --test
+#[test]
+#[should_panic(expected = "foo")]
+pub fn test_foo() {
+ panic!("foo bar")
+}
+
+#[test]
+#[should_panic(expected = "foo")]
+pub fn test_foo_dynamic() {
+ panic!("{} bar", "foo")
+}
diff --git a/tests/ui/test-attrs/test-should-panic-attr.rs b/tests/ui/test-attrs/test-should-panic-attr.rs
new file mode 100644
index 000000000..b71878406
--- /dev/null
+++ b/tests/ui/test-attrs/test-should-panic-attr.rs
@@ -0,0 +1,36 @@
+// check-pass
+// compile-flags: --test
+
+#[test]
+#[should_panic = "foo"]
+fn test1() {
+ panic!();
+}
+
+#[test]
+#[should_panic(expected)]
+//~^ WARN: argument must be of the form:
+fn test2() {
+ panic!();
+}
+
+#[test]
+#[should_panic(expect)]
+//~^ WARN: argument must be of the form:
+fn test3() {
+ panic!();
+}
+
+#[test]
+#[should_panic(expected(foo, bar))]
+//~^ WARN: argument must be of the form:
+fn test4() {
+ panic!();
+}
+
+#[test]
+#[should_panic(expected = "foo", bar)]
+//~^ WARN: argument must be of the form:
+fn test5() {
+ panic!();
+}
diff --git a/tests/ui/test-attrs/test-should-panic-attr.stderr b/tests/ui/test-attrs/test-should-panic-attr.stderr
new file mode 100644
index 000000000..492d1d5e0
--- /dev/null
+++ b/tests/ui/test-attrs/test-should-panic-attr.stderr
@@ -0,0 +1,34 @@
+warning: argument must be of the form: `expected = "error message"`
+ --> $DIR/test-should-panic-attr.rs:11:1
+ |
+LL | #[should_panic(expected)]
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^
+ |
+ = note: errors in this attribute were erroneously allowed and will become a hard error in a future release
+
+warning: argument must be of the form: `expected = "error message"`
+ --> $DIR/test-should-panic-attr.rs:18:1
+ |
+LL | #[should_panic(expect)]
+ | ^^^^^^^^^^^^^^^^^^^^^^^
+ |
+ = note: errors in this attribute were erroneously allowed and will become a hard error in a future release
+
+warning: argument must be of the form: `expected = "error message"`
+ --> $DIR/test-should-panic-attr.rs:25:1
+ |
+LL | #[should_panic(expected(foo, bar))]
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ |
+ = note: errors in this attribute were erroneously allowed and will become a hard error in a future release
+
+warning: argument must be of the form: `expected = "error message"`
+ --> $DIR/test-should-panic-attr.rs:32:1
+ |
+LL | #[should_panic(expected = "foo", bar)]
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ |
+ = note: errors in this attribute were erroneously allowed and will become a hard error in a future release
+
+warning: 4 warnings emitted
+
diff --git a/tests/ui/test-attrs/test-thread-capture.rs b/tests/ui/test-attrs/test-thread-capture.rs
new file mode 100644
index 000000000..53acca341
--- /dev/null
+++ b/tests/ui/test-attrs/test-thread-capture.rs
@@ -0,0 +1,33 @@
+// compile-flags: --test
+// run-fail
+// run-flags: --test-threads=1
+// check-run-results
+// exec-env:RUST_BACKTRACE=0
+// normalize-stdout-test "finished in \d+\.\d+s" -> "finished in $$TIME"
+// ignore-emscripten no threads support
+// needs-unwind
+
+#[test]
+fn thready_pass() {
+ println!("fee");
+ std::thread::spawn(|| {
+ println!("fie");
+ println!("foe");
+ })
+ .join()
+ .unwrap();
+ println!("fum");
+}
+
+#[test]
+fn thready_fail() {
+ println!("fee");
+ std::thread::spawn(|| {
+ println!("fie");
+ println!("foe");
+ })
+ .join()
+ .unwrap();
+ println!("fum");
+ panic!();
+}
diff --git a/tests/ui/test-attrs/test-thread-capture.run.stdout b/tests/ui/test-attrs/test-thread-capture.run.stdout
new file mode 100644
index 000000000..513c8cf2a
--- /dev/null
+++ b/tests/ui/test-attrs/test-thread-capture.run.stdout
@@ -0,0 +1,21 @@
+
+running 2 tests
+test thready_fail ... FAILED
+test thready_pass ... ok
+
+failures:
+
+---- thready_fail stdout ----
+fee
+fie
+foe
+fum
+thread 'thready_fail' panicked at 'explicit panic', $DIR/test-thread-capture.rs:32:5
+note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
+
+
+failures:
+ thready_fail
+
+test result: FAILED. 1 passed; 1 failed; 0 ignored; 0 measured; 0 filtered out; finished in $TIME
+
diff --git a/tests/ui/test-attrs/test-thread-nocapture.rs b/tests/ui/test-attrs/test-thread-nocapture.rs
new file mode 100644
index 000000000..2b57eb8aa
--- /dev/null
+++ b/tests/ui/test-attrs/test-thread-nocapture.rs
@@ -0,0 +1,33 @@
+// compile-flags: --test
+// run-fail
+// run-flags: --test-threads=1 --nocapture
+// check-run-results
+// exec-env:RUST_BACKTRACE=0
+// normalize-stdout-test "finished in \d+\.\d+s" -> "finished in $$TIME"
+// ignore-emscripten no threads support
+// needs-unwind
+
+#[test]
+fn thready_pass() {
+ println!("fee");
+ std::thread::spawn(|| {
+ println!("fie");
+ println!("foe");
+ })
+ .join()
+ .unwrap();
+ println!("fum");
+}
+
+#[test]
+fn thready_fail() {
+ println!("fee");
+ std::thread::spawn(|| {
+ println!("fie");
+ println!("foe");
+ })
+ .join()
+ .unwrap();
+ println!("fum");
+ panic!();
+}
diff --git a/tests/ui/test-attrs/test-thread-nocapture.run.stderr b/tests/ui/test-attrs/test-thread-nocapture.run.stderr
new file mode 100644
index 000000000..8c905d1af
--- /dev/null
+++ b/tests/ui/test-attrs/test-thread-nocapture.run.stderr
@@ -0,0 +1,2 @@
+thread 'thready_fail' panicked at 'explicit panic', $DIR/test-thread-nocapture.rs:32:5
+note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
diff --git a/tests/ui/test-attrs/test-thread-nocapture.run.stdout b/tests/ui/test-attrs/test-thread-nocapture.run.stdout
new file mode 100644
index 000000000..9d2da5082
--- /dev/null
+++ b/tests/ui/test-attrs/test-thread-nocapture.run.stdout
@@ -0,0 +1,20 @@
+
+running 2 tests
+test thready_fail ... fee
+fie
+foe
+fum
+FAILED
+test thready_pass ... fee
+fie
+foe
+fum
+ok
+
+failures:
+
+failures:
+ thready_fail
+
+test result: FAILED. 1 passed; 1 failed; 0 ignored; 0 measured; 0 filtered out; finished in $TIME
+
diff --git a/tests/ui/test-attrs/test-type.rs b/tests/ui/test-attrs/test-type.rs
new file mode 100644
index 000000000..f99e476ea
--- /dev/null
+++ b/tests/ui/test-attrs/test-type.rs
@@ -0,0 +1,27 @@
+// compile-flags: --test
+// run-flags: --test-threads=1
+// check-run-results
+// normalize-stdout-test "finished in \d+\.\d+s" -> "finished in $$TIME"
+// ignore-emscripten no threads support
+// run-pass
+
+#[test]
+fn test_ok() {
+ let _a = true;
+}
+
+#[test]
+#[should_panic]
+fn test_panic() {
+ panic!();
+}
+
+#[test]
+#[ignore = "msg"]
+fn test_no_run() {
+ loop {
+ println!("Hello, world");
+ }
+}
+
+fn main() {}
diff --git a/tests/ui/test-attrs/test-type.run.stdout b/tests/ui/test-attrs/test-type.run.stdout
new file mode 100644
index 000000000..143c13a36
--- /dev/null
+++ b/tests/ui/test-attrs/test-type.run.stdout
@@ -0,0 +1,8 @@
+
+running 3 tests
+test test_no_run ... ignored, msg
+test test_ok ... ok
+test test_panic - should panic ... ok
+
+test result: ok. 2 passed; 0 failed; 1 ignored; 0 measured; 0 filtered out; finished in $TIME
+
diff --git a/tests/ui/test-attrs/test-vs-cfg-test.rs b/tests/ui/test-attrs/test-vs-cfg-test.rs
new file mode 100644
index 000000000..cd1cd33c2
--- /dev/null
+++ b/tests/ui/test-attrs/test-vs-cfg-test.rs
@@ -0,0 +1,9 @@
+// run-pass
+// compile-flags: --cfg test
+
+// Make sure `--cfg test` does not inject test harness
+
+#[test]
+fn test() { panic!(); }
+
+fn main() {}
diff --git a/tests/ui/test-attrs/test-warns-dead-code.rs b/tests/ui/test-attrs/test-warns-dead-code.rs
new file mode 100644
index 000000000..4190885b6
--- /dev/null
+++ b/tests/ui/test-attrs/test-warns-dead-code.rs
@@ -0,0 +1,7 @@
+// compile-flags: --test
+
+#![deny(dead_code)]
+
+fn dead() {} //~ error: function `dead` is never used
+
+fn main() {}
diff --git a/tests/ui/test-attrs/test-warns-dead-code.stderr b/tests/ui/test-attrs/test-warns-dead-code.stderr
new file mode 100644
index 000000000..6c0f28841
--- /dev/null
+++ b/tests/ui/test-attrs/test-warns-dead-code.stderr
@@ -0,0 +1,14 @@
+error: function `dead` is never used
+ --> $DIR/test-warns-dead-code.rs:5:4
+ |
+LL | fn dead() {}
+ | ^^^^
+ |
+note: the lint level is defined here
+ --> $DIR/test-warns-dead-code.rs:3:9
+ |
+LL | #![deny(dead_code)]
+ | ^^^^^^^^^
+
+error: aborting due to previous error
+