@@ -84,7 +84,7 @@ pub fn std_links(book: &mut Book) {
8484 }
8585 let key = ch. source_path . as_ref ( ) . unwrap ( ) ;
8686 // Create a list of replacements to make in the raw markdown to point to the new url.
87- let replacements = compute_replacements ( & ch. content , & chapter_links[ key] , & ch_urls[ key] ) ;
87+ let replacements = compute_replacements ( & ch, & chapter_links[ key] , & ch_urls[ key] ) ;
8888
8989 let mut new_contents = ch. content . clone ( ) ;
9090 for ( md_link, url, range) in replacements {
@@ -120,6 +120,9 @@ struct Link<'a> {
120120 dest_url : CowStr < ' a > ,
121121 /// The span in the original markdown where the link is located.
122122 ///
123+ /// Note that this is the post-processed markdown (such as having rules
124+ /// expanded), not the markdown on the disk.
125+ ///
123126 /// Note that during translation, all links will be converted to inline
124127 /// links. That means that for reference-style links, the link reference
125128 /// definition will end up being ignored in the final markdown. For
@@ -288,19 +291,27 @@ fn relative_url(url: &str, chapter: &Chapter) -> String {
288291/// - `url` is the URL to the standard library.
289292/// - `range` is the range in the original markdown to replace with the new link.
290293fn compute_replacements < ' a > (
291- contents : & ' a str ,
294+ chapter : & ' a Chapter ,
292295 links : & [ Link < ' _ > ] ,
293296 urls : & [ & ' a str ] ,
294297) -> Vec < ( & ' a str , & ' a str , Range < usize > ) > {
295298 let mut replacements = Vec :: new ( ) ;
296299
297300 for ( url, link) in urls. iter ( ) . zip ( links) {
298301 let Some ( cap) = ANCHOR_URL . captures ( url) else {
299- eprintln ! ( "error: could not find anchor in:\n {url}\n link={link:#?}" ) ;
302+ let line = super :: line_from_range ( & chapter. content , & link. range ) ;
303+ eprintln ! (
304+ "error: broken markdown link found in {}\n \
305+ Line is: {line}\n \
306+ Link to `{}` could not be resolved by rustdoc to a known URL (result was `{}`).\n ",
307+ chapter. source_path. as_ref( ) . unwrap( ) . display( ) ,
308+ link. dest_url,
309+ url
310+ ) ;
300311 process:: exit ( 1 ) ;
301312 } ;
302313 let url = cap. get ( 1 ) . unwrap ( ) . as_str ( ) ;
303- let md_link = & contents [ link. range . clone ( ) ] ;
314+ let md_link = & chapter . content [ link. range . clone ( ) ] ;
304315
305316 let range = link. range . clone ( ) ;
306317 let add_link = |re : & Regex | {
0 commit comments