@@ -103,7 +103,7 @@ pub fn expand_test_or_bench(
103
103
} ;
104
104
105
105
// Note: non-associated fn items are already handled by `expand_test_or_bench`
106
- if ! matches ! ( item . kind , ast:: ItemKind :: Fn ( _ ) ) {
106
+ let ast:: ItemKind :: Fn ( fn_ ) = & item . kind else {
107
107
let diag = & cx. sess . parse_sess . span_diagnostic ;
108
108
let msg = "the `#[test]` attribute may only be used on a non-associated function" ;
109
109
let mut err = match item. kind {
@@ -121,7 +121,7 @@ pub fn expand_test_or_bench(
121
121
. emit ( ) ;
122
122
123
123
return vec ! [ Annotatable :: Item ( item) ] ;
124
- }
124
+ } ;
125
125
126
126
// has_*_signature will report any errors in the type so compilation
127
127
// will fail. We shouldn't try to expand in this case because the errors
@@ -132,12 +132,14 @@ pub fn expand_test_or_bench(
132
132
return vec ! [ Annotatable :: Item ( item) ] ;
133
133
}
134
134
135
- let ( sp, attr_sp) = ( cx. with_def_site_ctxt ( item. span ) , cx. with_def_site_ctxt ( attr_sp) ) ;
135
+ let sp = cx. with_def_site_ctxt ( item. span ) ;
136
+ let ret_ty_sp = cx. with_def_site_ctxt ( fn_. sig . decl . output . span ( ) ) ;
137
+ let attr_sp = cx. with_def_site_ctxt ( attr_sp) ;
136
138
137
139
let test_id = Ident :: new ( sym:: test, attr_sp) ;
138
140
139
141
// creates test::$name
140
- let test_path = |name| cx. path ( sp , vec ! [ test_id, Ident :: from_str_and_span( name, sp) ] ) ;
142
+ let test_path = |name| cx. path ( ret_ty_sp , vec ! [ test_id, Ident :: from_str_and_span( name, sp) ] ) ;
141
143
142
144
// creates test::ShouldPanic::$name
143
145
let should_panic_path = |name| {
@@ -183,7 +185,7 @@ pub fn expand_test_or_bench(
183
185
vec![
184
186
// super::$test_fn(b)
185
187
cx. expr_call(
186
- sp ,
188
+ ret_ty_sp ,
187
189
cx. expr_path( cx. path( sp, vec![ item. ident] ) ) ,
188
190
vec![ cx. expr_ident( sp, b) ] ,
189
191
) ,
@@ -207,7 +209,11 @@ pub fn expand_test_or_bench(
207
209
cx. expr_path( test_path( "assert_test_result" ) ) ,
208
210
vec![
209
211
// $test_fn()
210
- cx. expr_call( sp, cx. expr_path( cx. path( sp, vec![ item. ident] ) ) , vec![ ] ) , // )
212
+ cx. expr_call(
213
+ ret_ty_sp,
214
+ cx. expr_path( cx. path( sp, vec![ item. ident] ) ) ,
215
+ vec![ ] ,
216
+ ) , // )
211
217
] ,
212
218
) , // }
213
219
) , // )
0 commit comments