From 0671bdb1ebf61a2d8528738392e0a01c1436d49f Mon Sep 17 00:00:00 2001 From: giacomo Date: Sun, 11 Nov 2018 21:17:47 +0100 Subject: [PATCH 1/3] reword #[test] attribute error on fn items --- src/libsyntax_ext/test.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libsyntax_ext/test.rs b/src/libsyntax_ext/test.rs index be3485cfa7cc..b8a171b52adf 100644 --- a/src/libsyntax_ext/test.rs +++ b/src/libsyntax_ext/test.rs @@ -53,7 +53,7 @@ pub fn expand_test_or_bench( if let Annotatable::Item(i) = item { i } else { cx.parse_sess.span_diagnostic.span_fatal(item.span(), - "#[test] attribute is only allowed on fn items").raise(); + "#[test] attribute is only allowed on non associated functions").raise(); }; if let ast::ItemKind::Mac(_) = item.node { From 2b7c3fb725c4fe5ce968d62b3e07ebc74ffd82a3 Mon Sep 17 00:00:00 2001 From: giacomo Date: Sat, 17 Nov 2018 11:39:58 +0100 Subject: [PATCH 2/3] 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 000000000000..872dbd897707 --- /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 000000000000..780a119a6663 --- /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 + From 8e13e433c65f4755f43a527f8777a035f8b6a71b Mon Sep 17 00:00:00 2001 From: giacomo Date: Sat, 17 Nov 2018 12:28:04 +0100 Subject: [PATCH 3/3] tidy check fix --- .../ui/test-attr-non-associated-functions.rs | 24 +++++++++++++------ .../test-attr-non-associated-functions.stderr | 5 ++-- 2 files changed, 19 insertions(+), 10 deletions(-) diff --git a/src/test/ui/test-attr-non-associated-functions.rs b/src/test/ui/test-attr-non-associated-functions.rs index 872dbd897707..348bc6b4e982 100644 --- a/src/test/ui/test-attr-non-associated-functions.rs +++ b/src/test/ui/test-attr-non-associated-functions.rs @@ -1,19 +1,29 @@ +// Copyright 2018 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + // #[test] attribute is not allowed on associated functions or methods -// reworded error message +// 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 new() -> A { //~ ERROR #[test] attribute is only allowed on non associated functions + A {} + } } #[test] fn test() { - let _ = A::new(); + let _ = A::new(); } -fn main() {} \ No newline at end of file +fn main() {} diff --git a/src/test/ui/test-attr-non-associated-functions.stderr b/src/test/ui/test-attr-non-associated-functions.stderr index 780a119a6663..491fcc014311 100644 --- a/src/test/ui/test-attr-non-associated-functions.stderr +++ b/src/test/ui/test-attr-non-associated-functions.stderr @@ -1,8 +1,7 @@ error: #[test] attribute is only allowed on non associated functions - --> $DIR/test-attr-non-associated-functions.rs:9:2 + --> $DIR/test-attr-non-associated-functions.rs:19:5 | -LL | fn new() -> A { //~ ERROR #[test] attribute is only allowed on non associated functions - | _____^ +LL | / fn new() -> A { //~ ERROR #[test] attribute is only allowed on non associated functions LL | | A {} LL | | } | |_____^