Skip to content

Commit

Permalink
defatalize expand_test_or_bench
Browse files Browse the repository at this point in the history
  • Loading branch information
Centril committed Mar 24, 2020
1 parent 0e0f931 commit 3979964
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 10 deletions.
16 changes: 8 additions & 8 deletions src/librustc_builtin_macros/test.rs
Expand Up @@ -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 {
Expand Down
8 changes: 7 additions & 1 deletion src/test/ui/test-attrs/test-attr-non-associated-functions.rs
Expand Up @@ -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 {}
}
}
Expand Down
12 changes: 11 additions & 1 deletion src/test/ui/test-attrs/test-attr-non-associated-functions.stderr
Expand Up @@ -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

0 comments on commit 3979964

Please sign in to comment.