@@ -84,7 +84,7 @@ pub fn std_links(book: &mut Book) {
84
84
}
85
85
let key = ch. source_path . as_ref ( ) . unwrap ( ) ;
86
86
// 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] ) ;
88
88
89
89
let mut new_contents = ch. content . clone ( ) ;
90
90
for ( md_link, url, range) in replacements {
@@ -120,6 +120,9 @@ struct Link<'a> {
120
120
dest_url : CowStr < ' a > ,
121
121
/// The span in the original markdown where the link is located.
122
122
///
123
+ /// Note that this is the post-processed markdown (such as having rules
124
+ /// expanded), not the markdown on the disk.
125
+ ///
123
126
/// Note that during translation, all links will be converted to inline
124
127
/// links. That means that for reference-style links, the link reference
125
128
/// definition will end up being ignored in the final markdown. For
@@ -288,19 +291,27 @@ fn relative_url(url: &str, chapter: &Chapter) -> String {
288
291
/// - `url` is the URL to the standard library.
289
292
/// - `range` is the range in the original markdown to replace with the new link.
290
293
fn compute_replacements < ' a > (
291
- contents : & ' a str ,
294
+ chapter : & ' a Chapter ,
292
295
links : & [ Link < ' _ > ] ,
293
296
urls : & [ & ' a str ] ,
294
297
) -> Vec < ( & ' a str , & ' a str , Range < usize > ) > {
295
298
let mut replacements = Vec :: new ( ) ;
296
299
297
300
for ( url, link) in urls. iter ( ) . zip ( links) {
298
301
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
+ ) ;
300
311
process:: exit ( 1 ) ;
301
312
} ;
302
313
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 ( ) ] ;
304
315
305
316
let range = link. range . clone ( ) ;
306
317
let add_link = |re : & Regex | {
0 commit comments