Skip to content

Commit 715d83f

Browse files
authored
Rollup merge of rust-lang#55923 - Zeegomo:master, r=estebank
reword #[test] attribute error on fn items fix of [rust-lang#55787](rust-lang#55787) Reworded error message from "#[test] attribute is only allowed on fn items" to "#[test] attribute is only allowed on non associated functions"
2 parents 5e2ff63 + 8e13e43 commit 715d83f

File tree

3 files changed

+40
-1
lines changed

3 files changed

+40
-1
lines changed

src/libsyntax_ext/test.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ pub fn expand_test_or_bench(
5353
if let Annotatable::Item(i) = item { i }
5454
else {
5555
cx.parse_sess.span_diagnostic.span_fatal(item.span(),
56-
"#[test] attribute is only allowed on fn items").raise();
56+
"#[test] attribute is only allowed on non associated functions").raise();
5757
};
5858

5959
if let ast::ItemKind::Mac(_) = item.node {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// Copyright 2018 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
// #[test] attribute is not allowed on associated functions or methods
12+
// reworded error message
13+
// compile-flags:--test
14+
15+
struct A {}
16+
17+
impl A {
18+
#[test]
19+
fn new() -> A { //~ ERROR #[test] attribute is only allowed on non associated functions
20+
A {}
21+
}
22+
}
23+
24+
#[test]
25+
fn test() {
26+
let _ = A::new();
27+
}
28+
29+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
error: #[test] attribute is only allowed on non associated functions
2+
--> $DIR/test-attr-non-associated-functions.rs:19:5
3+
|
4+
LL | / fn new() -> A { //~ ERROR #[test] attribute is only allowed on non associated functions
5+
LL | | A {}
6+
LL | | }
7+
| |_____^
8+
9+
error: aborting due to previous error
10+

0 commit comments

Comments
 (0)