@@ -76,7 +76,7 @@ use crate::html::format::{
76
76
use crate :: html:: highlight;
77
77
use crate :: html:: markdown:: { HeadingOffset , Markdown , MarkdownHtml , MarkdownSummaryLine } ;
78
78
use crate :: html:: sources;
79
- use crate :: scrape_examples:: CallData ;
79
+ use crate :: scrape_examples:: { CallData , CallLocation } ;
80
80
use crate :: try_none;
81
81
82
82
/// A pair of name and its optional document.
@@ -2594,6 +2594,21 @@ fn render_call_locations(w: &mut Buffer, cx: &Context<'_>, item: &clean::Item) {
2594
2594
id = id
2595
2595
) ;
2596
2596
2597
+ // Create a URL to a particular location in a reverse-dependency's source file
2598
+ let link_to_loc = |call_data : & CallData , loc : & CallLocation | -> ( String , String ) {
2599
+ let ( line_lo, line_hi) = loc. call_expr . line_span ;
2600
+ let ( anchor, title) = if line_lo == line_hi {
2601
+ ( ( line_lo + 1 ) . to_string ( ) , format ! ( "line {}" , line_lo + 1 ) )
2602
+ } else {
2603
+ (
2604
+ format ! ( "{}-{}" , line_lo + 1 , line_hi + 1 ) ,
2605
+ format ! ( "lines {}-{}" , line_lo + 1 , line_hi + 1 ) ,
2606
+ )
2607
+ } ;
2608
+ let url = format ! ( "{}{}#{}" , cx. root_path( ) , call_data. url, anchor) ;
2609
+ ( url, title)
2610
+ } ;
2611
+
2597
2612
// Generate the HTML for a single example, being the title and code block
2598
2613
let write_example = |w : & mut Buffer , ( path, call_data) : ( & PathBuf , & CallData ) | -> bool {
2599
2614
let contents = match fs:: read_to_string ( & path) {
@@ -2631,15 +2646,7 @@ fn render_call_locations(w: &mut Buffer, cx: &Context<'_>, item: &clean::Item) {
2631
2646
let ( line_lo, line_hi) = loc. call_expr . line_span ;
2632
2647
let byte_range = ( byte_lo - byte_min, byte_hi - byte_min) ;
2633
2648
let line_range = ( line_lo - line_min, line_hi - line_min) ;
2634
- let ( anchor, line_title) = if line_lo == line_hi {
2635
- ( format ! ( "{}" , line_lo + 1 ) , format ! ( "line {}" , line_lo + 1 ) )
2636
- } else {
2637
- (
2638
- format ! ( "{}-{}" , line_lo + 1 , line_hi + 1 ) ,
2639
- format ! ( "lines {}-{}" , line_lo + 1 , line_hi + 1 ) ,
2640
- )
2641
- } ;
2642
- let line_url = format ! ( "{}{}#{}" , cx. root_path( ) , call_data. url, anchor) ;
2649
+ let ( line_url, line_title) = link_to_loc ( call_data, loc) ;
2643
2650
2644
2651
( byte_range, ( line_range, line_url, line_title) )
2645
2652
} )
@@ -2768,11 +2775,11 @@ fn render_call_locations(w: &mut Buffer, cx: &Context<'_>, item: &clean::Item) {
2768
2775
if it. peek ( ) . is_some ( ) {
2769
2776
write ! ( w, r#"<div class="example-links">Additional examples can be found in:<br><ul>"# ) ;
2770
2777
it. for_each ( |( _, call_data) | {
2778
+ let ( url, _) = link_to_loc ( & call_data, & call_data. locations [ 0 ] ) ;
2771
2779
write ! (
2772
2780
w,
2773
- r#"<li><a href="{root}{url}">{name}</a></li>"# ,
2774
- root = cx. root_path( ) ,
2775
- url = call_data. url,
2781
+ r#"<li><a href="{url}">{name}</a></li>"# ,
2782
+ url = url,
2776
2783
name = call_data. display_name
2777
2784
) ;
2778
2785
} ) ;
0 commit comments