11use std:: { collections:: HashMap , fmt} ;
22
33use ra_ap_syntax:: {
4- ast:: { self , HasDocComments , HasGenericParams , HasName } ,
4+ ast:: { self , HasDocComments , HasGenericParams , HasName , Fn } ,
55 AstNode , SourceFile , SyntaxKind ,
66} ;
77
@@ -302,7 +302,7 @@ pub(crate) fn find_function_in_file(
302302 top : stuff. 1 . 0 ,
303303 bottom : stuff. 1 . 1 ,
304304 lines : ( stuff. 0 . 0 , stuff. 0 . 1 ) ,
305- return_type : function . ret_type ( ) . map ( |ty| ty . to_string ( ) ) ,
305+ return_type : get_ret_type ( & function ) ,
306306 arguments : f. param_list ( ) . map_or_else ( HashMap :: new, |args| {
307307 args. params ( )
308308 . filter_map ( |arg| {
@@ -341,7 +341,7 @@ pub(crate) fn find_function_in_file(
341341 body,
342342 block : parent_block,
343343 function : parent_fn,
344- return_type : f . ret_type ( ) . map ( |ty| ty . to_string ( ) ) ,
344+ return_type : get_ret_type ( & f ) ,
345345 arguments : f. param_list ( ) . map_or_else ( HashMap :: new, |args| {
346346 args. params ( )
347347 . filter_map ( |arg| {
@@ -419,9 +419,11 @@ fn get_genrerics_and_lifetime<T: HasGenericParams>(block: &T) -> (Vec<String>, V
419419 || ( vec ! [ ] , vec ! [ ] ) ,
420420 |gt| {
421421 (
422- // gt.
423- gt. generic_params ( )
424- . map ( |gt| gt. to_string ( ) )
422+ gt. type_or_const_params ( )
423+ . map ( |gt|match gt {
424+ ast:: TypeOrConstParam :: Type ( ty) => ty. to_string ( ) ,
425+ ast:: TypeOrConstParam :: Const ( c) => c. to_string ( ) ,
426+ } )
425427 . collect :: < Vec < String > > ( ) ,
426428 gt. lifetime_params ( )
427429 . map ( |lt| lt. to_string ( ) )
@@ -443,6 +445,16 @@ fn get_doc_comments_and_attrs<T: HasDocComments>(block: &T) -> (Vec<String>, Vec
443445 . collect :: < Vec < String > > ( ) ,
444446 )
445447}
448+
449+ fn get_ret_type ( fns : & Fn ) -> Option < String > {
450+ match fns. ret_type ( ) {
451+ Some ( ret) => match ret. ty ( ) {
452+ Some ( ty) => Some ( ty. to_string ( ) ) ,
453+ None => None ,
454+ } ,
455+ None => None ,
456+ }
457+ }
446458#[ derive( Debug , Clone , PartialEq , Eq ) ]
447459pub enum RustFilter {
448460 /// when you want to filter by function that are in a specific block (impl, trait, extern)
0 commit comments