mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-22 06:44:35 +00:00
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`).
This commit is contained in:
parent
d3d01e1cd3
commit
58a06b6a99
@ -62,7 +62,6 @@ pub mod fx;
|
||||
pub mod graph;
|
||||
pub mod intern;
|
||||
pub mod jobserver;
|
||||
pub mod macros;
|
||||
pub mod marker;
|
||||
pub mod memmap;
|
||||
pub mod obligation_forest;
|
||||
|
@ -1,37 +0,0 @@
|
||||
#[macro_export]
|
||||
macro_rules! enum_from_u32 {
|
||||
($(#[$attr:meta])* pub enum $name:ident {
|
||||
$($(#[$var_attr:meta])* $variant:ident = $e:expr,)*
|
||||
}) => {
|
||||
$(#[$attr])*
|
||||
pub enum $name {
|
||||
$($(#[$var_attr])* $variant = $e),*
|
||||
}
|
||||
|
||||
impl $name {
|
||||
pub fn from_u32(u: u32) -> Option<$name> {
|
||||
$(if u == $name::$variant as u32 {
|
||||
return Some($name::$variant)
|
||||
})*
|
||||
None
|
||||
}
|
||||
}
|
||||
};
|
||||
($(#[$attr:meta])* pub enum $name:ident {
|
||||
$($(#[$var_attr:meta])* $variant:ident,)*
|
||||
}) => {
|
||||
$(#[$attr])*
|
||||
pub enum $name {
|
||||
$($(#[$var_attr])* $variant,)*
|
||||
}
|
||||
|
||||
impl $name {
|
||||
pub fn from_u32(u: u32) -> Option<$name> {
|
||||
$(if u == $name::$variant as u32 {
|
||||
return Some($name::$variant)
|
||||
})*
|
||||
None
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -55,21 +55,27 @@ macro_rules! language_item_table {
|
||||
(
|
||||
$( $(#[$attr:meta])* $variant:ident, $module:ident :: $name:ident, $method:ident, $target:expr, $generics:expr; )*
|
||||
) => {
|
||||
|
||||
rustc_data_structures::enum_from_u32! {
|
||||
/// A representation of all the valid lang items in Rust.
|
||||
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash, Encodable, Decodable)]
|
||||
pub enum LangItem {
|
||||
$(
|
||||
#[doc = concat!("The `", stringify!($name), "` lang item.")]
|
||||
///
|
||||
$(#[$attr])*
|
||||
$variant,
|
||||
)*
|
||||
}
|
||||
/// A representation of all the valid lang items in Rust.
|
||||
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash, Encodable, Decodable)]
|
||||
pub enum LangItem {
|
||||
$(
|
||||
#[doc = concat!("The `", stringify!($name), "` lang item.")]
|
||||
$(#[$attr])*
|
||||
$variant,
|
||||
)*
|
||||
}
|
||||
|
||||
impl LangItem {
|
||||
fn from_u32(u: u32) -> Option<LangItem> {
|
||||
// This implementation is clumsy, but makes no assumptions
|
||||
// about how discriminant tags are allocated within the
|
||||
// range `0 .. std::mem::variant_count::<LangItem>()`.
|
||||
$(if u == LangItem::$variant as u32 {
|
||||
return Some(LangItem::$variant)
|
||||
})*
|
||||
None
|
||||
}
|
||||
|
||||
/// Returns the `name` symbol in `#[lang = "$name"]`.
|
||||
/// For example, [`LangItem::PartialEq`]`.name()`
|
||||
/// would result in [`sym::eq`] since it is `#[lang = "eq"]`.
|
||||
@ -147,7 +153,7 @@ language_item_table! {
|
||||
Clone, sym::clone, clone_trait, Target::Trait, GenericRequirement::None;
|
||||
Sync, sym::sync, sync_trait, Target::Trait, GenericRequirement::Exact(0);
|
||||
DiscriminantKind, sym::discriminant_kind, discriminant_kind_trait, Target::Trait, GenericRequirement::None;
|
||||
/// The associated item of the [`DiscriminantKind`] trait.
|
||||
/// The associated item of the `DiscriminantKind` trait.
|
||||
Discriminant, sym::discriminant_type, discriminant_type, Target::AssocTy, GenericRequirement::None;
|
||||
|
||||
PointeeTrait, sym::pointee_trait, pointee_trait, Target::Trait, GenericRequirement::None;
|
||||
|
Loading…
Reference in New Issue
Block a user