@@ -103,7 +103,7 @@ pub fn expand_test_or_bench(
103103 } ;
104104
105105 // 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 {
107107 let diag = & cx. sess . parse_sess . span_diagnostic ;
108108 let msg = "the `#[test]` attribute may only be used on a non-associated function" ;
109109 let mut err = match item. kind {
@@ -121,7 +121,7 @@ pub fn expand_test_or_bench(
121121 . emit ( ) ;
122122
123123 return vec ! [ Annotatable :: Item ( item) ] ;
124- }
124+ } ;
125125
126126 // has_*_signature will report any errors in the type so compilation
127127 // will fail. We shouldn't try to expand in this case because the errors
@@ -132,12 +132,14 @@ pub fn expand_test_or_bench(
132132 return vec ! [ Annotatable :: Item ( item) ] ;
133133 }
134134
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) ;
136138
137139 let test_id = Ident :: new ( sym:: test, attr_sp) ;
138140
139141 // 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) ] ) ;
141143
142144 // creates test::ShouldPanic::$name
143145 let should_panic_path = |name| {
@@ -183,7 +185,7 @@ pub fn expand_test_or_bench(
183185 vec![
184186 // super::$test_fn(b)
185187 cx. expr_call(
186- sp ,
188+ ret_ty_sp ,
187189 cx. expr_path( cx. path( sp, vec![ item. ident] ) ) ,
188190 vec![ cx. expr_ident( sp, b) ] ,
189191 ) ,
@@ -207,7 +209,11 @@ pub fn expand_test_or_bench(
207209 cx. expr_path( test_path( "assert_test_result" ) ) ,
208210 vec![
209211 // $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+ ) , // )
211217 ] ,
212218 ) , // }
213219 ) , // )
0 commit comments