From 1e349fb0dd1fdd81e05bbcb8e7d6364d2c4c1f53 Mon Sep 17 00:00:00 2001 From: Cameron Steffen Date: Wed, 26 Oct 2022 16:18:46 -0500 Subject: [PATCH] Use an array in LanguageItems --- compiler/rustc_hir/src/lang_items.rs | 25 ++++++++++++------------- 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>, + items: [Option; std::mem::variant_count::()], /// Lang items that were not found during collection. pub missing: Vec, /// 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 = Vec::new(); + + Self { + items: [None; std::mem::variant_count::()], + missing: Vec::new(), + groups: [EMPTY; NUM_GROUPS], + } + } + pub fn get(&self, item: LangItem) -> Option { 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 { None } - const EMPTY: Vec = 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)]