@@ -46,6 +46,14 @@ enum_from_u32! {
46
46
}
47
47
}
48
48
49
+ impl LangItem {
50
+ fn name( self ) -> & ' static str {
51
+ match self {
52
+ $( $variant => $name, ) *
53
+ }
54
+ }
55
+ }
56
+
49
57
pub struct LanguageItems {
50
58
pub items: Vec <Option <DefId >>,
51
59
pub missing: Vec <LangItem >,
@@ -65,42 +73,17 @@ impl LanguageItems {
65
73
& * self . items
66
74
}
67
75
68
- pub fn item_name( index: usize ) -> & ' static str {
69
- let item: Option <LangItem > = LangItem :: from_u32( index as u32 ) ;
70
- match item {
71
- $( Some ( $variant) => $name, ) *
72
- None => "???"
73
- }
74
- }
75
-
76
76
pub fn require( & self , it: LangItem ) -> Result <DefId , String > {
77
- match self . items[ it as usize ] {
78
- Some ( id) => Ok ( id) ,
79
- None => {
80
- Err ( format!( "requires `{}` lang_item" ,
81
- LanguageItems :: item_name( it as usize ) ) )
82
- }
83
- }
84
- }
85
-
86
- pub fn require_owned_box( & self ) -> Result <DefId , String > {
87
- self . require( OwnedBoxLangItem )
77
+ self . items[ it as usize ] . ok_or_else( || format!( "requires `{}` lang_item" , it. name( ) ) )
88
78
}
89
79
90
80
pub fn fn_trait_kind( & self , id: DefId ) -> Option <ty:: ClosureKind > {
91
- let def_id_kinds = [
92
- ( self . fn_trait( ) , ty:: ClosureKind :: Fn ) ,
93
- ( self . fn_mut_trait( ) , ty:: ClosureKind :: FnMut ) ,
94
- ( self . fn_once_trait( ) , ty:: ClosureKind :: FnOnce ) ,
95
- ] ;
96
-
97
- for & ( opt_def_id, kind) in & def_id_kinds {
98
- if Some ( id) == opt_def_id {
99
- return Some ( kind) ;
100
- }
81
+ match Some ( id) {
82
+ x if x == self . fn_trait( ) => Some ( ty:: ClosureKind :: Fn ) ,
83
+ x if x == self . fn_mut_trait( ) => Some ( ty:: ClosureKind :: FnMut ) ,
84
+ x if x == self . fn_once_trait( ) => Some ( ty:: ClosureKind :: FnOnce ) ,
85
+ _ => None
101
86
}
102
-
103
- None
104
87
}
105
88
106
89
$(
@@ -162,7 +145,7 @@ impl<'a, 'tcx> LanguageItemCollector<'a, 'tcx> {
162
145
// Check for duplicates.
163
146
match self . items. items[ item_index] {
164
147
Some ( original_def_id) if original_def_id != item_def_id => {
165
- let name = LanguageItems :: item_name ( item_index) ;
148
+ let name = LangItem :: from_u32 ( item_index as u32 ) . unwrap ( ) . name ( ) ;
166
149
let mut err = match self . tcx. hir. span_if_local( item_def_id) {
167
150
Some ( span) => struct_span_err!(
168
151
self . tcx. sess,
@@ -327,14 +310,6 @@ language_item_table! {
327
310
328
311
PhantomDataItem , "phantom_data" , phantom_data;
329
312
330
- // Deprecated:
331
- CovariantTypeItem , "covariant_type" , covariant_type;
332
- ContravariantTypeItem , "contravariant_type" , contravariant_type;
333
- InvariantTypeItem , "invariant_type" , invariant_type;
334
- CovariantLifetimeItem , "covariant_lifetime" , covariant_lifetime;
335
- ContravariantLifetimeItem , "contravariant_lifetime" , contravariant_lifetime;
336
- InvariantLifetimeItem , "invariant_lifetime" , invariant_lifetime;
337
-
338
313
NonZeroItem , "non_zero" , non_zero;
339
314
340
315
DebugTraitLangItem , "debug_trait" , debug_trait;
0 commit comments