1
Fork 0

Rollup merge of #109301 - Ezrashaw:fix-ctf-ice, r=Nilstrieb

fix: fix ICE in `custom-test-frameworks` feature

Fixes #107454

Simple fix to emit error instead of ICEing. At some point, all the code in `tests.rs` should be refactored, there is a bit of duplication (this PR's code is repeated five times over lol).

r? `@Nilstrieb` (active on the linked issue?)
This commit is contained in:
Matthias Krüger 2023-03-20 07:10:31 +01:00 committed by GitHub
commit 5d3f460708
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 49 additions and 2 deletions

View file

@ -33,7 +33,23 @@ pub fn expand_test_case(
}
let sp = ecx.with_def_site_ctxt(attr_sp);
let mut item = anno_item.expect_item();
let (mut item, is_stmt) = match anno_item {
Annotatable::Item(item) => (item, false),
Annotatable::Stmt(stmt) if let ast::StmtKind::Item(_) = stmt.kind => if let ast::StmtKind::Item(i) = stmt.into_inner().kind {
(i, true)
} else {
unreachable!()
},
_ => {
ecx.struct_span_err(
anno_item.span(),
"`#[test_case]` attribute is only allowed on items",
)
.emit();
return vec![];
}
};
item = item.map(|mut item| {
let test_path_symbol = Symbol::intern(&item_path(
// skip the name of the root module
@ -50,7 +66,13 @@ pub fn expand_test_case(
item
});
return vec![Annotatable::Item(item)];
let ret = if is_stmt {
Annotatable::Stmt(P(ecx.stmt_item(item.span, item)))
} else {
Annotatable::Item(item)
};
vec![ret]
}
pub fn expand_test(