@@ -38,27 +38,34 @@ macro_rules! expand_group {
3838// So you probably just want to nip down to the end.
3939macro_rules! language_item_table {
4040 (
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; ) *
4242 ) => {
4343
4444 enum_from_u32! {
4545 /// A representation of all the valid language items in Rust.
4646 #[ derive( Debug , Copy , Clone , PartialEq , Eq , Hash , Encodable , Decodable ) ]
4747 pub enum LangItem {
48- $( $variant, ) *
48+ $(
49+ #[ doc = concat!( "The `" , stringify!( $name) , "` lang item." ) ]
50+ ///
51+ $( #[ $attr] ) *
52+ $variant,
53+ ) *
4954 }
5055 }
5156
5257 impl LangItem {
5358 /// 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"]`.
5661 pub fn name( self ) -> Symbol {
5762 match self {
58- $( LangItem :: $variant => $name, ) *
63+ $( LangItem :: $variant => $module :: $ name, ) *
5964 }
6065 }
6166
67+ /// The [group](LangItemGroup) that this lang item belongs to,
68+ /// or `None` if it doesn't belong to a group.
6269 pub fn group( self ) -> Option <LangItemGroup > {
6370 use LangItemGroup :: * ;
6471 match self {
@@ -67,15 +74,17 @@ macro_rules! language_item_table {
6774 }
6875 }
6976
77+ /// All of the language items, defined or not.
78+ /// Defined lang items can come from the current crate or its dependencies.
7079 #[ derive( HashStable_Generic , Debug ) ]
7180 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`] .
7483 pub items: Vec <Option <DefId >>,
7584 /// Lang items that were not found during collection.
7685 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.
7988 pub groups: [ Vec <DefId >; NUM_GROUPS ] ,
8089 }
8190
@@ -103,14 +112,13 @@ macro_rules! language_item_table {
103112 self . items[ it as usize ] . ok_or_else( || format!( "requires `{}` lang_item" , it. name( ) ) )
104113 }
105114
115+ /// Returns the [`DefId`]s of all lang items in a group.
106116 pub fn group( & self , group: LangItemGroup ) -> & [ DefId ] {
107117 self . groups[ group as usize ] . as_ref( )
108118 }
109119
110120 $(
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." ) ]
114122 pub fn $method( & self ) -> Option <DefId > {
115123 self . items[ LangItem :: $variant as usize ]
116124 }
@@ -120,7 +128,7 @@ macro_rules! language_item_table {
120128 /// A mapping from the name of the lang item to its order and the form it must be of.
121129 pub static ITEM_REFS : SyncLazy <FxHashMap <Symbol , ( usize , Target ) >> = SyncLazy :: new( || {
122130 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) ) ; ) *
124132 item_refs
125133 } ) ;
126134
@@ -140,7 +148,7 @@ impl<CTX> HashStable<CTX> for LangItem {
140148///
141149/// About the `check_name` argument: passing in a `Session` would be simpler,
142150/// 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
144152/// use a closure instead.
145153pub fn extract < ' a , F > ( check_name : F , attrs : & ' a [ ast:: Attribute ] ) -> Option < ( Symbol , Span ) >
146154where
@@ -190,15 +198,15 @@ language_item_table! {
190198
191199 Sized , sym:: sized, sized_trait, Target :: Trait ;
192200 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").
194202 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).
196204 StructuralTeq , sym:: structural_teq, structural_teq_trait, Target :: Trait ;
197205 Copy , sym:: copy, copy_trait, Target :: Trait ;
198206 Clone , sym:: clone, clone_trait, Target :: Trait ;
199207 Sync , sym:: sync, sync_trait, Target :: Trait ;
200208 DiscriminantKind , sym:: discriminant_kind, discriminant_kind_trait, Target :: Trait ;
201- // The associated item of `trait DiscriminantKind`.
209+ /// The associated item of the [` DiscriminantKind`] trait .
202210 Discriminant , sym:: discriminant_type, discriminant_type, Target :: AssocTy ;
203211
204212 PointeeTrait , sym:: pointee_trait, pointee_trait, Target :: Trait ;
@@ -273,7 +281,7 @@ language_item_table! {
273281 PanicInfo , sym:: panic_info, panic_info, Target :: Struct ;
274282 PanicLocation , sym:: panic_location, panic_location, Target :: Struct ;
275283 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
277285 BeginPanic , sym:: begin_panic, begin_panic_fn, Target :: Fn ;
278286
279287 ExchangeMalloc , sym:: exchange_malloc, exchange_malloc_fn, Target :: Fn ;
@@ -295,7 +303,7 @@ language_item_table! {
295303
296304 MaybeUninit , sym:: maybe_uninit, maybe_uninit, Target :: Union ;
297305
298- // Align offset for stride != 1; must not panic.
306+ /// Align offset for stride != 1; must not panic.
299307 AlignOffset , sym:: align_offset, align_offset_fn, Target :: Fn ;
300308
301309 Termination , sym:: termination, termination, Target :: Trait ;
0 commit comments