File tree 3 files changed +49
-2
lines changed
compiler/rustc_builtin_macros/src
tests/ui/test-attrs/custom-test-frameworks
3 files changed +49
-2
lines changed Original file line number Diff line number Diff line change @@ -33,7 +33,23 @@ pub fn expand_test_case(
33
33
}
34
34
35
35
let sp = ecx. with_def_site_ctxt ( attr_sp) ;
36
- let mut item = anno_item. expect_item ( ) ;
36
+ let ( mut item, is_stmt) = match anno_item {
37
+ Annotatable :: Item ( item) => ( item, false ) ,
38
+ Annotatable :: Stmt ( stmt) if let ast:: StmtKind :: Item ( _) = stmt. kind => if let ast:: StmtKind :: Item ( i) = stmt. into_inner ( ) . kind {
39
+ ( i, true )
40
+ } else {
41
+ unreachable ! ( )
42
+ } ,
43
+ _ => {
44
+ ecx. struct_span_err (
45
+ anno_item. span ( ) ,
46
+ "`#[test_case]` attribute is only allowed on items" ,
47
+ )
48
+ . emit ( ) ;
49
+
50
+ return vec ! [ ] ;
51
+ }
52
+ } ;
37
53
item = item. map ( |mut item| {
38
54
let test_path_symbol = Symbol :: intern ( & item_path (
39
55
// skip the name of the root module
@@ -50,7 +66,13 @@ pub fn expand_test_case(
50
66
item
51
67
} ) ;
52
68
53
- return vec ! [ Annotatable :: Item ( item) ] ;
69
+ let ret = if is_stmt {
70
+ Annotatable :: Stmt ( P ( ecx. stmt_item ( item. span , item) ) )
71
+ } else {
72
+ Annotatable :: Item ( item)
73
+ } ;
74
+
75
+ vec ! [ ret]
54
76
}
55
77
56
78
pub fn expand_test (
Original file line number Diff line number Diff line change
1
+ // compile-flags: --test
2
+
3
+ #![ feature( custom_test_frameworks) ]
4
+ #![ deny( unnameable_test_items) ]
5
+
6
+ fn foo ( ) {
7
+ #[ test_case]
8
+ //~^ ERROR cannot test inner items [unnameable_test_items]
9
+ fn test2 ( ) { }
10
+ }
Original file line number Diff line number Diff line change
1
+ error: cannot test inner items
2
+ --> $DIR/issue-107454.rs:7:5
3
+ |
4
+ LL | #[test_case]
5
+ | ^^^^^^^^^^^^
6
+ |
7
+ note: the lint level is defined here
8
+ --> $DIR/issue-107454.rs:4:9
9
+ |
10
+ LL | #![deny(unnameable_test_items)]
11
+ | ^^^^^^^^^^^^^^^^^^^^^
12
+ = note: this error originates in the attribute macro `test_case` (in Nightly builds, run with -Z macro-backtrace for more info)
13
+
14
+ error: aborting due to previous error
15
+
You can’t perform that action at this time.
0 commit comments