@@ -159,7 +159,7 @@ fn safety_builder(ast_func: &ast::Fn) -> Option<Vec<String>> {
159
159
fn gen_ex_template ( ast_func : & ast:: Fn , ctx : & AssistContext ) -> Option < Vec < String > > {
160
160
let ( mut lines, ex_helper) = gen_ex_start_helper ( ast_func, ctx) ?;
161
161
// Call the function, check result
162
- if returns_a_value ( ast_func) {
162
+ if returns_a_value ( ast_func, ctx ) {
163
163
if count_parameters ( & ex_helper. param_list ) < 3 {
164
164
lines. push ( format ! ( "assert_eq!({}, );" , ex_helper. function_call) ) ;
165
165
} else {
@@ -183,7 +183,7 @@ fn gen_ex_template(ast_func: &ast::Fn, ctx: &AssistContext) -> Option<Vec<String
183
183
/// `None` if the function has a `self` parameter but is not in an `impl`.
184
184
fn gen_panic_ex_template ( ast_func : & ast:: Fn , ctx : & AssistContext ) -> Option < Vec < String > > {
185
185
let ( mut lines, ex_helper) = gen_ex_start_helper ( ast_func, ctx) ?;
186
- match returns_a_value ( ast_func) {
186
+ match returns_a_value ( ast_func, ctx ) {
187
187
true => lines. push ( format ! ( "let _ = {}; // panics" , ex_helper. function_call) ) ,
188
188
false => lines. push ( format ! ( "{}; // panics" , ex_helper. function_call) ) ,
189
189
}
@@ -424,11 +424,12 @@ fn return_type(ast_func: &ast::Fn) -> Option<ast::Type> {
424
424
}
425
425
426
426
/// Helper function to determine if the function returns some data
427
- fn returns_a_value ( ast_func : & ast:: Fn ) -> bool {
428
- match return_type ( ast_func) {
429
- Some ( ret_type) => ![ "()" , "!" ] . contains ( & ret_type. to_string ( ) . as_str ( ) ) ,
430
- None => false ,
431
- }
427
+ fn returns_a_value ( ast_func : & ast:: Fn , ctx : & AssistContext ) -> bool {
428
+ ctx. sema
429
+ . to_def ( ast_func)
430
+ . map ( |hir_func| hir_func. ret_type ( ctx. db ( ) ) )
431
+ . map ( |ret_ty| !ret_ty. is_unit ( ) && !ret_ty. is_never ( ) )
432
+ . unwrap_or ( false )
432
433
}
433
434
434
435
#[ cfg( test) ]
0 commit comments