@@ -57,6 +57,7 @@ use std::rc::Rc;
57
57
use std:: cell:: RefCell ;
58
58
use std:: sync:: Arc ;
59
59
use std:: u32;
60
+ use std:: ops:: Range ;
60
61
61
62
use core:: { self , DocContext } ;
62
63
use doctree;
@@ -1182,9 +1183,39 @@ enum PathKind {
1182
1183
Type ,
1183
1184
}
1184
1185
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
+ ) {
1186
1193
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 ( ) ;
1188
1219
}
1189
1220
1190
1221
impl Clean < Attributes > for [ ast:: Attribute ] {
@@ -1193,7 +1224,7 @@ impl Clean<Attributes> for [ast::Attribute] {
1193
1224
1194
1225
if UnstableFeatures :: from_environment ( ) . is_nightly_build ( ) {
1195
1226
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) {
1197
1228
// bail early for real links
1198
1229
if ori_link. contains ( '/' ) {
1199
1230
continue ;
@@ -1237,7 +1268,7 @@ impl Clean<Attributes> for [ast::Attribute] {
1237
1268
if let Ok ( def) = resolve ( cx, path_str, true ) {
1238
1269
def
1239
1270
} else {
1240
- resolution_failure ( cx, & attrs, path_str) ;
1271
+ resolution_failure ( cx, & attrs, path_str, & dox , link_range ) ;
1241
1272
// this could just be a normal link or a broken link
1242
1273
// we could potentially check if something is
1243
1274
// "intra-doc-link-like" and warn in that case
@@ -1248,7 +1279,7 @@ impl Clean<Attributes> for [ast::Attribute] {
1248
1279
if let Ok ( def) = resolve ( cx, path_str, false ) {
1249
1280
def
1250
1281
} else {
1251
- resolution_failure ( cx, & attrs, path_str) ;
1282
+ resolution_failure ( cx, & attrs, path_str, & dox , link_range ) ;
1252
1283
// this could just be a normal link
1253
1284
continue ;
1254
1285
}
@@ -1293,7 +1324,7 @@ impl Clean<Attributes> for [ast::Attribute] {
1293
1324
} else if let Ok ( value_def) = resolve ( cx, path_str, true ) {
1294
1325
value_def
1295
1326
} else {
1296
- resolution_failure ( cx, & attrs, path_str) ;
1327
+ resolution_failure ( cx, & attrs, path_str, & dox , link_range ) ;
1297
1328
// this could just be a normal link
1298
1329
continue ;
1299
1330
}
@@ -1302,7 +1333,7 @@ impl Clean<Attributes> for [ast::Attribute] {
1302
1333
if let Some ( def) = macro_resolve ( cx, path_str) {
1303
1334
( def, None )
1304
1335
} else {
1305
- resolution_failure ( cx, & attrs, path_str) ;
1336
+ resolution_failure ( cx, & attrs, path_str, & dox , link_range ) ;
1306
1337
continue
1307
1338
}
1308
1339
}
0 commit comments