1use std::cmp::Ordering;
2use std::fmt;
3use std::hash::{Hash, Hasher};
4
5#[cfg(feature = "nightly")]
6use rustc_data_structures::stable_hash::{StableHash, StableHashCtxt, StableHasher, StableOrd};
7#[cfg(feature = "nightly")]
8use rustc_macros::{Decodable, Encodable};
9#[cfg(feature = "nightly")]
10use rustc_span::Symbol;
11
12use crate::AbiFromStrErr;
13
14#[cfg(test)]
15mod tests;
16
17#[derive(#[automatically_derived]
#[doc(hidden)]
unsafe impl ::core::clone::TrivialClone for ExternAbi { }
#[automatically_derived]
impl ::core::clone::Clone for ExternAbi {
#[inline]
fn clone(&self) -> ExternAbi {
let _: ::core::clone::AssertParamIsClone<bool>;
*self
}
}Clone, #[automatically_derived]
impl ::core::marker::Copy for ExternAbi { }Copy, #[automatically_derived]
impl ::core::fmt::Debug for ExternAbi {
#[inline]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
match self {
ExternAbi::C { unwind: __self_0 } =>
::core::fmt::Formatter::debug_struct_field1_finish(f, "C",
"unwind", &__self_0),
ExternAbi::System { unwind: __self_0 } =>
::core::fmt::Formatter::debug_struct_field1_finish(f,
"System", "unwind", &__self_0),
ExternAbi::Rust => ::core::fmt::Formatter::write_str(f, "Rust"),
ExternAbi::RustCall =>
::core::fmt::Formatter::write_str(f, "RustCall"),
ExternAbi::RustCold =>
::core::fmt::Formatter::write_str(f, "RustCold"),
ExternAbi::RustInvalid =>
::core::fmt::Formatter::write_str(f, "RustInvalid"),
ExternAbi::RustPreserveNone =>
::core::fmt::Formatter::write_str(f, "RustPreserveNone"),
ExternAbi::RustTail =>
::core::fmt::Formatter::write_str(f, "RustTail"),
ExternAbi::LlvmIntrinsic =>
::core::fmt::Formatter::write_str(f, "LlvmIntrinsic"),
ExternAbi::Custom =>
::core::fmt::Formatter::write_str(f, "Custom"),
ExternAbi::EfiApi =>
::core::fmt::Formatter::write_str(f, "EfiApi"),
ExternAbi::Swift => ::core::fmt::Formatter::write_str(f, "Swift"),
ExternAbi::Aapcs { unwind: __self_0 } =>
::core::fmt::Formatter::debug_struct_field1_finish(f, "Aapcs",
"unwind", &__self_0),
ExternAbi::CmseNonSecureCall =>
::core::fmt::Formatter::write_str(f, "CmseNonSecureCall"),
ExternAbi::CmseNonSecureEntry =>
::core::fmt::Formatter::write_str(f, "CmseNonSecureEntry"),
ExternAbi::GpuKernel =>
::core::fmt::Formatter::write_str(f, "GpuKernel"),
ExternAbi::PtxKernel =>
::core::fmt::Formatter::write_str(f, "PtxKernel"),
ExternAbi::AvrInterrupt =>
::core::fmt::Formatter::write_str(f, "AvrInterrupt"),
ExternAbi::AvrNonBlockingInterrupt =>
::core::fmt::Formatter::write_str(f,
"AvrNonBlockingInterrupt"),
ExternAbi::Msp430Interrupt =>
::core::fmt::Formatter::write_str(f, "Msp430Interrupt"),
ExternAbi::RiscvInterruptM =>
::core::fmt::Formatter::write_str(f, "RiscvInterruptM"),
ExternAbi::RiscvInterruptS =>
::core::fmt::Formatter::write_str(f, "RiscvInterruptS"),
ExternAbi::X86Interrupt =>
::core::fmt::Formatter::write_str(f, "X86Interrupt"),
ExternAbi::Cdecl { unwind: __self_0 } =>
::core::fmt::Formatter::debug_struct_field1_finish(f, "Cdecl",
"unwind", &__self_0),
ExternAbi::Stdcall { unwind: __self_0 } =>
::core::fmt::Formatter::debug_struct_field1_finish(f,
"Stdcall", "unwind", &__self_0),
ExternAbi::Fastcall { unwind: __self_0 } =>
::core::fmt::Formatter::debug_struct_field1_finish(f,
"Fastcall", "unwind", &__self_0),
ExternAbi::Thiscall { unwind: __self_0 } =>
::core::fmt::Formatter::debug_struct_field1_finish(f,
"Thiscall", "unwind", &__self_0),
ExternAbi::Vectorcall { unwind: __self_0 } =>
::core::fmt::Formatter::debug_struct_field1_finish(f,
"Vectorcall", "unwind", &__self_0),
ExternAbi::SysV64 { unwind: __self_0 } =>
::core::fmt::Formatter::debug_struct_field1_finish(f,
"SysV64", "unwind", &__self_0),
ExternAbi::Win64 { unwind: __self_0 } =>
::core::fmt::Formatter::debug_struct_field1_finish(f, "Win64",
"unwind", &__self_0),
}
}
}Debug)]
19#[cfg_attr(feature = "nightly", derive(const _: () =
{
impl<__E: ::rustc_span::SpanEncoder> ::rustc_serialize::Encodable<__E>
for ExternAbi {
fn encode(&self, __encoder: &mut __E) {
let disc =
match *self {
ExternAbi::C { unwind: ref __binding_0 } => { 0usize }
ExternAbi::System { unwind: ref __binding_0 } => { 1usize }
ExternAbi::Rust => { 2usize }
ExternAbi::RustCall => { 3usize }
ExternAbi::RustCold => { 4usize }
ExternAbi::RustInvalid => { 5usize }
ExternAbi::RustPreserveNone => { 6usize }
ExternAbi::RustTail => { 7usize }
ExternAbi::LlvmIntrinsic => { 8usize }
ExternAbi::Custom => { 9usize }
ExternAbi::EfiApi => { 10usize }
ExternAbi::Swift => { 11usize }
ExternAbi::Aapcs { unwind: ref __binding_0 } => { 12usize }
ExternAbi::CmseNonSecureCall => { 13usize }
ExternAbi::CmseNonSecureEntry => { 14usize }
ExternAbi::GpuKernel => { 15usize }
ExternAbi::PtxKernel => { 16usize }
ExternAbi::AvrInterrupt => { 17usize }
ExternAbi::AvrNonBlockingInterrupt => { 18usize }
ExternAbi::Msp430Interrupt => { 19usize }
ExternAbi::RiscvInterruptM => { 20usize }
ExternAbi::RiscvInterruptS => { 21usize }
ExternAbi::X86Interrupt => { 22usize }
ExternAbi::Cdecl { unwind: ref __binding_0 } => { 23usize }
ExternAbi::Stdcall { unwind: ref __binding_0 } => {
24usize
}
ExternAbi::Fastcall { unwind: ref __binding_0 } => {
25usize
}
ExternAbi::Thiscall { unwind: ref __binding_0 } => {
26usize
}
ExternAbi::Vectorcall { unwind: ref __binding_0 } => {
27usize
}
ExternAbi::SysV64 { unwind: ref __binding_0 } => { 28usize }
ExternAbi::Win64 { unwind: ref __binding_0 } => { 29usize }
};
::rustc_serialize::Encoder::emit_u8(__encoder, disc as u8);
match *self {
ExternAbi::C { unwind: ref __binding_0 } => {
::rustc_serialize::Encodable::<__E>::encode(__binding_0,
__encoder);
}
ExternAbi::System { unwind: ref __binding_0 } => {
::rustc_serialize::Encodable::<__E>::encode(__binding_0,
__encoder);
}
ExternAbi::Rust => {}
ExternAbi::RustCall => {}
ExternAbi::RustCold => {}
ExternAbi::RustInvalid => {}
ExternAbi::RustPreserveNone => {}
ExternAbi::RustTail => {}
ExternAbi::LlvmIntrinsic => {}
ExternAbi::Custom => {}
ExternAbi::EfiApi => {}
ExternAbi::Swift => {}
ExternAbi::Aapcs { unwind: ref __binding_0 } => {
::rustc_serialize::Encodable::<__E>::encode(__binding_0,
__encoder);
}
ExternAbi::CmseNonSecureCall => {}
ExternAbi::CmseNonSecureEntry => {}
ExternAbi::GpuKernel => {}
ExternAbi::PtxKernel => {}
ExternAbi::AvrInterrupt => {}
ExternAbi::AvrNonBlockingInterrupt => {}
ExternAbi::Msp430Interrupt => {}
ExternAbi::RiscvInterruptM => {}
ExternAbi::RiscvInterruptS => {}
ExternAbi::X86Interrupt => {}
ExternAbi::Cdecl { unwind: ref __binding_0 } => {
::rustc_serialize::Encodable::<__E>::encode(__binding_0,
__encoder);
}
ExternAbi::Stdcall { unwind: ref __binding_0 } => {
::rustc_serialize::Encodable::<__E>::encode(__binding_0,
__encoder);
}
ExternAbi::Fastcall { unwind: ref __binding_0 } => {
::rustc_serialize::Encodable::<__E>::encode(__binding_0,
__encoder);
}
ExternAbi::Thiscall { unwind: ref __binding_0 } => {
::rustc_serialize::Encodable::<__E>::encode(__binding_0,
__encoder);
}
ExternAbi::Vectorcall { unwind: ref __binding_0 } => {
::rustc_serialize::Encodable::<__E>::encode(__binding_0,
__encoder);
}
ExternAbi::SysV64 { unwind: ref __binding_0 } => {
::rustc_serialize::Encodable::<__E>::encode(__binding_0,
__encoder);
}
ExternAbi::Win64 { unwind: ref __binding_0 } => {
::rustc_serialize::Encodable::<__E>::encode(__binding_0,
__encoder);
}
}
}
}
};Encodable, const _: () =
{
impl<__D: ::rustc_span::SpanDecoder> ::rustc_serialize::Decodable<__D>
for ExternAbi {
fn decode(__decoder: &mut __D) -> Self {
match ::rustc_serialize::Decoder::read_u8(__decoder) as usize
{
0usize => {
ExternAbi::C {
unwind: ::rustc_serialize::Decodable::decode(__decoder),
}
}
1usize => {
ExternAbi::System {
unwind: ::rustc_serialize::Decodable::decode(__decoder),
}
}
2usize => { ExternAbi::Rust }
3usize => { ExternAbi::RustCall }
4usize => { ExternAbi::RustCold }
5usize => { ExternAbi::RustInvalid }
6usize => { ExternAbi::RustPreserveNone }
7usize => { ExternAbi::RustTail }
8usize => { ExternAbi::LlvmIntrinsic }
9usize => { ExternAbi::Custom }
10usize => { ExternAbi::EfiApi }
11usize => { ExternAbi::Swift }
12usize => {
ExternAbi::Aapcs {
unwind: ::rustc_serialize::Decodable::decode(__decoder),
}
}
13usize => { ExternAbi::CmseNonSecureCall }
14usize => { ExternAbi::CmseNonSecureEntry }
15usize => { ExternAbi::GpuKernel }
16usize => { ExternAbi::PtxKernel }
17usize => { ExternAbi::AvrInterrupt }
18usize => { ExternAbi::AvrNonBlockingInterrupt }
19usize => { ExternAbi::Msp430Interrupt }
20usize => { ExternAbi::RiscvInterruptM }
21usize => { ExternAbi::RiscvInterruptS }
22usize => { ExternAbi::X86Interrupt }
23usize => {
ExternAbi::Cdecl {
unwind: ::rustc_serialize::Decodable::decode(__decoder),
}
}
24usize => {
ExternAbi::Stdcall {
unwind: ::rustc_serialize::Decodable::decode(__decoder),
}
}
25usize => {
ExternAbi::Fastcall {
unwind: ::rustc_serialize::Decodable::decode(__decoder),
}
}
26usize => {
ExternAbi::Thiscall {
unwind: ::rustc_serialize::Decodable::decode(__decoder),
}
}
27usize => {
ExternAbi::Vectorcall {
unwind: ::rustc_serialize::Decodable::decode(__decoder),
}
}
28usize => {
ExternAbi::SysV64 {
unwind: ::rustc_serialize::Decodable::decode(__decoder),
}
}
29usize => {
ExternAbi::Win64 {
unwind: ::rustc_serialize::Decodable::decode(__decoder),
}
}
n => {
::core::panicking::panic_fmt(format_args!("invalid enum variant tag while decoding `ExternAbi`, expected 0..30, actual {0}",
n));
}
}
}
}
};Decodable))]
20pub enum ExternAbi {
21 C {
24 unwind: bool,
25 },
26 System {
28 unwind: bool,
29 },
30
31 Rust,
33 RustCall,
36 RustCold,
40
41 RustInvalid,
44
45 RustPreserveNone,
51
52 RustTail,
56
57 LlvmIntrinsic,
59
60 Custom,
64
65 EfiApi,
68
69 Swift,
72
73 Aapcs {
76 unwind: bool,
77 },
78 CmseNonSecureCall,
80 CmseNonSecureEntry,
82
83 GpuKernel,
86 PtxKernel,
89
90 AvrInterrupt,
92 AvrNonBlockingInterrupt,
93 Msp430Interrupt,
94 RiscvInterruptM,
95 RiscvInterruptS,
96 X86Interrupt,
97
98 Cdecl {
101 unwind: bool,
102 },
103 Stdcall {
105 unwind: bool,
106 },
107 Fastcall {
109 unwind: bool,
110 },
111 Thiscall {
113 unwind: bool,
114 },
115 Vectorcall {
117 unwind: bool,
118 },
119
120 SysV64 {
122 unwind: bool,
123 },
124 Win64 {
125 unwind: bool,
126 },
127}
128
129macro_rules! abi_impls {
130 ($e_name:ident = {
131 $($variant:ident $({ unwind: $uw:literal })? =><= $tok:literal,)*
132 }) => {
133 impl $e_name {
134 pub const ALL_VARIANTS: &[Self] = &[
135 $($e_name::$variant $({ unwind: $uw })*,)*
136 ];
137 pub const fn as_str(&self) -> &'static str {
138 match self {
139 $($e_name::$variant $( { unwind: $uw } )* => $tok,)*
140 }
141 }
142 const fn internal_const_eq(&self, other: &Self) -> bool {
144 match (self, other) {
145 $( ( $e_name::$variant $( { unwind: $uw } )* , $e_name::$variant $( { unwind: $uw } )* ) => true,)*
146 _ => false,
147 }
148 }
149 pub const fn as_packed(&self) -> u8 {
151 let mut index = 0;
152 while index < $e_name::ALL_VARIANTS.len() {
153 if self.internal_const_eq(&$e_name::ALL_VARIANTS[index]) {
154 return index as u8;
155 }
156 index += 1;
157 }
158 panic!("unreachable: invalid ExternAbi variant");
159 }
160 pub const fn from_packed(index: u8) -> Self {
161 let index = index as usize;
162 assert!(index < $e_name::ALL_VARIANTS.len(), "invalid ExternAbi index");
163 $e_name::ALL_VARIANTS[index]
164 }
165 }
166
167 impl ::core::str::FromStr for $e_name {
168 type Err = AbiFromStrErr;
169 fn from_str(s: &str) -> Result<$e_name, Self::Err> {
170 match s {
171 $($tok => Ok($e_name::$variant $({ unwind: $uw })*),)*
172 _ => Err(AbiFromStrErr::Unknown),
173 }
174 }
175 }
176 }
177}
178
179impl ExternAbi {
pub const ALL_VARIANTS: &[Self] =
&[ExternAbi::C { unwind: false }, ExternAbi::C { unwind: true },
ExternAbi::Rust, ExternAbi::Swift,
ExternAbi::Aapcs { unwind: false },
ExternAbi::Aapcs { unwind: true }, ExternAbi::AvrInterrupt,
ExternAbi::AvrNonBlockingInterrupt,
ExternAbi::Cdecl { unwind: false },
ExternAbi::Cdecl { unwind: true },
ExternAbi::CmseNonSecureCall, ExternAbi::CmseNonSecureEntry,
ExternAbi::Custom, ExternAbi::EfiApi,
ExternAbi::Fastcall { unwind: false },
ExternAbi::Fastcall { unwind: true }, ExternAbi::GpuKernel,
ExternAbi::LlvmIntrinsic, ExternAbi::Msp430Interrupt,
ExternAbi::PtxKernel, ExternAbi::RiscvInterruptM,
ExternAbi::RiscvInterruptS, ExternAbi::RustCall,
ExternAbi::RustCold, ExternAbi::RustInvalid,
ExternAbi::RustPreserveNone,
ExternAbi::Stdcall { unwind: false },
ExternAbi::Stdcall { unwind: true },
ExternAbi::System { unwind: false },
ExternAbi::System { unwind: true },
ExternAbi::SysV64 { unwind: false },
ExternAbi::SysV64 { unwind: true }, ExternAbi::RustTail,
ExternAbi::Thiscall { unwind: false },
ExternAbi::Thiscall { unwind: true },
ExternAbi::Vectorcall { unwind: false },
ExternAbi::Vectorcall { unwind: true },
ExternAbi::Win64 { unwind: false },
ExternAbi::Win64 { unwind: true }, ExternAbi::X86Interrupt];
pub const fn as_str(&self) -> &'static str {
match self {
ExternAbi::C { unwind: false } => "C",
ExternAbi::C { unwind: true } => "C-unwind",
ExternAbi::Rust => "Rust",
ExternAbi::Swift => "Swift",
ExternAbi::Aapcs { unwind: false } => "aapcs",
ExternAbi::Aapcs { unwind: true } => "aapcs-unwind",
ExternAbi::AvrInterrupt => "avr-interrupt",
ExternAbi::AvrNonBlockingInterrupt =>
"avr-non-blocking-interrupt",
ExternAbi::Cdecl { unwind: false } => "cdecl",
ExternAbi::Cdecl { unwind: true } => "cdecl-unwind",
ExternAbi::CmseNonSecureCall => "cmse-nonsecure-call",
ExternAbi::CmseNonSecureEntry => "cmse-nonsecure-entry",
ExternAbi::Custom => "custom",
ExternAbi::EfiApi => "efiapi",
ExternAbi::Fastcall { unwind: false } => "fastcall",
ExternAbi::Fastcall { unwind: true } => "fastcall-unwind",
ExternAbi::GpuKernel => "gpu-kernel",
ExternAbi::LlvmIntrinsic => "llvm-intrinsic",
ExternAbi::Msp430Interrupt => "msp430-interrupt",
ExternAbi::PtxKernel => "ptx-kernel",
ExternAbi::RiscvInterruptM => "riscv-interrupt-m",
ExternAbi::RiscvInterruptS => "riscv-interrupt-s",
ExternAbi::RustCall => "rust-call",
ExternAbi::RustCold => "rust-cold",
ExternAbi::RustInvalid => "rust-invalid",
ExternAbi::RustPreserveNone => "rust-preserve-none",
ExternAbi::Stdcall { unwind: false } => "stdcall",
ExternAbi::Stdcall { unwind: true } => "stdcall-unwind",
ExternAbi::System { unwind: false } => "system",
ExternAbi::System { unwind: true } => "system-unwind",
ExternAbi::SysV64 { unwind: false } => "sysv64",
ExternAbi::SysV64 { unwind: true } => "sysv64-unwind",
ExternAbi::RustTail => "tail",
ExternAbi::Thiscall { unwind: false } => "thiscall",
ExternAbi::Thiscall { unwind: true } => "thiscall-unwind",
ExternAbi::Vectorcall { unwind: false } => "vectorcall",
ExternAbi::Vectorcall { unwind: true } => "vectorcall-unwind",
ExternAbi::Win64 { unwind: false } => "win64",
ExternAbi::Win64 { unwind: true } => "win64-unwind",
ExternAbi::X86Interrupt => "x86-interrupt",
}
}
const fn internal_const_eq(&self, other: &Self) -> bool {
match (self, other) {
(ExternAbi::C { unwind: false }, ExternAbi::C { unwind: false })
=> true,
(ExternAbi::C { unwind: true }, ExternAbi::C { unwind: true }) =>
true,
(ExternAbi::Rust, ExternAbi::Rust) => true,
(ExternAbi::Swift, ExternAbi::Swift) => true,
(ExternAbi::Aapcs { unwind: false }, ExternAbi::Aapcs {
unwind: false }) => true,
(ExternAbi::Aapcs { unwind: true }, ExternAbi::Aapcs {
unwind: true }) => true,
(ExternAbi::AvrInterrupt, ExternAbi::AvrInterrupt) => true,
(ExternAbi::AvrNonBlockingInterrupt,
ExternAbi::AvrNonBlockingInterrupt) => true,
(ExternAbi::Cdecl { unwind: false }, ExternAbi::Cdecl {
unwind: false }) => true,
(ExternAbi::Cdecl { unwind: true }, ExternAbi::Cdecl {
unwind: true }) => true,
(ExternAbi::CmseNonSecureCall, ExternAbi::CmseNonSecureCall) =>
true,
(ExternAbi::CmseNonSecureEntry, ExternAbi::CmseNonSecureEntry) =>
true,
(ExternAbi::Custom, ExternAbi::Custom) => true,
(ExternAbi::EfiApi, ExternAbi::EfiApi) => true,
(ExternAbi::Fastcall { unwind: false }, ExternAbi::Fastcall {
unwind: false }) => true,
(ExternAbi::Fastcall { unwind: true }, ExternAbi::Fastcall {
unwind: true }) => true,
(ExternAbi::GpuKernel, ExternAbi::GpuKernel) => true,
(ExternAbi::LlvmIntrinsic, ExternAbi::LlvmIntrinsic) => true,
(ExternAbi::Msp430Interrupt, ExternAbi::Msp430Interrupt) => true,
(ExternAbi::PtxKernel, ExternAbi::PtxKernel) => true,
(ExternAbi::RiscvInterruptM, ExternAbi::RiscvInterruptM) => true,
(ExternAbi::RiscvInterruptS, ExternAbi::RiscvInterruptS) => true,
(ExternAbi::RustCall, ExternAbi::RustCall) => true,
(ExternAbi::RustCold, ExternAbi::RustCold) => true,
(ExternAbi::RustInvalid, ExternAbi::RustInvalid) => true,
(ExternAbi::RustPreserveNone, ExternAbi::RustPreserveNone) =>
true,
(ExternAbi::Stdcall { unwind: false }, ExternAbi::Stdcall {
unwind: false }) => true,
(ExternAbi::Stdcall { unwind: true }, ExternAbi::Stdcall {
unwind: true }) => true,
(ExternAbi::System { unwind: false }, ExternAbi::System {
unwind: false }) => true,
(ExternAbi::System { unwind: true }, ExternAbi::System {
unwind: true }) => true,
(ExternAbi::SysV64 { unwind: false }, ExternAbi::SysV64 {
unwind: false }) => true,
(ExternAbi::SysV64 { unwind: true }, ExternAbi::SysV64 {
unwind: true }) => true,
(ExternAbi::RustTail, ExternAbi::RustTail) => true,
(ExternAbi::Thiscall { unwind: false }, ExternAbi::Thiscall {
unwind: false }) => true,
(ExternAbi::Thiscall { unwind: true }, ExternAbi::Thiscall {
unwind: true }) => true,
(ExternAbi::Vectorcall { unwind: false }, ExternAbi::Vectorcall {
unwind: false }) => true,
(ExternAbi::Vectorcall { unwind: true }, ExternAbi::Vectorcall {
unwind: true }) => true,
(ExternAbi::Win64 { unwind: false }, ExternAbi::Win64 {
unwind: false }) => true,
(ExternAbi::Win64 { unwind: true }, ExternAbi::Win64 {
unwind: true }) => true,
(ExternAbi::X86Interrupt, ExternAbi::X86Interrupt) => true,
_ => false,
}
}
pub const fn as_packed(&self) -> u8 {
let mut index = 0;
while index < ExternAbi::ALL_VARIANTS.len() {
if self.internal_const_eq(&ExternAbi::ALL_VARIANTS[index]) {
return index as u8;
}
index += 1;
}
{
::core::panicking::panic_fmt(format_args!("unreachable: invalid ExternAbi variant"));
};
}
pub const fn from_packed(index: u8) -> Self {
let index = index as usize;
if !(index < ExternAbi::ALL_VARIANTS.len()) {
{
::core::panicking::panic_fmt(format_args!("invalid ExternAbi index"));
}
};
ExternAbi::ALL_VARIANTS[index]
}
}
impl ::core::str::FromStr for ExternAbi {
type Err = AbiFromStrErr;
fn from_str(s: &str) -> Result<ExternAbi, Self::Err> {
match s {
"C" => Ok(ExternAbi::C { unwind: false }),
"C-unwind" => Ok(ExternAbi::C { unwind: true }),
"Rust" => Ok(ExternAbi::Rust),
"Swift" => Ok(ExternAbi::Swift),
"aapcs" => Ok(ExternAbi::Aapcs { unwind: false }),
"aapcs-unwind" => Ok(ExternAbi::Aapcs { unwind: true }),
"avr-interrupt" => Ok(ExternAbi::AvrInterrupt),
"avr-non-blocking-interrupt" =>
Ok(ExternAbi::AvrNonBlockingInterrupt),
"cdecl" => Ok(ExternAbi::Cdecl { unwind: false }),
"cdecl-unwind" => Ok(ExternAbi::Cdecl { unwind: true }),
"cmse-nonsecure-call" => Ok(ExternAbi::CmseNonSecureCall),
"cmse-nonsecure-entry" => Ok(ExternAbi::CmseNonSecureEntry),
"custom" => Ok(ExternAbi::Custom),
"efiapi" => Ok(ExternAbi::EfiApi),
"fastcall" => Ok(ExternAbi::Fastcall { unwind: false }),
"fastcall-unwind" => Ok(ExternAbi::Fastcall { unwind: true }),
"gpu-kernel" => Ok(ExternAbi::GpuKernel),
"llvm-intrinsic" => Ok(ExternAbi::LlvmIntrinsic),
"msp430-interrupt" => Ok(ExternAbi::Msp430Interrupt),
"ptx-kernel" => Ok(ExternAbi::PtxKernel),
"riscv-interrupt-m" => Ok(ExternAbi::RiscvInterruptM),
"riscv-interrupt-s" => Ok(ExternAbi::RiscvInterruptS),
"rust-call" => Ok(ExternAbi::RustCall),
"rust-cold" => Ok(ExternAbi::RustCold),
"rust-invalid" => Ok(ExternAbi::RustInvalid),
"rust-preserve-none" => Ok(ExternAbi::RustPreserveNone),
"stdcall" => Ok(ExternAbi::Stdcall { unwind: false }),
"stdcall-unwind" => Ok(ExternAbi::Stdcall { unwind: true }),
"system" => Ok(ExternAbi::System { unwind: false }),
"system-unwind" => Ok(ExternAbi::System { unwind: true }),
"sysv64" => Ok(ExternAbi::SysV64 { unwind: false }),
"sysv64-unwind" => Ok(ExternAbi::SysV64 { unwind: true }),
"tail" => Ok(ExternAbi::RustTail),
"thiscall" => Ok(ExternAbi::Thiscall { unwind: false }),
"thiscall-unwind" => Ok(ExternAbi::Thiscall { unwind: true }),
"vectorcall" => Ok(ExternAbi::Vectorcall { unwind: false }),
"vectorcall-unwind" => Ok(ExternAbi::Vectorcall { unwind: true }),
"win64" => Ok(ExternAbi::Win64 { unwind: false }),
"win64-unwind" => Ok(ExternAbi::Win64 { unwind: true }),
"x86-interrupt" => Ok(ExternAbi::X86Interrupt),
_ => Err(AbiFromStrErr::Unknown),
}
}
}abi_impls! {
180 ExternAbi = {
181 C { unwind: false } =><= "C",
182 C { unwind: true } =><= "C-unwind",
183 Rust =><= "Rust",
184 Swift =><= "Swift",
185 Aapcs { unwind: false } =><= "aapcs",
186 Aapcs { unwind: true } =><= "aapcs-unwind",
187 AvrInterrupt =><= "avr-interrupt",
188 AvrNonBlockingInterrupt =><= "avr-non-blocking-interrupt",
189 Cdecl { unwind: false } =><= "cdecl",
190 Cdecl { unwind: true } =><= "cdecl-unwind",
191 CmseNonSecureCall =><= "cmse-nonsecure-call",
192 CmseNonSecureEntry =><= "cmse-nonsecure-entry",
193 Custom =><= "custom",
194 EfiApi =><= "efiapi",
195 Fastcall { unwind: false } =><= "fastcall",
196 Fastcall { unwind: true } =><= "fastcall-unwind",
197 GpuKernel =><= "gpu-kernel",
198 LlvmIntrinsic =><= "llvm-intrinsic",
199 Msp430Interrupt =><= "msp430-interrupt",
200 PtxKernel =><= "ptx-kernel",
201 RiscvInterruptM =><= "riscv-interrupt-m",
202 RiscvInterruptS =><= "riscv-interrupt-s",
203 RustCall =><= "rust-call",
204 RustCold =><= "rust-cold",
205 RustInvalid =><= "rust-invalid",
206 RustPreserveNone =><= "rust-preserve-none",
207 Stdcall { unwind: false } =><= "stdcall",
208 Stdcall { unwind: true } =><= "stdcall-unwind",
209 System { unwind: false } =><= "system",
210 System { unwind: true } =><= "system-unwind",
211 SysV64 { unwind: false } =><= "sysv64",
212 SysV64 { unwind: true } =><= "sysv64-unwind",
213 RustTail =><= "tail",
214 Thiscall { unwind: false } =><= "thiscall",
215 Thiscall { unwind: true } =><= "thiscall-unwind",
216 Vectorcall { unwind: false } =><= "vectorcall",
217 Vectorcall { unwind: true } =><= "vectorcall-unwind",
218 Win64 { unwind: false } =><= "win64",
219 Win64 { unwind: true } =><= "win64-unwind",
220 X86Interrupt =><= "x86-interrupt",
221 }
222}
223
224impl Ord for ExternAbi {
225 fn cmp(&self, rhs: &Self) -> Ordering {
226 self.as_str().cmp(rhs.as_str())
227 }
228}
229
230impl PartialOrd for ExternAbi {
231 fn partial_cmp(&self, rhs: &Self) -> Option<Ordering> {
232 Some(self.cmp(rhs))
233 }
234}
235
236impl PartialEq for ExternAbi {
237 fn eq(&self, rhs: &Self) -> bool {
238 self.cmp(rhs) == Ordering::Equal
239 }
240}
241
242impl Eq for ExternAbi {}
243
244impl Hash for ExternAbi {
245 fn hash<H: Hasher>(&self, state: &mut H) {
246 self.as_str().hash(state);
247 u32::from_be_bytes(*b"ABI\0").hash(state);
249 }
250}
251
252#[cfg(feature = "nightly")]
253impl StableHash for ExternAbi {
254 #[inline]
255 fn stable_hash<Hcx: StableHashCtxt>(&self, _: &mut Hcx, hasher: &mut StableHasher) {
256 Hash::hash(self, hasher);
257 }
258}
259
260#[cfg(feature = "nightly")]
261impl StableOrd for ExternAbi {
262 const CAN_USE_UNSTABLE_SORT: bool = true;
263
264 const THIS_IMPLEMENTATION_HAS_BEEN_TRIPLE_CHECKED: () = ();
266}
267
268#[cfg(feature = "nightly")]
269impl ::rustc_error_messages::IntoDiagArg for ExternAbi {
fn into_diag_arg(self, path: &mut Option<std::path::PathBuf>)
-> ::rustc_error_messages::DiagArgValue {
self.to_string().into_diag_arg(path)
}
}rustc_error_messages::into_diag_arg_using_display!(ExternAbi);
270
271#[cfg(feature = "nightly")]
272#[derive(#[automatically_derived]
impl ::core::fmt::Debug for CVariadicStatus {
#[inline]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
match self {
CVariadicStatus::NotSupported =>
::core::fmt::Formatter::write_str(f, "NotSupported"),
CVariadicStatus::Stable =>
::core::fmt::Formatter::write_str(f, "Stable"),
CVariadicStatus::Unstable { feature: __self_0 } =>
::core::fmt::Formatter::debug_struct_field1_finish(f,
"Unstable", "feature", &__self_0),
}
}
}Debug)]
273pub enum CVariadicStatus {
274 NotSupported,
275 Stable,
276 Unstable { feature: Symbol },
277}
278
279impl ExternAbi {
280 pub fn is_rustic_abi(self) -> bool {
287 use ExternAbi::*;
288 #[allow(non_exhaustive_omitted_patterns)] match self {
Rust | RustCall | RustCold | RustPreserveNone | RustTail => true,
_ => false,
}matches!(self, Rust | RustCall | RustCold | RustPreserveNone | RustTail)
289 }
290
291 #[cfg(feature = "nightly")]
295 pub fn supports_c_variadic(self) -> CVariadicStatus {
296 match self {
308 Self::C { .. }
309 | Self::Cdecl { .. }
310 | Self::Aapcs { .. }
311 | Self::Win64 { .. }
312 | Self::SysV64 { .. }
313 | Self::EfiApi
314 | Self::System { .. } => CVariadicStatus::Stable,
315 _ => CVariadicStatus::NotSupported,
316 }
317 }
318
319 #[cfg(feature = "nightly")]
321 pub fn supports_guaranteed_tail_call(self) -> bool {
322 match self {
323 Self::CmseNonSecureCall | Self::CmseNonSecureEntry => {
324 false
327 }
328 Self::AvrInterrupt
329 | Self::AvrNonBlockingInterrupt
330 | Self::Msp430Interrupt
331 | Self::RiscvInterruptM
332 | Self::RiscvInterruptS
333 | Self::X86Interrupt => {
334 false
336 }
337 Self::GpuKernel | Self::PtxKernel => {
338 false
340 }
341 Self::Custom => {
342 false
344 }
345 Self::RustCall => {
346 false
350 }
351
352 Self::C { .. }
353 | Self::System { .. }
354 | Self::Rust
355 | Self::RustCold
356 | Self::RustInvalid
357 | Self::LlvmIntrinsic
358 | Self::EfiApi
359 | Self::Aapcs { .. }
360 | Self::Cdecl { .. }
361 | Self::Stdcall { .. }
362 | Self::Fastcall { .. }
363 | Self::Thiscall { .. }
364 | Self::Vectorcall { .. }
365 | Self::SysV64 { .. }
366 | Self::Win64 { .. }
367 | Self::RustPreserveNone
368 | Self::RustTail
369 | Self::Swift => true,
370 }
371 }
372}
373
374pub fn all_names() -> Vec<&'static str> {
375 ExternAbi::ALL_VARIANTS.iter().map(|abi| abi.as_str()).collect()
376}
377
378impl ExternAbi {
379 pub const FALLBACK: ExternAbi = ExternAbi::C { unwind: false };
381
382 pub fn name(self) -> &'static str {
383 self.as_str()
384 }
385}
386
387impl fmt::Display for ExternAbi {
388 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
389 f.write_fmt(format_args!("\"{0}\"", self.as_str()))write!(f, "\"{}\"", self.as_str())
390 }
391}