Skip to content

Commit a2a5be5

Browse files
committed
Remove enum_from_u32.
It's a macro that just creates an enum with a `from_u32` method. It has two arms. One is unused and the other has a single use. This commit inlines that single use and removes the whole macro. This increases readability because we don't have two different macros interacting (`enum_from_u32` and `language_item_table`). It also converts the `from_u32` method to `items` which is more efficient, because it doesn't require lots of repeated conditions. (Thanks to SparrowLii for that suggestion.)
1 parent 55b6ff8 commit a2a5be5

File tree

3 files changed

+14
-55
lines changed

3 files changed

+14
-55
lines changed

compiler/rustc_data_structures/src/lib.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,6 @@ pub mod fx;
6262
pub mod graph;
6363
pub mod intern;
6464
pub mod jobserver;
65-
pub mod macros;
6665
pub mod marker;
6766
pub mod memmap;
6867
pub mod obligation_forest;

compiler/rustc_data_structures/src/macros.rs

Lines changed: 0 additions & 37 deletions
This file was deleted.

compiler/rustc_hir/src/lang_items.rs

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,7 @@ impl LanguageItems {
4242
}
4343

4444
pub fn iter(&self) -> impl Iterator<Item = (LangItem, DefId)> + '_ {
45-
self.items
46-
.iter()
47-
.enumerate()
48-
.filter_map(|(i, id)| id.map(|id| (LangItem::from_u32(i as u32).unwrap(), id)))
45+
self.items.iter().enumerate().filter_map(|(i, id)| id.map(|id| (LangItem::items()[i], id)))
4946
}
5047
}
5148

@@ -55,21 +52,21 @@ macro_rules! language_item_table {
5552
(
5653
$( $(#[$attr:meta])* $variant:ident, $module:ident :: $name:ident, $method:ident, $target:expr, $generics:expr; )*
5754
) => {
58-
59-
rustc_data_structures::enum_from_u32! {
60-
/// A representation of all the valid lang items in Rust.
61-
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash, Encodable, Decodable)]
62-
pub enum LangItem {
63-
$(
64-
#[doc = concat!("The `", stringify!($name), "` lang item.")]
65-
///
66-
$(#[$attr])*
67-
$variant,
68-
)*
69-
}
55+
/// A representation of all the valid lang items in Rust.
56+
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash, Encodable, Decodable)]
57+
pub enum LangItem {
58+
$(
59+
#[doc = concat!("The `", stringify!($name), "` lang item.")]
60+
$(#[$attr])*
61+
$variant,
62+
)*
7063
}
7164

7265
impl LangItem {
66+
const fn items() -> [LangItem; std::mem::variant_count::<LangItem>()] {
67+
[$(LangItem::$variant,)*]
68+
}
69+
7370
/// Returns the `name` symbol in `#[lang = "$name"]`.
7471
/// For example, [`LangItem::PartialEq`]`.name()`
7572
/// would result in [`sym::eq`] since it is `#[lang = "eq"]`.
@@ -147,7 +144,7 @@ language_item_table! {
147144
Clone, sym::clone, clone_trait, Target::Trait, GenericRequirement::None;
148145
Sync, sym::sync, sync_trait, Target::Trait, GenericRequirement::Exact(0);
149146
DiscriminantKind, sym::discriminant_kind, discriminant_kind_trait, Target::Trait, GenericRequirement::None;
150-
/// The associated item of the [`DiscriminantKind`] trait.
147+
/// The associated item of the `DiscriminantKind` trait.
151148
Discriminant, sym::discriminant_type, discriminant_type, Target::AssocTy, GenericRequirement::None;
152149

153150
PointeeTrait, sym::pointee_trait, pointee_trait, Target::Trait, GenericRequirement::None;

0 commit comments

Comments
 (0)