mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-25 08:13:41 +00:00
fix: fix ICE in custom-test-frameworks
feature
This commit is contained in:
parent
85123d2504
commit
c05bebcd67
@ -33,7 +33,23 @@ pub fn expand_test_case(
|
|||||||
}
|
}
|
||||||
|
|
||||||
let sp = ecx.with_def_site_ctxt(attr_sp);
|
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| {
|
item = item.map(|mut item| {
|
||||||
let test_path_symbol = Symbol::intern(&item_path(
|
let test_path_symbol = Symbol::intern(&item_path(
|
||||||
// skip the name of the root module
|
// skip the name of the root module
|
||||||
@ -50,7 +66,13 @@ pub fn expand_test_case(
|
|||||||
item
|
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(
|
pub fn expand_test(
|
||||||
|
10
tests/ui/test-attrs/custom-test-frameworks/issue-107454.rs
Normal file
10
tests/ui/test-attrs/custom-test-frameworks/issue-107454.rs
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
// compile-flags: --test
|
||||||
|
|
||||||
|
#![feature(custom_test_frameworks)]
|
||||||
|
#![deny(unnameable_test_items)]
|
||||||
|
|
||||||
|
fn foo() {
|
||||||
|
#[test_case]
|
||||||
|
//~^ ERROR cannot test inner items [unnameable_test_items]
|
||||||
|
fn test2() {}
|
||||||
|
}
|
@ -0,0 +1,15 @@
|
|||||||
|
error: cannot test inner items
|
||||||
|
--> $DIR/issue-107454.rs:7:5
|
||||||
|
|
|
||||||
|
LL | #[test_case]
|
||||||
|
| ^^^^^^^^^^^^
|
||||||
|
|
|
||||||
|
note: the lint level is defined here
|
||||||
|
--> $DIR/issue-107454.rs:4:9
|
||||||
|
|
|
||||||
|
LL | #![deny(unnameable_test_items)]
|
||||||
|
| ^^^^^^^^^^^^^^^^^^^^^
|
||||||
|
= note: this error originates in the attribute macro `test_case` (in Nightly builds, run with -Z macro-backtrace for more info)
|
||||||
|
|
||||||
|
error: aborting due to previous error
|
||||||
|
|
Loading…
Reference in New Issue
Block a user