@@ -57,6 +57,7 @@ use std::rc::Rc;
5757use std:: cell:: RefCell ;
5858use std:: sync:: Arc ;
5959use std:: u32;
60+ use std:: ops:: Range ;
6061
6162use core:: { self , DocContext } ;
6263use doctree;
@@ -1182,9 +1183,39 @@ enum PathKind {
11821183 Type ,
11831184}
11841185
1185- fn resolution_failure ( cx : & DocContext , attrs : & Attributes , path_str : & str ) {
1186+ fn resolution_failure (
1187+ cx : & DocContext ,
1188+ attrs : & Attributes ,
1189+ path_str : & str ,
1190+ dox : & str ,
1191+ link_range : Option < Range < usize > > ,
1192+ ) {
11861193 let sp = span_of_attrs ( attrs) ;
1187- cx. sess ( ) . span_warn ( sp, & format ! ( "[{}] cannot be resolved, ignoring it..." , path_str) ) ;
1194+ let mut diag = cx. sess ( )
1195+ . struct_span_warn ( sp, & format ! ( "[{}] cannot be resolved, ignoring it..." , path_str) ) ;
1196+
1197+ if let Some ( link_range) = link_range {
1198+ // blah blah blah\nblah\nblah [blah] blah blah\nblah blah
1199+ // ^ ~~~~~~
1200+ // | link_range
1201+ // last_new_line_offset
1202+
1203+ let last_new_line_offset = dox[ ..link_range. start ] . rfind ( '\n' ) . map_or ( 0 , |n| n + 1 ) ;
1204+ let line = dox[ last_new_line_offset..] . lines ( ) . next ( ) . unwrap_or ( "" ) ;
1205+
1206+ // Print the line containing the `link_range` and manually mark it with '^'s
1207+ diag. note ( & format ! (
1208+ "the link appears in this line:\n \n {line}\n {indicator: <before$}{indicator:^<found$}" ,
1209+ line=line,
1210+ indicator="" ,
1211+ before=link_range. start - last_new_line_offset,
1212+ found=link_range. len( ) ,
1213+ ) ) ;
1214+ } else {
1215+
1216+ }
1217+
1218+ diag. emit ( ) ;
11881219}
11891220
11901221impl Clean < Attributes > for [ ast:: Attribute ] {
@@ -1193,7 +1224,7 @@ impl Clean<Attributes> for [ast::Attribute] {
11931224
11941225 if UnstableFeatures :: from_environment ( ) . is_nightly_build ( ) {
11951226 let dox = attrs. collapsed_doc_value ( ) . unwrap_or_else ( String :: new) ;
1196- for ori_link in markdown_links ( & dox) {
1227+ for ( ori_link, link_range ) in markdown_links ( & dox) {
11971228 // bail early for real links
11981229 if ori_link. contains ( '/' ) {
11991230 continue ;
@@ -1237,7 +1268,7 @@ impl Clean<Attributes> for [ast::Attribute] {
12371268 if let Ok ( def) = resolve ( cx, path_str, true ) {
12381269 def
12391270 } else {
1240- resolution_failure ( cx, & attrs, path_str) ;
1271+ resolution_failure ( cx, & attrs, path_str, & dox , link_range ) ;
12411272 // this could just be a normal link or a broken link
12421273 // we could potentially check if something is
12431274 // "intra-doc-link-like" and warn in that case
@@ -1248,7 +1279,7 @@ impl Clean<Attributes> for [ast::Attribute] {
12481279 if let Ok ( def) = resolve ( cx, path_str, false ) {
12491280 def
12501281 } else {
1251- resolution_failure ( cx, & attrs, path_str) ;
1282+ resolution_failure ( cx, & attrs, path_str, & dox , link_range ) ;
12521283 // this could just be a normal link
12531284 continue ;
12541285 }
@@ -1293,7 +1324,7 @@ impl Clean<Attributes> for [ast::Attribute] {
12931324 } else if let Ok ( value_def) = resolve ( cx, path_str, true ) {
12941325 value_def
12951326 } else {
1296- resolution_failure ( cx, & attrs, path_str) ;
1327+ resolution_failure ( cx, & attrs, path_str, & dox , link_range ) ;
12971328 // this could just be a normal link
12981329 continue ;
12991330 }
@@ -1302,7 +1333,7 @@ impl Clean<Attributes> for [ast::Attribute] {
13021333 if let Some ( def) = macro_resolve ( cx, path_str) {
13031334 ( def, None )
13041335 } else {
1305- resolution_failure ( cx, & attrs, path_str) ;
1336+ resolution_failure ( cx, & attrs, path_str, & dox , link_range ) ;
13061337 continue
13071338 }
13081339 }
0 commit comments