Skip to content

Commit 1e349fb

Browse files
committed
Use an array in LanguageItems
1 parent f808430 commit 1e349fb

File tree

2 files changed

+13
-13
lines changed

2 files changed

+13
-13
lines changed

compiler/rustc_hir/src/lang_items.rs

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ macro_rules! expand_group {
3939
pub struct LanguageItems {
4040
/// Mappings from lang items to their possibly found [`DefId`]s.
4141
/// The index corresponds to the order in [`LangItem`].
42-
items: Vec<Option<DefId>>,
42+
items: [Option<DefId>; std::mem::variant_count::<LangItem>()],
4343
/// Lang items that were not found during collection.
4444
pub missing: Vec<LangItem>,
4545
/// Mapping from [`LangItemGroup`] discriminants to all
@@ -48,6 +48,17 @@ pub struct LanguageItems {
4848
}
4949

5050
impl LanguageItems {
51+
/// Construct an empty collection of lang items and no missing ones.
52+
pub fn new() -> Self {
53+
const EMPTY: Vec<DefId> = Vec::new();
54+
55+
Self {
56+
items: [None; std::mem::variant_count::<LangItem>()],
57+
missing: Vec::new(),
58+
groups: [EMPTY; NUM_GROUPS],
59+
}
60+
}
61+
5162
pub fn get(&self, item: LangItem) -> Option<DefId> {
5263
self.items[item as usize]
5364
}
@@ -132,18 +143,6 @@ macro_rules! language_item_table {
132143
}
133144

134145
impl LanguageItems {
135-
/// Construct an empty collection of lang items and no missing ones.
136-
pub fn new() -> Self {
137-
fn init_none(_: LangItem) -> Option<DefId> { None }
138-
const EMPTY: Vec<DefId> = Vec::new();
139-
140-
Self {
141-
items: vec![$(init_none(LangItem::$variant)),*],
142-
missing: Vec::new(),
143-
groups: [EMPTY; NUM_GROUPS],
144-
}
145-
}
146-
147146
/// Returns the [`DefId`]s of all lang items in a group.
148147
pub fn group(&self, group: LangItemGroup) -> &[DefId] {
149148
self.groups[group as usize].as_ref()

compiler/rustc_hir/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#![feature(min_specialization)]
1010
#![feature(never_type)]
1111
#![feature(rustc_attrs)]
12+
#![feature(variant_count)]
1213
#![recursion_limit = "256"]
1314
#![deny(rustc::untranslatable_diagnostic)]
1415
#![deny(rustc::diagnostic_outside_of_impl)]

0 commit comments

Comments
 (0)