@@ -39,7 +39,7 @@ macro_rules! expand_group {
3939pub 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
5050impl 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( )
0 commit comments