@@ -17,7 +17,7 @@ use rustc_hir::def::{CtorOf, DefKind as HirDefKind, Res};
1717use rustc_hir:: def_id:: { DefId , LOCAL_CRATE } ;
1818use rustc_hir:: intravisit:: { self , Visitor } ;
1919use rustc_hir:: Node ;
20- use rustc_hir_pretty:: ty_to_string;
20+ use rustc_hir_pretty:: { fn_to_string , ty_to_string} ;
2121use rustc_middle:: hir:: map:: Map ;
2222use rustc_middle:: middle:: cstore:: ExternCrate ;
2323use rustc_middle:: middle:: privacy:: AccessLevels ;
@@ -135,7 +135,7 @@ impl<'l, 'tcx> SaveContext<'l, 'tcx> {
135135 let def_id = self . tcx . hir ( ) . local_def_id ( item. hir_id ) . to_def_id ( ) ;
136136 let qualname = format ! ( "::{}" , self . tcx. def_path_str( def_id) ) ;
137137 match item. kind {
138- hir:: ForeignItemKind :: Fn ( ref decl, _ , ref generics) => {
138+ hir:: ForeignItemKind :: Fn ( ref decl, arg_names , ref generics) => {
139139 filter ! ( self . span_utils, item. ident. span) ;
140140
141141 Some ( Data :: DefData ( Def {
@@ -144,7 +144,23 @@ impl<'l, 'tcx> SaveContext<'l, 'tcx> {
144144 span : self . span_from_span ( item. ident . span ) ,
145145 name : item. ident . to_string ( ) ,
146146 qualname,
147- value : make_signature ( decl, generics) ,
147+ value : fn_to_string (
148+ decl,
149+ hir:: FnHeader {
150+ // functions in extern block are implicitly unsafe
151+ unsafety : hir:: Unsafety :: Unsafe ,
152+ // functions in extern block cannot be const
153+ constness : hir:: Constness :: NotConst ,
154+ abi : self . tcx . hir ( ) . get_foreign_abi ( item. hir_id ) ,
155+ // functions in extern block cannot be async
156+ asyncness : hir:: IsAsync :: NotAsync ,
157+ } ,
158+ Some ( item. ident . name ) ,
159+ generics,
160+ & item. vis ,
161+ arg_names,
162+ None ,
163+ ) ,
148164 parent : None ,
149165 children : vec ! [ ] ,
150166 decl_id : None ,
@@ -191,7 +207,15 @@ impl<'l, 'tcx> SaveContext<'l, 'tcx> {
191207 span : self . span_from_span ( item. ident . span ) ,
192208 name : item. ident . to_string ( ) ,
193209 qualname,
194- value : make_signature ( & sig. decl , generics) ,
210+ value : fn_to_string (
211+ sig. decl ,
212+ sig. header ,
213+ Some ( item. ident . name ) ,
214+ generics,
215+ & item. vis ,
216+ & [ ] ,
217+ None ,
218+ ) ,
195219 parent : None ,
196220 children : vec ! [ ] ,
197221 decl_id : None ,
@@ -848,31 +872,6 @@ impl<'l, 'tcx> SaveContext<'l, 'tcx> {
848872 }
849873}
850874
851- fn make_signature ( decl : & hir:: FnDecl < ' _ > , generics : & hir:: Generics < ' _ > ) -> String {
852- let mut sig = "fn " . to_owned ( ) ;
853- if !generics. params . is_empty ( ) {
854- sig. push ( '<' ) ;
855- sig. push_str (
856- & generics
857- . params
858- . iter ( )
859- . map ( |param| param. name . ident ( ) . to_string ( ) )
860- . collect :: < Vec < _ > > ( )
861- . join ( ", " ) ,
862- ) ;
863- sig. push_str ( "> " ) ;
864- }
865- sig. push ( '(' ) ;
866- sig. push_str ( & decl. inputs . iter ( ) . map ( ty_to_string) . collect :: < Vec < _ > > ( ) . join ( ", " ) ) ;
867- sig. push ( ')' ) ;
868- match decl. output {
869- hir:: FnRetTy :: DefaultReturn ( _) => sig. push_str ( " -> ()" ) ,
870- hir:: FnRetTy :: Return ( ref t) => sig. push_str ( & format ! ( " -> {}" , ty_to_string( t) ) ) ,
871- }
872-
873- sig
874- }
875-
876875// An AST visitor for collecting paths (e.g., the names of structs) and formal
877876// variables (idents) from patterns.
878877struct PathCollector < ' l > {
0 commit comments