1use std::cmp::Ordering;
2use std::fmt;
3use std::hash::{Hash, Hasher};
4
5#[cfg(feature = "nightly")]
6use rustc_data_structures::stable_hasher::{
7 HashStable, HashStableContext, StableHasher, StableOrd,
8};
9#[cfg(feature = "nightly")]
10use rustc_macros::{Decodable, Encodable};
11#[cfg(feature = "nightly")]
12use rustc_span::Symbol;
13
14use crate::AbiFromStrErr;
15
16#[cfg(test)]
17mod tests;
18
19#[derive(#[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::Unadjusted =>
::core::fmt::Formatter::write_str(f, "Unadjusted"),
ExternAbi::Custom =>
::core::fmt::Formatter::write_str(f, "Custom"),
ExternAbi::EfiApi =>
::core::fmt::Formatter::write_str(f, "EfiApi"),
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)]
21#[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::Unadjusted => { 7usize }
ExternAbi::Custom => { 8usize }
ExternAbi::EfiApi => { 9usize }
ExternAbi::Aapcs { unwind: ref __binding_0 } => { 10usize }
ExternAbi::CmseNonSecureCall => { 11usize }
ExternAbi::CmseNonSecureEntry => { 12usize }
ExternAbi::GpuKernel => { 13usize }
ExternAbi::PtxKernel => { 14usize }
ExternAbi::AvrInterrupt => { 15usize }
ExternAbi::AvrNonBlockingInterrupt => { 16usize }
ExternAbi::Msp430Interrupt => { 17usize }
ExternAbi::RiscvInterruptM => { 18usize }
ExternAbi::RiscvInterruptS => { 19usize }
ExternAbi::X86Interrupt => { 20usize }
ExternAbi::Cdecl { unwind: ref __binding_0 } => { 21usize }
ExternAbi::Stdcall { unwind: ref __binding_0 } => {
22usize
}
ExternAbi::Fastcall { unwind: ref __binding_0 } => {
23usize
}
ExternAbi::Thiscall { unwind: ref __binding_0 } => {
24usize
}
ExternAbi::Vectorcall { unwind: ref __binding_0 } => {
25usize
}
ExternAbi::SysV64 { unwind: ref __binding_0 } => { 26usize }
ExternAbi::Win64 { unwind: ref __binding_0 } => { 27usize }
};
::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::Unadjusted => {}
ExternAbi::Custom => {}
ExternAbi::EfiApi => {}
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::Unadjusted }
8usize => { ExternAbi::Custom }
9usize => { ExternAbi::EfiApi }
10usize => {
ExternAbi::Aapcs {
unwind: ::rustc_serialize::Decodable::decode(__decoder),
}
}
11usize => { ExternAbi::CmseNonSecureCall }
12usize => { ExternAbi::CmseNonSecureEntry }
13usize => { ExternAbi::GpuKernel }
14usize => { ExternAbi::PtxKernel }
15usize => { ExternAbi::AvrInterrupt }
16usize => { ExternAbi::AvrNonBlockingInterrupt }
17usize => { ExternAbi::Msp430Interrupt }
18usize => { ExternAbi::RiscvInterruptM }
19usize => { ExternAbi::RiscvInterruptS }
20usize => { ExternAbi::X86Interrupt }
21usize => {
ExternAbi::Cdecl {
unwind: ::rustc_serialize::Decodable::decode(__decoder),
}
}
22usize => {
ExternAbi::Stdcall {
unwind: ::rustc_serialize::Decodable::decode(__decoder),
}
}
23usize => {
ExternAbi::Fastcall {
unwind: ::rustc_serialize::Decodable::decode(__decoder),
}
}
24usize => {
ExternAbi::Thiscall {
unwind: ::rustc_serialize::Decodable::decode(__decoder),
}
}
25usize => {
ExternAbi::Vectorcall {
unwind: ::rustc_serialize::Decodable::decode(__decoder),
}
}
26usize => {
ExternAbi::SysV64 {
unwind: ::rustc_serialize::Decodable::decode(__decoder),
}
}
27usize => {
ExternAbi::Win64 {
unwind: ::rustc_serialize::Decodable::decode(__decoder),
}
}
n => {
::core::panicking::panic_fmt(format_args!("invalid enum variant tag while decoding `ExternAbi`, expected 0..28, actual {0}",
n));
}
}
}
}
};Decodable))]
22pub enum ExternAbi {
23 C {
26 unwind: bool,
27 },
28 System {
30 unwind: bool,
31 },
32
33 Rust,
35 RustCall,
38 RustCold,
42
43 RustInvalid,
46
47 RustPreserveNone,
53
54 Unadjusted,
57
58 Custom,
62
63 EfiApi,
66
67 Aapcs {
70 unwind: bool,
71 },
72 CmseNonSecureCall,
74 CmseNonSecureEntry,
76
77 GpuKernel,
80 PtxKernel,
83
84 AvrInterrupt,
86 AvrNonBlockingInterrupt,
87 Msp430Interrupt,
88 RiscvInterruptM,
89 RiscvInterruptS,
90 X86Interrupt,
91
92 Cdecl {
95 unwind: bool,
96 },
97 Stdcall {
99 unwind: bool,
100 },
101 Fastcall {
103 unwind: bool,
104 },
105 Thiscall {
107 unwind: bool,
108 },
109 Vectorcall {
111 unwind: bool,
112 },
113
114 SysV64 {
116 unwind: bool,
117 },
118 Win64 {
119 unwind: bool,
120 },
121}
122
123macro_rules! abi_impls {
124 ($e_name:ident = {
125 $($variant:ident $({ unwind: $uw:literal })? =><= $tok:literal,)*
126 }) => {
127 impl $e_name {
128 pub const ALL_VARIANTS: &[Self] = &[
129 $($e_name::$variant $({ unwind: $uw })*,)*
130 ];
131 pub const fn as_str(&self) -> &'static str {
132 match self {
133 $($e_name::$variant $( { unwind: $uw } )* => $tok,)*
134 }
135 }
136 const fn internal_const_eq(&self, other: &Self) -> bool {
138 match (self, other) {
139 $( ( $e_name::$variant $( { unwind: $uw } )* , $e_name::$variant $( { unwind: $uw } )* ) => true,)*
140 _ => false,
141 }
142 }
143 pub const fn as_packed(&self) -> u8 {
145 let mut index = 0;
146 while index < $e_name::ALL_VARIANTS.len() {
147 if self.internal_const_eq(&$e_name::ALL_VARIANTS[index]) {
148 return index as u8;
149 }
150 index += 1;
151 }
152 panic!("unreachable: invalid ExternAbi variant");
153 }
154 pub const fn from_packed(index: u8) -> Self {
155 let index = index as usize;
156 assert!(index < $e_name::ALL_VARIANTS.len(), "invalid ExternAbi index");
157 $e_name::ALL_VARIANTS[index]
158 }
159 }
160
161 impl ::core::str::FromStr for $e_name {
162 type Err = AbiFromStrErr;
163 fn from_str(s: &str) -> Result<$e_name, Self::Err> {
164 match s {
165 $($tok => Ok($e_name::$variant $({ unwind: $uw })*),)*
166 _ => Err(AbiFromStrErr::Unknown),
167 }
168 }
169 }
170 }
171}
172
173impl ExternAbi {
pub const ALL_VARIANTS: &[Self] =
&[ExternAbi::C { unwind: false }, ExternAbi::C { unwind: true },
ExternAbi::Rust, 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::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::Thiscall { unwind: false },
ExternAbi::Thiscall { unwind: true }, ExternAbi::Unadjusted,
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::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::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::Thiscall { unwind: false } => "thiscall",
ExternAbi::Thiscall { unwind: true } => "thiscall-unwind",
ExternAbi::Unadjusted => "unadjusted",
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::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::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::Thiscall { unwind: false }, ExternAbi::Thiscall {
unwind: false }) => true,
(ExternAbi::Thiscall { unwind: true }, ExternAbi::Thiscall {
unwind: true }) => true,
(ExternAbi::Unadjusted, ExternAbi::Unadjusted) => 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),
"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),
"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 }),
"thiscall" => Ok(ExternAbi::Thiscall { unwind: false }),
"thiscall-unwind" => Ok(ExternAbi::Thiscall { unwind: true }),
"unadjusted" => Ok(ExternAbi::Unadjusted),
"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! {
174 ExternAbi = {
175 C { unwind: false } =><= "C",
176 C { unwind: true } =><= "C-unwind",
177 Rust =><= "Rust",
178 Aapcs { unwind: false } =><= "aapcs",
179 Aapcs { unwind: true } =><= "aapcs-unwind",
180 AvrInterrupt =><= "avr-interrupt",
181 AvrNonBlockingInterrupt =><= "avr-non-blocking-interrupt",
182 Cdecl { unwind: false } =><= "cdecl",
183 Cdecl { unwind: true } =><= "cdecl-unwind",
184 CmseNonSecureCall =><= "cmse-nonsecure-call",
185 CmseNonSecureEntry =><= "cmse-nonsecure-entry",
186 Custom =><= "custom",
187 EfiApi =><= "efiapi",
188 Fastcall { unwind: false } =><= "fastcall",
189 Fastcall { unwind: true } =><= "fastcall-unwind",
190 GpuKernel =><= "gpu-kernel",
191 Msp430Interrupt =><= "msp430-interrupt",
192 PtxKernel =><= "ptx-kernel",
193 RiscvInterruptM =><= "riscv-interrupt-m",
194 RiscvInterruptS =><= "riscv-interrupt-s",
195 RustCall =><= "rust-call",
196 RustCold =><= "rust-cold",
197 RustInvalid =><= "rust-invalid",
198 RustPreserveNone =><= "rust-preserve-none",
199 Stdcall { unwind: false } =><= "stdcall",
200 Stdcall { unwind: true } =><= "stdcall-unwind",
201 System { unwind: false } =><= "system",
202 System { unwind: true } =><= "system-unwind",
203 SysV64 { unwind: false } =><= "sysv64",
204 SysV64 { unwind: true } =><= "sysv64-unwind",
205 Thiscall { unwind: false } =><= "thiscall",
206 Thiscall { unwind: true } =><= "thiscall-unwind",
207 Unadjusted =><= "unadjusted",
208 Vectorcall { unwind: false } =><= "vectorcall",
209 Vectorcall { unwind: true } =><= "vectorcall-unwind",
210 Win64 { unwind: false } =><= "win64",
211 Win64 { unwind: true } =><= "win64-unwind",
212 X86Interrupt =><= "x86-interrupt",
213 }
214}
215
216impl Ord for ExternAbi {
217 fn cmp(&self, rhs: &Self) -> Ordering {
218 self.as_str().cmp(rhs.as_str())
219 }
220}
221
222impl PartialOrd for ExternAbi {
223 fn partial_cmp(&self, rhs: &Self) -> Option<Ordering> {
224 Some(self.cmp(rhs))
225 }
226}
227
228impl PartialEq for ExternAbi {
229 fn eq(&self, rhs: &Self) -> bool {
230 self.cmp(rhs) == Ordering::Equal
231 }
232}
233
234impl Eq for ExternAbi {}
235
236impl Hash for ExternAbi {
237 fn hash<H: Hasher>(&self, state: &mut H) {
238 self.as_str().hash(state);
239 u32::from_be_bytes(*b"ABI\0").hash(state);
241 }
242}
243
244#[cfg(feature = "nightly")]
245impl HashStable for ExternAbi {
246 #[inline]
247 fn hash_stable<Hcx: HashStableContext>(&self, _: &mut Hcx, hasher: &mut StableHasher) {
248 Hash::hash(self, hasher);
249 }
250}
251
252#[cfg(feature = "nightly")]
253impl StableOrd for ExternAbi {
254 const CAN_USE_UNSTABLE_SORT: bool = true;
255
256 const THIS_IMPLEMENTATION_HAS_BEEN_TRIPLE_CHECKED: () = ();
258}
259
260#[cfg(feature = "nightly")]
261impl ::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);
262
263#[cfg(feature = "nightly")]
264pub enum CVariadicStatus {
265 NotSupported,
266 Stable,
267 Unstable { feature: Symbol },
268}
269
270impl ExternAbi {
271 pub fn is_rustic_abi(self) -> bool {
278 use ExternAbi::*;
279 #[allow(non_exhaustive_omitted_patterns)] match self {
Rust | RustCall | RustCold | RustPreserveNone => true,
_ => false,
}matches!(self, Rust | RustCall | RustCold | RustPreserveNone)
280 }
281
282 #[cfg(feature = "nightly")]
286 pub fn supports_c_variadic(self) -> CVariadicStatus {
287 match self {
299 Self::C { .. }
300 | Self::Cdecl { .. }
301 | Self::Aapcs { .. }
302 | Self::Win64 { .. }
303 | Self::SysV64 { .. }
304 | Self::EfiApi
305 | Self::System { .. } => CVariadicStatus::Stable,
306 _ => CVariadicStatus::NotSupported,
307 }
308 }
309
310 #[cfg(feature = "nightly")]
312 pub fn supports_guaranteed_tail_call(self) -> bool {
313 match self {
314 Self::CmseNonSecureCall | Self::CmseNonSecureEntry => {
315 false
318 }
319 Self::AvrInterrupt
320 | Self::AvrNonBlockingInterrupt
321 | Self::Msp430Interrupt
322 | Self::RiscvInterruptM
323 | Self::RiscvInterruptS
324 | Self::X86Interrupt => {
325 false
327 }
328 Self::GpuKernel | Self::PtxKernel => {
329 false
331 }
332 Self::Custom => {
333 false
335 }
336 Self::C { .. }
337 | Self::System { .. }
338 | Self::Rust
339 | Self::RustCall
340 | Self::RustCold
341 | Self::RustInvalid
342 | Self::Unadjusted
343 | Self::EfiApi
344 | Self::Aapcs { .. }
345 | Self::Cdecl { .. }
346 | Self::Stdcall { .. }
347 | Self::Fastcall { .. }
348 | Self::Thiscall { .. }
349 | Self::Vectorcall { .. }
350 | Self::SysV64 { .. }
351 | Self::Win64 { .. }
352 | Self::RustPreserveNone => true,
353 }
354 }
355}
356
357pub fn all_names() -> Vec<&'static str> {
358 ExternAbi::ALL_VARIANTS.iter().map(|abi| abi.as_str()).collect()
359}
360
361impl ExternAbi {
362 pub const FALLBACK: ExternAbi = ExternAbi::C { unwind: false };
364
365 pub fn name(self) -> &'static str {
366 self.as_str()
367 }
368}
369
370impl fmt::Display for ExternAbi {
371 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
372 f.write_fmt(format_args!("\"{0}\"", self.as_str()))write!(f, "\"{}\"", self.as_str())
373 }
374}