@@ -487,21 +487,38 @@ impl Item {
487
487
let Some ( links) = cx. cache ( ) . intra_doc_links . get ( & self . item_id ) else { return vec ! [ ] } ;
488
488
links
489
489
. iter ( )
490
- . filter_map ( |ItemLink { link : s, link_text, page_id : id, ref fragment } | {
491
- debug ! ( ?id) ;
492
- if let Ok ( ( mut href, ..) ) = href ( * id, cx) {
493
- debug ! ( ?href) ;
494
- if let Some ( ref fragment) = * fragment {
495
- fragment. render ( & mut href, cx. tcx ( ) )
490
+ . filter_map ( |ItemLink { link : s, link_text, ref kind, ref fragment } | match kind {
491
+ ItemLinkKind :: Item { page_id : id } => {
492
+ debug ! ( ?id) ;
493
+ if let Some ( id) = id {
494
+ if let Ok ( ( mut href, ..) ) = href ( * id, cx) {
495
+ debug ! ( ?href) ;
496
+ if let Some ( ref fragment) = * fragment {
497
+ fragment. render ( & mut href, cx. tcx ( ) )
498
+ }
499
+ return Some ( RenderedLink {
500
+ original_text : s. clone ( ) ,
501
+ new_text : link_text. clone ( ) ,
502
+ tooltip : link_tooltip ( * id, fragment, cx) ,
503
+ href,
504
+ } ) ;
505
+ }
496
506
}
507
+ None
508
+ }
509
+ ItemLinkKind :: Example { file_path } => {
510
+ let example_name = file_path. split ( '/' ) . next ( ) . unwrap_or ( file_path) ;
511
+ let mut href =
512
+ std:: iter:: repeat ( "../" ) . take ( cx. current . len ( ) ) . collect :: < String > ( ) ;
513
+ href. push_str ( "src/" ) ;
514
+ href. push_str ( file_path) ;
515
+ href. push_str ( ".html" ) ;
497
516
Some ( RenderedLink {
498
517
original_text : s. clone ( ) ,
499
518
new_text : link_text. clone ( ) ,
500
- tooltip : link_tooltip ( * id , fragment , cx ) ,
519
+ tooltip : format ! ( "Example {example_name}" ) ,
501
520
href,
502
521
} )
503
- } else {
504
- None
505
522
}
506
523
} )
507
524
. collect ( )
@@ -1110,6 +1127,23 @@ impl<I: Iterator<Item = ast::MetaItemInner>> NestedAttributesExt for I {
1110
1127
}
1111
1128
}
1112
1129
1130
+ /// The kind of a link that has not yet been rendered.
1131
+ ///
1132
+ /// It is used in [`ItemLink`].
1133
+ #[ derive( Clone , Debug , PartialEq , Eq , Hash ) ]
1134
+ pub ( crate ) enum ItemLinkKind {
1135
+ Item {
1136
+ /// The `DefId` of the Item whose **HTML Page** contains the item being
1137
+ /// linked to. This will be different to `item_id` on item's that don't
1138
+ /// have their own page, such as struct fields and enum variants.
1139
+ page_id : Option < DefId > ,
1140
+ } ,
1141
+ Example {
1142
+ /// The path of the example file.
1143
+ file_path : String ,
1144
+ } ,
1145
+ }
1146
+
1113
1147
/// A link that has not yet been rendered.
1114
1148
///
1115
1149
/// This link will be turned into a rendered link by [`Item::links`].
@@ -1122,12 +1156,9 @@ pub(crate) struct ItemLink {
1122
1156
/// This may not be the same as `link` if there was a disambiguator
1123
1157
/// in an intra-doc link (e.g. \[`fn@f`\])
1124
1158
pub ( crate ) link_text : Box < str > ,
1125
- /// The `DefId` of the Item whose **HTML Page** contains the item being
1126
- /// linked to. This will be different to `item_id` on item's that don't
1127
- /// have their own page, such as struct fields and enum variants.
1128
- pub ( crate ) page_id : DefId ,
1129
1159
/// The url fragment to append to the link
1130
1160
pub ( crate ) fragment : Option < UrlFragment > ,
1161
+ pub ( crate ) kind : ItemLinkKind ,
1131
1162
}
1132
1163
1133
1164
pub struct RenderedLink {
0 commit comments