From 2b7c3fb725c4fe5ce968d62b3e07ebc74ffd82a3 Mon Sep 17 00:00:00 2001 From: giacomo Date: Sat, 17 Nov 2018 11:39:58 +0100 Subject: [PATCH] add test for #[test] attribute only allowed on non associated functions --- .../ui/test-attr-non-associated-functions.rs | 19 +++++++++++++++++++ .../test-attr-non-associated-functions.stderr | 11 +++++++++++ 2 files changed, 30 insertions(+) create mode 100644 src/test/ui/test-attr-non-associated-functions.rs create mode 100644 src/test/ui/test-attr-non-associated-functions.stderr diff --git a/src/test/ui/test-attr-non-associated-functions.rs b/src/test/ui/test-attr-non-associated-functions.rs new file mode 100644 index 00000000000..872dbd89770 --- /dev/null +++ b/src/test/ui/test-attr-non-associated-functions.rs @@ -0,0 +1,19 @@ +// #[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 test() { + let _ = A::new(); +} + +fn main() {} \ No newline at end of file diff --git a/src/test/ui/test-attr-non-associated-functions.stderr b/src/test/ui/test-attr-non-associated-functions.stderr new file mode 100644 index 00000000000..780a119a666 --- /dev/null +++ b/src/test/ui/test-attr-non-associated-functions.stderr @@ -0,0 +1,11 @@ +error: #[test] attribute is only allowed on non associated functions + --> $DIR/test-attr-non-associated-functions.rs:9:2 + | +LL | fn new() -> A { //~ ERROR #[test] attribute is only allowed on non associated functions + | _____^ +LL | | A {} +LL | | } + | |_____^ + +error: aborting due to previous error +