Skip to content

Commit 2150c83

Browse files
compiler: remove rustc_abi::lookup and AbiUnsupported
These can be entirely replaced by the FromStr implementation.
1 parent 99f9c34 commit 2150c83

File tree

4 files changed

+15
-18
lines changed

4 files changed

+15
-18
lines changed

compiler/rustc_abi/src/extern_abi.rs

+1-8
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
use std::cmp::Ordering;
22
use std::fmt;
33
use std::hash::{Hash, Hasher};
4-
use std::str::FromStr;
54

65
#[cfg(feature = "nightly")]
76
use rustc_data_structures::stable_hasher::{HashStable, StableHasher, StableOrd};
@@ -101,6 +100,7 @@ macro_rules! abi_impls {
101100
}
102101
}
103102

103+
#[derive(Debug)]
104104
pub enum AbiFromStrErr {
105105
Unknown,
106106
}
@@ -214,13 +214,6 @@ impl ExternAbi {
214214
}
215215
}
216216

217-
#[derive(Copy, Clone, Debug)]
218-
pub struct AbiUnsupported {}
219-
/// Returns the ABI with the given name (if any).
220-
pub fn lookup(name: &str) -> Result<Abi, AbiUnsupported> {
221-
ExternAbi::from_str(name).map_err(|_| AbiUnsupported {})
222-
}
223-
224217
pub fn all_names() -> Vec<&'static str> {
225218
ExternAbi::ALL_VARIANTS.iter().map(|abi| abi.as_str()).collect()
226219
}

compiler/rustc_abi/src/extern_abi/tests.rs

+5-4
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,25 @@
11
use std::assert_matches::assert_matches;
2+
use std::str::FromStr;
23

34
use super::*;
45

56
#[allow(non_snake_case)]
67
#[test]
78
fn lookup_Rust() {
8-
let abi = lookup("Rust");
9+
let abi = ExternAbi::from_str("Rust");
910
assert!(abi.is_ok() && abi.unwrap().as_str() == "Rust");
1011
}
1112

1213
#[test]
1314
fn lookup_cdecl() {
14-
let abi = lookup("cdecl");
15+
let abi = ExternAbi::from_str("cdecl");
1516
assert!(abi.is_ok() && abi.unwrap().as_str() == "cdecl");
1617
}
1718

1819
#[test]
1920
fn lookup_baz() {
20-
let abi = lookup("baz");
21-
assert_matches!(abi, Err(AbiUnsupported {}));
21+
let abi = ExternAbi::from_str("baz");
22+
assert_matches!(abi, Err(AbiFromStrErr::Unknown));
2223
}
2324

2425
#[test]

compiler/rustc_abi/src/lib.rs

+8-5
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ mod tests;
6262
mod extern_abi;
6363

6464
pub use callconv::{Heterogeneous, HomogeneousAggregate, Reg, RegKind};
65-
pub use extern_abi::{AbiUnsupported, ExternAbi, all_names, lookup};
65+
pub use extern_abi::{ExternAbi, all_names};
6666
#[cfg(feature = "nightly")]
6767
pub use layout::{FIRST_VARIANT, FieldIdx, Layout, TyAbiInterface, TyAndLayout, VariantIdx};
6868
pub use layout::{LayoutCalculator, LayoutCalculatorError};
@@ -1178,10 +1178,13 @@ impl Scalar {
11781178
#[inline]
11791179
pub fn is_bool(&self) -> bool {
11801180
use Integer::*;
1181-
matches!(self, Scalar::Initialized {
1182-
value: Primitive::Int(I8, false),
1183-
valid_range: WrappingRange { start: 0, end: 1 }
1184-
})
1181+
matches!(
1182+
self,
1183+
Scalar::Initialized {
1184+
value: Primitive::Int(I8, false),
1185+
valid_range: WrappingRange { start: 0, end: 1 }
1186+
}
1187+
)
11851188
}
11861189

11871190
/// Get the primitive representation of this type, ignoring the valid range and whether the

compiler/rustc_ast_lowering/src/item.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1475,7 +1475,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
14751475

14761476
pub(super) fn lower_abi(&mut self, abi_str: StrLit) -> ExternAbi {
14771477
let ast::StrLit { symbol_unescaped, span, .. } = abi_str;
1478-
let extern_abi = rustc_abi::lookup(symbol_unescaped.as_str()).unwrap_or_else(|_| {
1478+
let extern_abi = symbol_unescaped.as_str().parse().unwrap_or_else(|_| {
14791479
self.error_on_invalid_abi(abi_str);
14801480
ExternAbi::Rust
14811481
});

0 commit comments

Comments
 (0)