@@ -191,15 +191,28 @@ pub(crate) fn load_attrs<'hir>(cx: &DocContext<'hir>, did: DefId) -> &'hir [ast:
191191 cx. tcx . get_attrs_unchecked ( did)
192192}
193193
194+ pub ( crate ) fn item_relative_path ( tcx : TyCtxt < ' _ > , def_id : DefId ) -> Vec < Symbol > {
195+ tcx. def_path ( def_id)
196+ . data
197+ . into_iter ( )
198+ . filter_map ( |elem| {
199+ // extern blocks (and a few others things) have an empty name.
200+ match elem. data . get_opt_name ( ) {
201+ Some ( s) if !s. is_empty ( ) => Some ( s) ,
202+ _ => None ,
203+ }
204+ } )
205+ . collect ( )
206+ }
207+
194208/// Record an external fully qualified name in the external_paths cache.
195209///
196210/// These names are used later on by HTML rendering to generate things like
197211/// source links back to the original item.
198212pub ( crate ) fn record_extern_fqn ( cx : & mut DocContext < ' _ > , did : DefId , kind : ItemType ) {
199213 let crate_name = cx. tcx . crate_name ( did. krate ) ;
200214
201- let relative =
202- cx. tcx . def_path ( did) . data . into_iter ( ) . filter_map ( |elem| elem. data . get_opt_name ( ) ) ;
215+ let relative = item_relative_path ( cx. tcx , did) ;
203216 let fqn = if let ItemType :: Macro = kind {
204217 // Check to see if it is a macro 2.0 or built-in macro
205218 if matches ! (
@@ -210,7 +223,7 @@ pub(crate) fn record_extern_fqn(cx: &mut DocContext<'_>, did: DefId, kind: ItemT
210223 ) {
211224 once ( crate_name) . chain ( relative) . collect ( )
212225 } else {
213- vec ! [ crate_name, relative. last( ) . expect( "relative was empty" ) ]
226+ vec ! [ crate_name, * relative. last( ) . expect( "relative was empty" ) ]
214227 }
215228 } else {
216229 once ( crate_name) . chain ( relative) . collect ( )
0 commit comments