@@ -12,14 +12,14 @@ use rustc_hir::{def::CtorKind, def_id::DefId};
1212use rustc_middle:: ty:: { self , TyCtxt } ;
1313use rustc_span:: def_id:: CRATE_DEF_INDEX ;
1414use rustc_span:: Pos ;
15+ use rustc_target:: spec:: abi:: Abi as RustcAbi ;
1516
1617use rustdoc_json_types:: * ;
1718
1819use crate :: clean:: utils:: print_const_expr;
1920use crate :: clean:: { self , ItemId } ;
2021use crate :: formats:: item_type:: ItemType ;
2122use crate :: json:: JsonRenderer ;
22- use std:: collections:: HashSet ;
2323
2424impl JsonRenderer < ' _ > {
2525 pub ( super ) fn convert_item ( & self , item : clean:: Item ) -> Option < Item > {
@@ -271,22 +271,28 @@ crate fn from_ctor_kind(struct_type: CtorKind) -> StructType {
271271 }
272272}
273273
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 ) ,
283280 }
281+ }
284282
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 ( ) ) ,
287295 }
288-
289- v
290296}
291297
292298impl FromWithTcx < clean:: Function > for Function {
@@ -296,7 +302,6 @@ impl FromWithTcx<clean::Function> for Function {
296302 decl : decl. into_tcx ( tcx) ,
297303 generics : generics. into_tcx ( tcx) ,
298304 header : from_fn_header ( & header) ,
299- abi : header. abi . to_string ( ) ,
300305 }
301306 }
302307}
@@ -465,16 +470,14 @@ impl FromWithTcx<clean::BareFunctionDecl> for FunctionPointer {
465470 fn from_tcx ( bare_decl : clean:: BareFunctionDecl , tcx : TyCtxt < ' _ > ) -> Self {
466471 let clean:: BareFunctionDecl { unsafety, generic_params, decl, abi } = bare_decl;
467472 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) ,
474478 } ,
475479 generic_params : generic_params. into_iter ( ) . map ( |x| x. into_tcx ( tcx) ) . collect ( ) ,
476480 decl : decl. into_tcx ( tcx) ,
477- abi : abi. to_string ( ) ,
478481 }
479482 }
480483}
@@ -554,7 +557,6 @@ crate fn from_function_method(
554557 decl : decl. into_tcx ( tcx) ,
555558 generics : generics. into_tcx ( tcx) ,
556559 header : from_fn_header ( & header) ,
557- abi : header. abi . to_string ( ) ,
558560 has_body,
559561 }
560562}
0 commit comments