defatalize expand_test_or_bench

This commit is contained in:
Mazdak Farrokhzad 2020-03-17 13:27:56 +01:00
parent 0e0f9311da
commit 3979964200
3 changed files with 26 additions and 10 deletions

View File

@ -74,16 +74,16 @@ pub fn expand_test_or_bench(
return vec![];
}
let item = if let Annotatable::Item(i) = item {
i
} else {
cx.parse_sess
.span_diagnostic
.span_fatal(
item.span(),
let item = match item {
Annotatable::Item(i) => i,
other => {
cx.struct_span_err(
other.span(),
"`#[test]` attribute is only allowed on non associated functions",
)
.raise();
.emit();
return vec![other];
}
};
if let ast::ItemKind::MacCall(_) = item.kind {

View File

@ -6,7 +6,13 @@ struct A {}
impl A {
#[test]
fn new() -> A { //~ ERROR `#[test]` attribute is only allowed on non associated functions
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 {}
}
}

View File

@ -2,9 +2,19 @@ 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: aborting due to previous error
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