diff options
| author | Cameron Steffen <cam.steffen94@gmail.com> | 2022-10-26 16:18:46 -0500 |
|---|---|---|
| committer | Cameron Steffen <cam.steffen94@gmail.com> | 2022-10-29 16:04:10 -0500 |
| commit | 1e349fb0dd1fdd81e05bbcb8e7d6364d2c4c1f53 (patch) | |
| tree | 7dd954d6c7460518cf6efde91dfac75eb243168e | |
| parent | f808430497525663dd3f62c294a3ae1762abdc22 (diff) | |
| download | rust-1e349fb0dd1fdd81e05bbcb8e7d6364d2c4c1f53.tar.gz rust-1e349fb0dd1fdd81e05bbcb8e7d6364d2c4c1f53.zip | |
Use an array in LanguageItems
| -rw-r--r-- | compiler/rustc_hir/src/lang_items.rs | 25 | ||||
| -rw-r--r-- | compiler/rustc_hir/src/lib.rs | 1 |
2 files changed, 13 insertions, 13 deletions
diff --git a/compiler/rustc_hir/src/lang_items.rs b/compiler/rustc_hir/src/lang_items.rs index 9d1d84e32bb..672d3fdf28d 100644 --- a/compiler/rustc_hir/src/lang_items.rs +++ b/compiler/rustc_hir/src/lang_items.rs @@ -39,7 +39,7 @@ macro_rules! expand_group { pub struct LanguageItems { /// Mappings from lang items to their possibly found [`DefId`]s. /// The index corresponds to the order in [`LangItem`]. - items: Vec<Option<DefId>>, + items: [Option<DefId>; std::mem::variant_count::<LangItem>()], /// Lang items that were not found during collection. pub missing: Vec<LangItem>, /// Mapping from [`LangItemGroup`] discriminants to all @@ -48,6 +48,17 @@ pub struct LanguageItems { } impl LanguageItems { + /// Construct an empty collection of lang items and no missing ones. + pub fn new() -> Self { + const EMPTY: Vec<DefId> = Vec::new(); + + Self { + items: [None; std::mem::variant_count::<LangItem>()], + missing: Vec::new(), + groups: [EMPTY; NUM_GROUPS], + } + } + pub fn get(&self, item: LangItem) -> Option<DefId> { self.items[item as usize] } @@ -132,18 +143,6 @@ macro_rules! language_item_table { } impl LanguageItems { - /// Construct an empty collection of lang items and no missing ones. - pub fn new() -> Self { - fn init_none(_: LangItem) -> Option<DefId> { None } - const EMPTY: Vec<DefId> = Vec::new(); - - Self { - items: vec![$(init_none(LangItem::$variant)),*], - missing: Vec::new(), - groups: [EMPTY; NUM_GROUPS], - } - } - /// Returns the [`DefId`]s of all lang items in a group. pub fn group(&self, group: LangItemGroup) -> &[DefId] { self.groups[group as usize].as_ref() diff --git a/compiler/rustc_hir/src/lib.rs b/compiler/rustc_hir/src/lib.rs index 1c4aa420c9b..d54d8e84aaf 100644 --- a/compiler/rustc_hir/src/lib.rs +++ b/compiler/rustc_hir/src/lib.rs @@ -9,6 +9,7 @@ #![feature(min_specialization)] #![feature(never_type)] #![feature(rustc_attrs)] +#![feature(variant_count)] #![recursion_limit = "256"] #![deny(rustc::untranslatable_diagnostic)] #![deny(rustc::diagnostic_outside_of_impl)] |
