@@ -28,76 +28,76 @@ macro_rules! language_item_table {
28
28
$( $variant: ident, $name: expr, $method: ident, $target: path; ) *
29
29
) => {
30
30
31
- enum_from_u32! {
32
- /// A representation of all the valid language items in Rust.
33
- #[ derive( Debug , Copy , Clone , PartialEq , Eq , Hash , RustcEncodable , RustcDecodable ) ]
34
- pub enum LangItem {
35
- $( $variant, ) *
36
- }
37
- }
38
-
39
- impl LangItem {
40
- /// Returns the `name` in `#[lang = "$name"]`.
41
- /// For example, `LangItem::EqTraitLangItem`,
42
- /// that is `#[lang = "eq"]` would result in `"eq"`.
43
- pub fn name( self ) -> & ' static str {
44
- match self {
45
- $( $variant => $name, ) *
31
+ enum_from_u32! {
32
+ /// A representation of all the valid language items in Rust.
33
+ #[ derive( Debug , Copy , Clone , PartialEq , Eq , Hash , RustcEncodable , RustcDecodable ) ]
34
+ pub enum LangItem {
35
+ $( $variant, ) *
36
+ }
46
37
}
47
- }
48
- }
49
-
50
- #[ derive( HashStable_Generic ) ]
51
- pub struct LanguageItems {
52
- /// Mappings from lang items to their possibly found `DefId`s.
53
- /// The index corresponds to the order in `LangItem`.
54
- pub items: Vec <Option <DefId >>,
55
- /// Lang items that were not found during collection.
56
- pub missing: Vec <LangItem >,
57
- }
58
-
59
- impl LanguageItems {
60
- /// Construct an empty collection of lang items and no missing ones.
61
- pub fn new( ) -> Self {
62
- fn init_none( _: LangItem ) -> Option <DefId > { None }
63
38
64
- Self {
65
- items: vec![ $( init_none( $variant) ) ,* ] ,
66
- missing: Vec :: new( ) ,
39
+ impl LangItem {
40
+ /// Returns the `name` in `#[lang = "$name"]`.
41
+ /// For example, `LangItem::EqTraitLangItem`,
42
+ /// that is `#[lang = "eq"]` would result in `"eq"`.
43
+ pub fn name( self ) -> & ' static str {
44
+ match self {
45
+ $( $variant => $name, ) *
46
+ }
47
+ }
67
48
}
68
- }
69
-
70
- /// Returns the mappings to the possibly found `DefId`s for each lang item.
71
- pub fn items( & self ) -> & [ Option <DefId >] {
72
- & * self . items
73
- }
74
49
75
- /// Requires that a given `LangItem` was bound and returns the corresponding `DefId`.
76
- /// If it wasn't bound, e.g. due to a missing `#[lang = "<it.name()>"]`,
77
- /// returns an error message as a string.
78
- pub fn require( & self , it: LangItem ) -> Result <DefId , String > {
79
- self . items[ it as usize ] . ok_or_else( || format!( "requires `{}` lang_item" , it. name( ) ) )
80
- }
50
+ #[ derive( HashStable_Generic ) ]
51
+ pub struct LanguageItems {
52
+ /// Mappings from lang items to their possibly found `DefId`s.
53
+ /// The index corresponds to the order in `LangItem`.
54
+ pub items: Vec <Option <DefId >>,
55
+ /// Lang items that were not found during collection.
56
+ pub missing: Vec <LangItem >,
57
+ }
81
58
82
- $(
83
- /// Returns the corresponding `DefId` for the lang item
84
- #[ doc = $name]
85
- /// if it exists.
86
- #[ allow( dead_code) ]
87
- pub fn $method( & self ) -> Option <DefId > {
88
- self . items[ $variant as usize ]
59
+ impl LanguageItems {
60
+ /// Construct an empty collection of lang items and no missing ones.
61
+ pub fn new( ) -> Self {
62
+ fn init_none( _: LangItem ) -> Option <DefId > { None }
63
+
64
+ Self {
65
+ items: vec![ $( init_none( $variant) ) ,* ] ,
66
+ missing: Vec :: new( ) ,
67
+ }
68
+ }
69
+
70
+ /// Returns the mappings to the possibly found `DefId`s for each lang item.
71
+ pub fn items( & self ) -> & [ Option <DefId >] {
72
+ & * self . items
73
+ }
74
+
75
+ /// Requires that a given `LangItem` was bound and returns the corresponding `DefId`.
76
+ /// If it wasn't bound, e.g. due to a missing `#[lang = "<it.name()>"]`,
77
+ /// returns an error message as a string.
78
+ pub fn require( & self , it: LangItem ) -> Result <DefId , String > {
79
+ self . items[ it as usize ] . ok_or_else( || format!( "requires `{}` lang_item" , it. name( ) ) )
80
+ }
81
+
82
+ $(
83
+ /// Returns the corresponding `DefId` for the lang item
84
+ #[ doc = $name]
85
+ /// if it exists.
86
+ #[ allow( dead_code) ]
87
+ pub fn $method( & self ) -> Option <DefId > {
88
+ self . items[ $variant as usize ]
89
+ }
90
+ ) *
89
91
}
90
- ) *
91
- }
92
92
93
- lazy_static! {
94
- /// A mapping from the name of the lang item to its order and the form it must be of.
95
- pub static ref ITEM_REFS : FxHashMap <& ' static str , ( usize , Target ) > = {
96
- let mut item_refs = FxHashMap :: default ( ) ;
97
- $( item_refs. insert( $name, ( $variant as usize , $target) ) ; ) *
98
- item_refs
99
- } ;
100
- }
93
+ lazy_static! {
94
+ /// A mapping from the name of the lang item to its order and the form it must be of.
95
+ pub static ref ITEM_REFS : FxHashMap <& ' static str , ( usize , Target ) > = {
96
+ let mut item_refs = FxHashMap :: default ( ) ;
97
+ $( item_refs. insert( $name, ( $variant as usize , $target) ) ; ) *
98
+ item_refs
99
+ } ;
100
+ }
101
101
102
102
// End of the macro
103
103
}
0 commit comments