@@ -17,7 +17,7 @@ use rustc_hir::def::{CtorOf, DefKind as HirDefKind, Res};
17
17
use rustc_hir:: def_id:: { DefId , LOCAL_CRATE } ;
18
18
use rustc_hir:: intravisit:: { self , Visitor } ;
19
19
use rustc_hir:: Node ;
20
- use rustc_hir_pretty:: ty_to_string;
20
+ use rustc_hir_pretty:: { fn_to_string , ty_to_string} ;
21
21
use rustc_middle:: hir:: map:: Map ;
22
22
use rustc_middle:: middle:: cstore:: ExternCrate ;
23
23
use rustc_middle:: middle:: privacy:: AccessLevels ;
@@ -135,7 +135,7 @@ impl<'l, 'tcx> SaveContext<'l, 'tcx> {
135
135
let def_id = self . tcx . hir ( ) . local_def_id ( item. hir_id ) . to_def_id ( ) ;
136
136
let qualname = format ! ( "::{}" , self . tcx. def_path_str( def_id) ) ;
137
137
match item. kind {
138
- hir:: ForeignItemKind :: Fn ( ref decl, _ , ref generics) => {
138
+ hir:: ForeignItemKind :: Fn ( ref decl, arg_names , ref generics) => {
139
139
filter ! ( self . span_utils, item. ident. span) ;
140
140
141
141
Some ( Data :: DefData ( Def {
@@ -144,7 +144,23 @@ impl<'l, 'tcx> SaveContext<'l, 'tcx> {
144
144
span : self . span_from_span ( item. ident . span ) ,
145
145
name : item. ident . to_string ( ) ,
146
146
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
+ ) ,
148
164
parent : None ,
149
165
children : vec ! [ ] ,
150
166
decl_id : None ,
@@ -191,7 +207,15 @@ impl<'l, 'tcx> SaveContext<'l, 'tcx> {
191
207
span : self . span_from_span ( item. ident . span ) ,
192
208
name : item. ident . to_string ( ) ,
193
209
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
+ ) ,
195
219
parent : None ,
196
220
children : vec ! [ ] ,
197
221
decl_id : None ,
@@ -848,31 +872,6 @@ impl<'l, 'tcx> SaveContext<'l, 'tcx> {
848
872
}
849
873
}
850
874
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
-
876
875
// An AST visitor for collecting paths (e.g., the names of structs) and formal
877
876
// variables (idents) from patterns.
878
877
struct PathCollector < ' l > {
0 commit comments