@@ -2,7 +2,7 @@ use crate::clean::auto_trait::AutoTraitFinder;
2
2
use crate :: clean:: blanket_impl:: BlanketImplFinder ;
3
3
use crate :: clean:: {
4
4
inline, Clean , Crate , Generic , GenericArg , GenericArgs , ImportSource , Item , ItemKind , Lifetime ,
5
- MacroKind , Path , PathSegment , Primitive , PrimitiveType , ResolvedPath , Type , TypeBinding ,
5
+ Path , PathSegment , Primitive , PrimitiveType , ResolvedPath , Type , TypeBinding ,
6
6
} ;
7
7
use crate :: core:: DocContext ;
8
8
use crate :: formats:: item_type:: ItemType ;
@@ -451,35 +451,48 @@ crate fn get_auto_trait_and_blanket_impls(
451
451
auto_impls. into_iter ( ) . chain ( blanket_impls)
452
452
}
453
453
454
+ /// If `res` has a documentation page associated, store it in the cache.
455
+ ///
456
+ /// This is later used by [`href()`] to determine the HTML link for the item.
457
+ ///
458
+ /// [`href()`]: crate::html::format::href
454
459
crate fn register_res ( cx : & mut DocContext < ' _ > , res : Res ) -> DefId {
460
+ use DefKind :: * ;
455
461
debug ! ( "register_res({:?})" , res) ;
456
462
457
463
let ( did, kind) = match res {
458
- Res :: Def ( DefKind :: Fn , i) => ( i, ItemType :: Function ) ,
459
- Res :: Def ( DefKind :: TyAlias , i) => ( i, ItemType :: Typedef ) ,
460
- Res :: Def ( DefKind :: Enum , i) => ( i, ItemType :: Enum ) ,
461
- Res :: Def ( DefKind :: Trait , i) => ( i, ItemType :: Trait ) ,
462
464
Res :: Def ( DefKind :: AssocTy | DefKind :: AssocFn | DefKind :: AssocConst , i) => {
465
+ // associated items are documented, but on the page of their parent
463
466
( cx. tcx . parent ( i) . unwrap ( ) , ItemType :: Trait )
464
467
}
465
- Res :: Def ( DefKind :: Struct , i) => ( i, ItemType :: Struct ) ,
466
- Res :: Def ( DefKind :: Union , i) => ( i, ItemType :: Union ) ,
467
- Res :: Def ( DefKind :: Mod , i) => ( i, ItemType :: Module ) ,
468
- Res :: Def ( DefKind :: ForeignTy , i) => ( i, ItemType :: ForeignType ) ,
469
- Res :: Def ( DefKind :: Const , i) => ( i, ItemType :: Constant ) ,
470
- Res :: Def ( DefKind :: Static , i) => ( i, ItemType :: Static ) ,
471
468
Res :: Def ( DefKind :: Variant , i) => {
469
+ // variant items are documented, but on the page of their parent
472
470
( cx. tcx . parent ( i) . expect ( "cannot get parent def id" ) , ItemType :: Enum )
473
471
}
474
- Res :: Def ( DefKind :: Macro ( mac_kind) , i) => match mac_kind {
475
- MacroKind :: Bang => ( i, ItemType :: Macro ) ,
476
- MacroKind :: Attr => ( i, ItemType :: ProcAttribute ) ,
477
- MacroKind :: Derive => ( i, ItemType :: ProcDerive ) ,
478
- } ,
479
- Res :: Def ( DefKind :: TraitAlias , i) => ( i, ItemType :: TraitAlias ) ,
480
- Res :: SelfTy ( Some ( def_id) , _) => ( def_id, ItemType :: Trait ) ,
481
- Res :: SelfTy ( _, Some ( ( impl_def_id, _) ) ) => return impl_def_id,
482
- _ => return res. def_id ( ) ,
472
+ // Each of these have their own page.
473
+ Res :: Def (
474
+ kind
475
+ @
476
+ ( Fn | TyAlias | Enum | Trait | Struct | Union | Mod | ForeignTy | Const | Static
477
+ | Macro ( ..) | TraitAlias ) ,
478
+ i,
479
+ ) => ( i, kind. into ( ) ) ,
480
+ // This is part of a trait definition; document the trait.
481
+ Res :: SelfTy ( Some ( trait_def_id) , _) => ( trait_def_id, ItemType :: Trait ) ,
482
+ // This is an inherent impl; it doesn't have its own page.
483
+ Res :: SelfTy ( None , Some ( ( impl_def_id, _) ) ) => return impl_def_id,
484
+ Res :: SelfTy ( None , None )
485
+ | Res :: PrimTy ( _)
486
+ | Res :: ToolMod
487
+ | Res :: SelfCtor ( _)
488
+ | Res :: Local ( _)
489
+ | Res :: NonMacroAttr ( _)
490
+ | Res :: Err => return res. def_id ( ) ,
491
+ Res :: Def (
492
+ TyParam | ConstParam | Ctor ( ..) | ExternCrate | Use | ForeignMod | AnonConst | OpaqueTy
493
+ | Field | LifetimeParam | GlobalAsm | Impl | Closure | Generator ,
494
+ id,
495
+ ) => return id,
483
496
} ;
484
497
if did. is_local ( ) {
485
498
return did;
0 commit comments