@@ -39,7 +39,7 @@ macro_rules! expand_group {
39
39
pub struct LanguageItems {
40
40
/// Mappings from lang items to their possibly found [`DefId`]s.
41
41
/// The index corresponds to the order in [`LangItem`].
42
- items : Vec < Option < DefId > > ,
42
+ items : [ Option < DefId > ; std :: mem :: variant_count :: < LangItem > ( ) ] ,
43
43
/// Lang items that were not found during collection.
44
44
pub missing : Vec < LangItem > ,
45
45
/// Mapping from [`LangItemGroup`] discriminants to all
@@ -48,6 +48,17 @@ pub struct LanguageItems {
48
48
}
49
49
50
50
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
+
51
62
pub fn get ( & self , item : LangItem ) -> Option < DefId > {
52
63
self . items [ item as usize ]
53
64
}
@@ -132,18 +143,6 @@ macro_rules! language_item_table {
132
143
}
133
144
134
145
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
-
147
146
/// Returns the [`DefId`]s of all lang items in a group.
148
147
pub fn group( & self , group: LangItemGroup ) -> & [ DefId ] {
149
148
self . groups[ group as usize ] . as_ref( )
0 commit comments