@@ -17,22 +17,6 @@ use rustc_macros::HashStable_Generic;
17
17
use rustc_span:: symbol:: { kw, sym, Symbol } ;
18
18
use rustc_span:: Span ;
19
19
20
- pub enum LangItemGroup {
21
- Op ,
22
- Fn ,
23
- }
24
-
25
- const NUM_GROUPS : usize = 2 ;
26
-
27
- macro_rules! expand_group {
28
- ( ) => {
29
- None
30
- } ;
31
- ( $group: expr) => {
32
- Some ( $group)
33
- } ;
34
- }
35
-
36
20
/// All of the language items, defined or not.
37
21
/// Defined lang items can come from the current crate or its dependencies.
38
22
#[ derive( HashStable_Generic , Debug ) ]
@@ -42,21 +26,12 @@ pub struct LanguageItems {
42
26
items : [ Option < DefId > ; std:: mem:: variant_count :: < LangItem > ( ) ] ,
43
27
/// Lang items that were not found during collection.
44
28
pub missing : Vec < LangItem > ,
45
- /// Mapping from [`LangItemGroup`] discriminants to all
46
- /// [`DefId`]s of lang items in that group.
47
- pub groups : [ Vec < DefId > ; NUM_GROUPS ] ,
48
29
}
49
30
50
31
impl LanguageItems {
51
32
/// Construct an empty collection of lang items and no missing ones.
52
33
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
- }
34
+ Self { items : [ None ; std:: mem:: variant_count :: < LangItem > ( ) ] , missing : Vec :: new ( ) }
60
35
}
61
36
62
37
pub fn get ( & self , item : LangItem ) -> Option < DefId > {
@@ -86,7 +61,7 @@ impl LanguageItems {
86
61
// So you probably just want to nip down to the end.
87
62
macro_rules! language_item_table {
88
63
(
89
- $( $( #[ $attr: meta] ) * $variant: ident $ ( $group : expr ) ? , $module: ident :: $name: ident, $method: ident, $target: expr, $generics: expr; ) *
64
+ $( $( #[ $attr: meta] ) * $variant: ident, $module: ident :: $name: ident, $method: ident, $target: expr, $generics: expr; ) *
90
65
) => {
91
66
92
67
enum_from_u32! {
@@ -120,15 +95,6 @@ macro_rules! language_item_table {
120
95
}
121
96
}
122
97
123
- /// The [group](LangItemGroup) that this lang item belongs to,
124
- /// or `None` if it doesn't belong to a group.
125
- pub fn group( self ) -> Option <LangItemGroup > {
126
- use LangItemGroup :: * ;
127
- match self {
128
- $( LangItem :: $variant => expand_group!( $( $group) * ) , ) *
129
- }
130
- }
131
-
132
98
pub fn target( self ) -> Target {
133
99
match self {
134
100
$( LangItem :: $variant => $target, ) *
@@ -143,11 +109,6 @@ macro_rules! language_item_table {
143
109
}
144
110
145
111
impl LanguageItems {
146
- /// Returns the [`DefId`]s of all lang items in a group.
147
- pub fn group( & self , group: LangItemGroup ) -> & [ DefId ] {
148
- self . groups[ group as usize ] . as_ref( )
149
- }
150
-
151
112
$(
152
113
#[ doc = concat!( "Returns the [`DefId`] of the `" , stringify!( $name) , "` lang item if it is defined." ) ]
153
114
pub fn $method( & self ) -> Option <DefId > {
@@ -209,30 +170,30 @@ language_item_table! {
209
170
TransmuteOpts , sym:: transmute_opts, transmute_opts, Target :: Struct , GenericRequirement :: Exact ( 0 ) ;
210
171
TransmuteTrait , sym:: transmute_trait, transmute_trait, Target :: Trait , GenericRequirement :: Exact ( 3 ) ;
211
172
212
- Add ( Op ) , sym:: add, add_trait, Target :: Trait , GenericRequirement :: Exact ( 1 ) ;
213
- Sub ( Op ) , sym:: sub, sub_trait, Target :: Trait , GenericRequirement :: Exact ( 1 ) ;
214
- Mul ( Op ) , sym:: mul, mul_trait, Target :: Trait , GenericRequirement :: Exact ( 1 ) ;
215
- Div ( Op ) , sym:: div, div_trait, Target :: Trait , GenericRequirement :: Exact ( 1 ) ;
216
- Rem ( Op ) , sym:: rem, rem_trait, Target :: Trait , GenericRequirement :: Exact ( 1 ) ;
217
- Neg ( Op ) , sym:: neg, neg_trait, Target :: Trait , GenericRequirement :: Exact ( 0 ) ;
218
- Not ( Op ) , sym:: not, not_trait, Target :: Trait , GenericRequirement :: Exact ( 0 ) ;
219
- BitXor ( Op ) , sym:: bitxor, bitxor_trait, Target :: Trait , GenericRequirement :: Exact ( 1 ) ;
220
- BitAnd ( Op ) , sym:: bitand, bitand_trait, Target :: Trait , GenericRequirement :: Exact ( 1 ) ;
221
- BitOr ( Op ) , sym:: bitor, bitor_trait, Target :: Trait , GenericRequirement :: Exact ( 1 ) ;
222
- Shl ( Op ) , sym:: shl, shl_trait, Target :: Trait , GenericRequirement :: Exact ( 1 ) ;
223
- Shr ( Op ) , sym:: shr, shr_trait, Target :: Trait , GenericRequirement :: Exact ( 1 ) ;
224
- AddAssign ( Op ) , sym:: add_assign, add_assign_trait, Target :: Trait , GenericRequirement :: Exact ( 1 ) ;
225
- SubAssign ( Op ) , sym:: sub_assign, sub_assign_trait, Target :: Trait , GenericRequirement :: Exact ( 1 ) ;
226
- MulAssign ( Op ) , sym:: mul_assign, mul_assign_trait, Target :: Trait , GenericRequirement :: Exact ( 1 ) ;
227
- DivAssign ( Op ) , sym:: div_assign, div_assign_trait, Target :: Trait , GenericRequirement :: Exact ( 1 ) ;
228
- RemAssign ( Op ) , sym:: rem_assign, rem_assign_trait, Target :: Trait , GenericRequirement :: Exact ( 1 ) ;
229
- BitXorAssign ( Op ) , sym:: bitxor_assign, bitxor_assign_trait, Target :: Trait , GenericRequirement :: Exact ( 1 ) ;
230
- BitAndAssign ( Op ) , sym:: bitand_assign, bitand_assign_trait, Target :: Trait , GenericRequirement :: Exact ( 1 ) ;
231
- BitOrAssign ( Op ) , sym:: bitor_assign, bitor_assign_trait, Target :: Trait , GenericRequirement :: Exact ( 1 ) ;
232
- ShlAssign ( Op ) , sym:: shl_assign, shl_assign_trait, Target :: Trait , GenericRequirement :: Exact ( 1 ) ;
233
- ShrAssign ( Op ) , sym:: shr_assign, shr_assign_trait, Target :: Trait , GenericRequirement :: Exact ( 1 ) ;
234
- Index ( Op ) , sym:: index, index_trait, Target :: Trait , GenericRequirement :: Exact ( 1 ) ;
235
- IndexMut ( Op ) , sym:: index_mut, index_mut_trait, Target :: Trait , GenericRequirement :: Exact ( 1 ) ;
173
+ Add , sym:: add, add_trait, Target :: Trait , GenericRequirement :: Exact ( 1 ) ;
174
+ Sub , sym:: sub, sub_trait, Target :: Trait , GenericRequirement :: Exact ( 1 ) ;
175
+ Mul , sym:: mul, mul_trait, Target :: Trait , GenericRequirement :: Exact ( 1 ) ;
176
+ Div , sym:: div, div_trait, Target :: Trait , GenericRequirement :: Exact ( 1 ) ;
177
+ Rem , sym:: rem, rem_trait, Target :: Trait , GenericRequirement :: Exact ( 1 ) ;
178
+ Neg , sym:: neg, neg_trait, Target :: Trait , GenericRequirement :: Exact ( 0 ) ;
179
+ Not , sym:: not, not_trait, Target :: Trait , GenericRequirement :: Exact ( 0 ) ;
180
+ BitXor , sym:: bitxor, bitxor_trait, Target :: Trait , GenericRequirement :: Exact ( 1 ) ;
181
+ BitAnd , sym:: bitand, bitand_trait, Target :: Trait , GenericRequirement :: Exact ( 1 ) ;
182
+ BitOr , sym:: bitor, bitor_trait, Target :: Trait , GenericRequirement :: Exact ( 1 ) ;
183
+ Shl , sym:: shl, shl_trait, Target :: Trait , GenericRequirement :: Exact ( 1 ) ;
184
+ Shr , sym:: shr, shr_trait, Target :: Trait , GenericRequirement :: Exact ( 1 ) ;
185
+ AddAssign , sym:: add_assign, add_assign_trait, Target :: Trait , GenericRequirement :: Exact ( 1 ) ;
186
+ SubAssign , sym:: sub_assign, sub_assign_trait, Target :: Trait , GenericRequirement :: Exact ( 1 ) ;
187
+ MulAssign , sym:: mul_assign, mul_assign_trait, Target :: Trait , GenericRequirement :: Exact ( 1 ) ;
188
+ DivAssign , sym:: div_assign, div_assign_trait, Target :: Trait , GenericRequirement :: Exact ( 1 ) ;
189
+ RemAssign , sym:: rem_assign, rem_assign_trait, Target :: Trait , GenericRequirement :: Exact ( 1 ) ;
190
+ BitXorAssign , sym:: bitxor_assign, bitxor_assign_trait, Target :: Trait , GenericRequirement :: Exact ( 1 ) ;
191
+ BitAndAssign , sym:: bitand_assign, bitand_assign_trait, Target :: Trait , GenericRequirement :: Exact ( 1 ) ;
192
+ BitOrAssign , sym:: bitor_assign, bitor_assign_trait, Target :: Trait , GenericRequirement :: Exact ( 1 ) ;
193
+ ShlAssign , sym:: shl_assign, shl_assign_trait, Target :: Trait , GenericRequirement :: Exact ( 1 ) ;
194
+ ShrAssign , sym:: shr_assign, shr_assign_trait, Target :: Trait , GenericRequirement :: Exact ( 1 ) ;
195
+ Index , sym:: index, index_trait, Target :: Trait , GenericRequirement :: Exact ( 1 ) ;
196
+ IndexMut , sym:: index_mut, index_mut_trait, Target :: Trait , GenericRequirement :: Exact ( 1 ) ;
236
197
237
198
UnsafeCell , sym:: unsafe_cell, unsafe_cell_type, Target :: Struct , GenericRequirement :: None ;
238
199
VaList , sym:: va_list, va_list, Target :: Struct , GenericRequirement :: None ;
@@ -242,9 +203,9 @@ language_item_table! {
242
203
DerefTarget , sym:: deref_target, deref_target, Target :: AssocTy , GenericRequirement :: None ;
243
204
Receiver , sym:: receiver, receiver_trait, Target :: Trait , GenericRequirement :: None ;
244
205
245
- Fn ( Fn ) , kw:: Fn , fn_trait, Target :: Trait , GenericRequirement :: Exact ( 1 ) ;
246
- FnMut ( Fn ) , sym:: fn_mut, fn_mut_trait, Target :: Trait , GenericRequirement :: Exact ( 1 ) ;
247
- FnOnce ( Fn ) , sym:: fn_once, fn_once_trait, Target :: Trait , GenericRequirement :: Exact ( 1 ) ;
206
+ Fn , kw:: Fn , fn_trait, Target :: Trait , GenericRequirement :: Exact ( 1 ) ;
207
+ FnMut , sym:: fn_mut, fn_mut_trait, Target :: Trait , GenericRequirement :: Exact ( 1 ) ;
208
+ FnOnce , sym:: fn_once, fn_once_trait, Target :: Trait , GenericRequirement :: Exact ( 1 ) ;
248
209
249
210
FnOnceOutput , sym:: fn_once_output, fn_once_output, Target :: AssocTy , GenericRequirement :: None ;
250
211
@@ -254,8 +215,8 @@ language_item_table! {
254
215
Unpin , sym:: unpin, unpin_trait, Target :: Trait , GenericRequirement :: None ;
255
216
Pin , sym:: pin, pin_type, Target :: Struct , GenericRequirement :: None ;
256
217
257
- PartialEq ( Op ) , sym:: eq, eq_trait, Target :: Trait , GenericRequirement :: Exact ( 1 ) ;
258
- PartialOrd ( Op ) , sym:: partial_ord, partial_ord_trait, Target :: Trait , GenericRequirement :: Exact ( 1 ) ;
218
+ PartialEq , sym:: eq, eq_trait, Target :: Trait , GenericRequirement :: Exact ( 1 ) ;
219
+ PartialOrd , sym:: partial_ord, partial_ord_trait, Target :: Trait , GenericRequirement :: Exact ( 1 ) ;
259
220
260
221
// A number of panic-related lang items. The `panic` item corresponds to divide-by-zero and
261
222
// various panic cases with `match`. The `panic_bounds_check` item is for indexing arrays.
@@ -351,3 +312,34 @@ pub enum GenericRequirement {
351
312
Minimum ( usize ) ,
352
313
Exact ( usize ) ,
353
314
}
315
+
316
+ pub static FN_TRAITS : & ' static [ LangItem ] = & [ LangItem :: Fn , LangItem :: FnMut , LangItem :: FnOnce ] ;
317
+
318
+ pub static OPERATORS : & ' static [ LangItem ] = & [
319
+ LangItem :: Add ,
320
+ LangItem :: Sub ,
321
+ LangItem :: Mul ,
322
+ LangItem :: Div ,
323
+ LangItem :: Rem ,
324
+ LangItem :: Neg ,
325
+ LangItem :: Not ,
326
+ LangItem :: BitXor ,
327
+ LangItem :: BitAnd ,
328
+ LangItem :: BitOr ,
329
+ LangItem :: Shl ,
330
+ LangItem :: Shr ,
331
+ LangItem :: AddAssign ,
332
+ LangItem :: SubAssign ,
333
+ LangItem :: MulAssign ,
334
+ LangItem :: DivAssign ,
335
+ LangItem :: RemAssign ,
336
+ LangItem :: BitXorAssign ,
337
+ LangItem :: BitAndAssign ,
338
+ LangItem :: BitOrAssign ,
339
+ LangItem :: ShlAssign ,
340
+ LangItem :: ShrAssign ,
341
+ LangItem :: Index ,
342
+ LangItem :: IndexMut ,
343
+ LangItem :: PartialEq ,
344
+ LangItem :: PartialOrd ,
345
+ ] ;
0 commit comments