Skip to content

Commit 58a06b6

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`).
1 parent d3d01e1 commit 58a06b6

File tree

3 files changed

+19
-51
lines changed

3 files changed

+19
-51
lines changed

compiler/rustc_data_structures/src/lib.rs

-1
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

-37
This file was deleted.

compiler/rustc_hir/src/lang_items.rs

+19-13
Original file line numberDiff line numberDiff line change
@@ -55,21 +55,27 @@ macro_rules! language_item_table {
5555
(
5656
$( $(#[$attr:meta])* $variant:ident, $module:ident :: $name:ident, $method:ident, $target:expr, $generics:expr; )*
5757
) => {
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-
}
58+
/// A representation of all the valid lang items in Rust.
59+
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash, Encodable, Decodable)]
60+
pub enum LangItem {
61+
$(
62+
#[doc = concat!("The `", stringify!($name), "` lang item.")]
63+
$(#[$attr])*
64+
$variant,
65+
)*
7066
}
7167

7268
impl LangItem {
69+
fn from_u32(u: u32) -> Option<LangItem> {
70+
// This implementation is clumsy, but makes no assumptions
71+
// about how discriminant tags are allocated within the
72+
// range `0 .. std::mem::variant_count::<LangItem>()`.
73+
$(if u == LangItem::$variant as u32 {
74+
return Some(LangItem::$variant)
75+
})*
76+
None
77+
}
78+
7379
/// Returns the `name` symbol in `#[lang = "$name"]`.
7480
/// For example, [`LangItem::PartialEq`]`.name()`
7581
/// would result in [`sym::eq`] since it is `#[lang = "eq"]`.
@@ -147,7 +153,7 @@ language_item_table! {
147153
Clone, sym::clone, clone_trait, Target::Trait, GenericRequirement::None;
148154
Sync, sym::sync, sync_trait, Target::Trait, GenericRequirement::Exact(0);
149155
DiscriminantKind, sym::discriminant_kind, discriminant_kind_trait, Target::Trait, GenericRequirement::None;
150-
/// The associated item of the [`DiscriminantKind`] trait.
156+
/// The associated item of the `DiscriminantKind` trait.
151157
Discriminant, sym::discriminant_type, discriminant_type, Target::AssocTy, GenericRequirement::None;
152158

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

0 commit comments

Comments
 (0)