@@ -38,27 +38,34 @@ macro_rules! expand_group {
38
38
// So you probably just want to nip down to the end.
39
39
macro_rules! language_item_table {
40
40
(
41
- $( $variant: ident $( $group: expr) ?, $name: expr , $method: ident, $target: expr; ) *
41
+ $( $( # [ $attr : meta ] ) * $ variant: ident $( $group: expr) ?, $module : ident :: $ name: ident , $method: ident, $target: expr; ) *
42
42
) => {
43
43
44
44
enum_from_u32! {
45
45
/// A representation of all the valid language items in Rust.
46
46
#[ derive( Debug , Copy , Clone , PartialEq , Eq , Hash , Encodable , Decodable ) ]
47
47
pub enum LangItem {
48
- $( $variant, ) *
48
+ $(
49
+ #[ doc = concat!( "The `" , stringify!( $name) , "` lang item." ) ]
50
+ ///
51
+ $( #[ $attr] ) *
52
+ $variant,
53
+ ) *
49
54
}
50
55
}
51
56
52
57
impl LangItem {
53
58
/// Returns the `name` symbol in `#[lang = "$name"]`.
54
- /// For example, `LangItem::EqTraitLangItem`,
55
- /// that is `#[lang = "eq"]` would result in `sym::eq `.
59
+ /// For example, [ `LangItem::PartialEq`]`.name()`
60
+ /// would result in [`sym::eq`] since it is `#[lang = "eq"]`.
56
61
pub fn name( self ) -> Symbol {
57
62
match self {
58
- $( LangItem :: $variant => $name, ) *
63
+ $( LangItem :: $variant => $module :: $ name, ) *
59
64
}
60
65
}
61
66
67
+ /// The [group](LangItemGroup) that this lang item belongs to,
68
+ /// or `None` if it doesn't belong to a group.
62
69
pub fn group( self ) -> Option <LangItemGroup > {
63
70
use LangItemGroup :: * ;
64
71
match self {
@@ -67,15 +74,17 @@ macro_rules! language_item_table {
67
74
}
68
75
}
69
76
77
+ /// All of the language items, defined or not.
78
+ /// Defined lang items can come from the current crate or its dependencies.
70
79
#[ derive( HashStable_Generic , Debug ) ]
71
80
pub struct LanguageItems {
72
- /// Mappings from lang items to their possibly found `DefId`s.
73
- /// The index corresponds to the order in `LangItem`.
81
+ /// Mappings from lang items to their possibly found [ `DefId`] s.
82
+ /// The index corresponds to the order in [ `LangItem`] .
74
83
pub items: Vec <Option <DefId >>,
75
84
/// Lang items that were not found during collection.
76
85
pub missing: Vec <LangItem >,
77
- /// Mapping from `LangItemGroup` discriminants to all
78
- /// `DefId`s of lang items in that group.
86
+ /// Mapping from [ `LangItemGroup`] discriminants to all
87
+ /// [ `DefId`] s of lang items in that group.
79
88
pub groups: [ Vec <DefId >; NUM_GROUPS ] ,
80
89
}
81
90
@@ -103,14 +112,13 @@ macro_rules! language_item_table {
103
112
self . items[ it as usize ] . ok_or_else( || format!( "requires `{}` lang_item" , it. name( ) ) )
104
113
}
105
114
115
+ /// Returns the [`DefId`]s of all lang items in a group.
106
116
pub fn group( & self , group: LangItemGroup ) -> & [ DefId ] {
107
117
self . groups[ group as usize ] . as_ref( )
108
118
}
109
119
110
120
$(
111
- /// Returns the corresponding `DefId` for the lang item if it
112
- /// exists.
113
- #[ allow( dead_code) ]
121
+ #[ doc = concat!( "Returns the [`DefId`] of the `" , stringify!( $name) , "` lang item if it is defined." ) ]
114
122
pub fn $method( & self ) -> Option <DefId > {
115
123
self . items[ LangItem :: $variant as usize ]
116
124
}
@@ -120,7 +128,7 @@ macro_rules! language_item_table {
120
128
/// A mapping from the name of the lang item to its order and the form it must be of.
121
129
pub static ITEM_REFS : SyncLazy <FxHashMap <Symbol , ( usize , Target ) >> = SyncLazy :: new( || {
122
130
let mut item_refs = FxHashMap :: default ( ) ;
123
- $( item_refs. insert( $name, ( LangItem :: $variant as usize , $target) ) ; ) *
131
+ $( item_refs. insert( $module :: $ name, ( LangItem :: $variant as usize , $target) ) ; ) *
124
132
item_refs
125
133
} ) ;
126
134
@@ -140,7 +148,7 @@ impl<CTX> HashStable<CTX> for LangItem {
140
148
///
141
149
/// About the `check_name` argument: passing in a `Session` would be simpler,
142
150
/// because then we could call `Session::check_name` directly. But we want to
143
- /// avoid the need for `librustc_hir ` to depend on `librustc_session `, so we
151
+ /// avoid the need for `rustc_hir ` to depend on `rustc_session `, so we
144
152
/// use a closure instead.
145
153
pub fn extract < ' a , F > ( check_name : F , attrs : & ' a [ ast:: Attribute ] ) -> Option < ( Symbol , Span ) >
146
154
where
@@ -190,15 +198,15 @@ language_item_table! {
190
198
191
199
Sized , sym:: sized, sized_trait, Target :: Trait ;
192
200
Unsize , sym:: unsize, unsize_trait, Target :: Trait ;
193
- // Trait injected by #[derive(PartialEq)], (i.e. "Partial EQ").
201
+ /// Trait injected by ` #[derive(PartialEq)]` , (i.e. "Partial EQ").
194
202
StructuralPeq , sym:: structural_peq, structural_peq_trait, Target :: Trait ;
195
- // Trait injected by #[derive(Eq)], (i.e. "Total EQ"; no, I will not apologize).
203
+ /// Trait injected by ` #[derive(Eq)]` , (i.e. "Total EQ"; no, I will not apologize).
196
204
StructuralTeq , sym:: structural_teq, structural_teq_trait, Target :: Trait ;
197
205
Copy , sym:: copy, copy_trait, Target :: Trait ;
198
206
Clone , sym:: clone, clone_trait, Target :: Trait ;
199
207
Sync , sym:: sync, sync_trait, Target :: Trait ;
200
208
DiscriminantKind , sym:: discriminant_kind, discriminant_kind_trait, Target :: Trait ;
201
- // The associated item of `trait DiscriminantKind`.
209
+ /// The associated item of the [` DiscriminantKind`] trait .
202
210
Discriminant , sym:: discriminant_type, discriminant_type, Target :: AssocTy ;
203
211
204
212
PointeeTrait , sym:: pointee_trait, pointee_trait, Target :: Trait ;
@@ -273,7 +281,7 @@ language_item_table! {
273
281
PanicInfo , sym:: panic_info, panic_info, Target :: Struct ;
274
282
PanicLocation , sym:: panic_location, panic_location, Target :: Struct ;
275
283
PanicImpl , sym:: panic_impl, panic_impl, Target :: Fn ;
276
- // libstd panic entry point. Necessary for const eval to be able to catch it
284
+ /// libstd panic entry point. Necessary for const eval to be able to catch it
277
285
BeginPanic , sym:: begin_panic, begin_panic_fn, Target :: Fn ;
278
286
279
287
ExchangeMalloc , sym:: exchange_malloc, exchange_malloc_fn, Target :: Fn ;
@@ -295,7 +303,7 @@ language_item_table! {
295
303
296
304
MaybeUninit , sym:: maybe_uninit, maybe_uninit, Target :: Union ;
297
305
298
- // Align offset for stride != 1; must not panic.
306
+ /// Align offset for stride != 1; must not panic.
299
307
AlignOffset , sym:: align_offset, align_offset_fn, Target :: Fn ;
300
308
301
309
Termination , sym:: termination, termination, Target :: Trait ;
0 commit comments