@@ -46,6 +46,14 @@ enum_from_u32! {
4646 }
4747}
4848
49+ impl LangItem {
50+ fn name( self ) -> & ' static str {
51+ match self {
52+ $( $variant => $name, ) *
53+ }
54+ }
55+ }
56+
4957pub struct LanguageItems {
5058 pub items: Vec <Option <DefId >>,
5159 pub missing: Vec <LangItem >,
@@ -65,42 +73,17 @@ impl LanguageItems {
6573 & * self . items
6674 }
6775
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-
7676 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( ) ) )
8878 }
8979
9080 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
10186 }
102-
103- None
10487 }
10588
10689 $(
@@ -162,7 +145,7 @@ impl<'a, 'tcx> LanguageItemCollector<'a, 'tcx> {
162145 // Check for duplicates.
163146 match self . items. items[ item_index] {
164147 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 ( ) ;
166149 let mut err = match self . tcx. hir. span_if_local( item_def_id) {
167150 Some ( span) => struct_span_err!(
168151 self . tcx. sess,
@@ -327,14 +310,6 @@ language_item_table! {
327310
328311 PhantomDataItem , "phantom_data" , phantom_data;
329312
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-
338313 NonZeroItem , "non_zero" , non_zero;
339314
340315 DebugTraitLangItem , "debug_trait" , debug_trait;
0 commit comments