@@ -12,14 +12,14 @@ use rustc_hir::{def::CtorKind, def_id::DefId};
12
12
use rustc_middle:: ty:: { self , TyCtxt } ;
13
13
use rustc_span:: def_id:: CRATE_DEF_INDEX ;
14
14
use rustc_span:: Pos ;
15
+ use rustc_target:: spec:: abi:: Abi as RustcAbi ;
15
16
16
17
use rustdoc_json_types:: * ;
17
18
18
19
use crate :: clean:: utils:: print_const_expr;
19
20
use crate :: clean:: { self , ItemId } ;
20
21
use crate :: formats:: item_type:: ItemType ;
21
22
use crate :: json:: JsonRenderer ;
22
- use std:: collections:: HashSet ;
23
23
24
24
impl JsonRenderer < ' _ > {
25
25
pub ( super ) fn convert_item ( & self , item : clean:: Item ) -> Option < Item > {
@@ -271,22 +271,28 @@ crate fn from_ctor_kind(struct_type: CtorKind) -> StructType {
271
271
}
272
272
}
273
273
274
- crate fn from_fn_header ( header : & rustc_hir:: FnHeader ) -> HashSet < Qualifiers > {
275
- let mut v = HashSet :: new ( ) ;
276
-
277
- if let rustc_hir:: Unsafety :: Unsafe = header. unsafety {
278
- v. insert ( Qualifiers :: Unsafe ) ;
279
- }
280
-
281
- if let rustc_hir:: IsAsync :: Async = header. asyncness {
282
- v. insert ( Qualifiers :: Async ) ;
274
+ crate fn from_fn_header ( header : & rustc_hir:: FnHeader ) -> Header {
275
+ Header {
276
+ async_ : header. is_async ( ) ,
277
+ const_ : header. is_const ( ) ,
278
+ unsafe_ : header. is_unsafe ( ) ,
279
+ abi : convert_abi ( header. abi ) ,
283
280
}
281
+ }
284
282
285
- if let rustc_hir:: Constness :: Const = header. constness {
286
- v. insert ( Qualifiers :: Const ) ;
283
+ fn convert_abi ( a : RustcAbi ) -> Abi {
284
+ match a {
285
+ RustcAbi :: Rust => Abi :: Rust ,
286
+ RustcAbi :: C { unwind } => Abi :: C { unwind } ,
287
+ RustcAbi :: Cdecl { unwind } => Abi :: Cdecl { unwind } ,
288
+ RustcAbi :: Stdcall { unwind } => Abi :: Stdcall { unwind } ,
289
+ RustcAbi :: Fastcall { unwind } => Abi :: Fastcall { unwind } ,
290
+ RustcAbi :: Aapcs { unwind } => Abi :: Aapcs { unwind } ,
291
+ RustcAbi :: Win64 { unwind } => Abi :: Win64 { unwind } ,
292
+ RustcAbi :: SysV64 { unwind } => Abi :: SysV64 { unwind } ,
293
+ RustcAbi :: System { unwind } => Abi :: System { unwind } ,
294
+ _ => Abi :: Other ( a. to_string ( ) ) ,
287
295
}
288
-
289
- v
290
296
}
291
297
292
298
impl FromWithTcx < clean:: Function > for Function {
@@ -296,7 +302,6 @@ impl FromWithTcx<clean::Function> for Function {
296
302
decl : decl. into_tcx ( tcx) ,
297
303
generics : generics. into_tcx ( tcx) ,
298
304
header : from_fn_header ( & header) ,
299
- abi : header. abi . to_string ( ) ,
300
305
}
301
306
}
302
307
}
@@ -465,16 +470,14 @@ impl FromWithTcx<clean::BareFunctionDecl> for FunctionPointer {
465
470
fn from_tcx ( bare_decl : clean:: BareFunctionDecl , tcx : TyCtxt < ' _ > ) -> Self {
466
471
let clean:: BareFunctionDecl { unsafety, generic_params, decl, abi } = bare_decl;
467
472
FunctionPointer {
468
- header : if let rustc_hir:: Unsafety :: Unsafe = unsafety {
469
- let mut hs = HashSet :: new ( ) ;
470
- hs. insert ( Qualifiers :: Unsafe ) ;
471
- hs
472
- } else {
473
- HashSet :: new ( )
473
+ header : Header {
474
+ unsafe_ : matches ! ( unsafety, rustc_hir:: Unsafety :: Unsafe ) ,
475
+ const_ : false ,
476
+ async_ : false ,
477
+ abi : convert_abi ( abi) ,
474
478
} ,
475
479
generic_params : generic_params. into_iter ( ) . map ( |x| x. into_tcx ( tcx) ) . collect ( ) ,
476
480
decl : decl. into_tcx ( tcx) ,
477
- abi : abi. to_string ( ) ,
478
481
}
479
482
}
480
483
}
@@ -554,7 +557,6 @@ crate fn from_function_method(
554
557
decl : decl. into_tcx ( tcx) ,
555
558
generics : generics. into_tcx ( tcx) ,
556
559
header : from_fn_header ( & header) ,
557
- abi : header. abi . to_string ( ) ,
558
560
has_body,
559
561
}
560
562
}
0 commit comments