Skip to content

Commit a32e7dc

Browse files
rationalize AbiConvErr better
1 parent dda0821 commit a32e7dc

File tree

4 files changed

+14
-12
lines changed

4 files changed

+14
-12
lines changed

compiler/rustc_abi/src/canon_abi.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use std::str::FromStr;
66
#[cfg(feature = "nightly")]
77
use rustc_data_structures::stable_hasher::{HashStable, StableHasher, StableOrd};
88

9-
use crate::{AbiFromStrErr, ExternAbi};
9+
use crate::{AbiConvErr, ExternAbi};
1010

1111
/// Calling convention to determine codegen
1212
///
@@ -137,7 +137,7 @@ impl CanonAbi {
137137
/// convert an ExternAbi to a CanonAbi if it maps directly
138138
///
139139
/// Pretty incorrect to publicly expose!
140-
const fn try_from_extern_abi(extern_abi: ExternAbi) -> Result<Self, AbiFromStrErr> {
140+
const fn try_from_extern_abi(extern_abi: ExternAbi) -> Result<Self, AbiConvErr> {
141141
match extern_abi {
142142
ExternAbi::C { unwind: false } => Ok(Self::C),
143143
ExternAbi::Rust => Ok(Self::Rust),
@@ -173,7 +173,7 @@ impl CanonAbi {
173173
| ExternAbi::PtxKernel
174174
| ExternAbi::RustCall
175175
| ExternAbi::System { unwind: _ }
176-
| ExternAbi::Unadjusted => Err(AbiFromStrErr::Unknown),
176+
| ExternAbi::Unadjusted => Err(AbiConvErr::Unknown),
177177
// unwind where it should not unwind
178178
ExternAbi::Aapcs { unwind: true }
179179
| ExternAbi::C { unwind: true }
@@ -182,13 +182,13 @@ impl CanonAbi {
182182
| ExternAbi::Vectorcall { unwind: true }
183183
| ExternAbi::Thiscall { unwind: true }
184184
| ExternAbi::Win64 { unwind: true }
185-
| ExternAbi::SysV64 { unwind: true } => Err(AbiFromStrErr::NoUnwind),
185+
| ExternAbi::SysV64 { unwind: true } => Err(AbiConvErr::UnwindInvalid),
186186
}
187187
}
188188
}
189189

190190
impl FromStr for CanonAbi {
191-
type Err = AbiFromStrErr;
191+
type Err = AbiConvErr;
192192

193193
fn from_str(s: &str) -> Result<Self, Self::Err> {
194194
// parse as ExternAbi and propagate out errors, as CanonAbi uses the same errors

compiler/rustc_abi/src/extern_abi.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use rustc_data_structures::stable_hasher::{HashStable, StableHasher, StableOrd};
77
#[cfg(feature = "nightly")]
88
use rustc_macros::{Decodable, Encodable};
99

10-
use crate::AbiFromStrErr;
10+
use crate::AbiConvErr;
1111

1212
#[cfg(test)]
1313
mod tests;
@@ -90,11 +90,11 @@ macro_rules! abi_impls {
9090
}
9191

9292
impl ::core::str::FromStr for $e_name {
93-
type Err = AbiFromStrErr;
93+
type Err = AbiConvErr;
9494
fn from_str(s: &str) -> Result<$e_name, Self::Err> {
9595
match s {
9696
$($tok => Ok($e_name::$variant $({ unwind: $uw })*),)*
97-
_ => Err(AbiFromStrErr::Unknown),
97+
_ => Err(AbiConvErr::Unknown),
9898
}
9999
}
100100
}

compiler/rustc_abi/src/extern_abi/tests.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ fn lookup_cdecl() {
1919
#[test]
2020
fn lookup_baz() {
2121
let abi = ExternAbi::from_str("baz");
22-
assert_matches!(abi, Err(AbiFromStrErr::Unknown));
22+
assert_matches!(abi, Err(AbiConvErr::Unknown));
2323
}
2424

2525
#[test]

compiler/rustc_abi/src/lib.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1897,10 +1897,12 @@ pub enum StructKind {
18971897
Prefixed(Size, Align),
18981898
}
18991899

1900+
/// Errors in converting to or from an "Abi" type,
1901+
/// relative to the conversion performed.
19001902
#[derive(Clone, Debug)]
1901-
pub enum AbiFromStrErr {
1903+
pub enum AbiConvErr {
19021904
/// not a known ABI
19031905
Unknown,
1904-
/// no "-unwind" variant
1905-
NoUnwind,
1906+
/// "unwind" isn't valid
1907+
UnwindInvalid,
19061908
}

0 commit comments

Comments
 (0)