@@ -321,7 +321,7 @@ impl<'a, 'tcx> DocFolder for LinkCollector<'a, 'tcx> {
321
321
if let Ok ( res) = self . resolve ( path_str, ns, & current_item, parent_node) {
322
322
res
323
323
} else {
324
- resolution_failure ( cx, & item. attrs , path_str, & dox, link_range) ;
324
+ resolution_failure ( cx, & item, path_str, & dox, link_range) ;
325
325
// This could just be a normal link or a broken link
326
326
// we could potentially check if something is
327
327
// "intra-doc-link-like" and warn in that case.
@@ -332,7 +332,7 @@ impl<'a, 'tcx> DocFolder for LinkCollector<'a, 'tcx> {
332
332
if let Ok ( res) = self . resolve ( path_str, ns, & current_item, parent_node) {
333
333
res
334
334
} else {
335
- resolution_failure ( cx, & item. attrs , path_str, & dox, link_range) ;
335
+ resolution_failure ( cx, & item, path_str, & dox, link_range) ;
336
336
// This could just be a normal link.
337
337
continue ;
338
338
}
@@ -357,7 +357,7 @@ impl<'a, 'tcx> DocFolder for LinkCollector<'a, 'tcx> {
357
357
} ;
358
358
359
359
if candidates. is_empty ( ) {
360
- resolution_failure ( cx, & item. attrs , path_str, & dox, link_range) ;
360
+ resolution_failure ( cx, & item, path_str, & dox, link_range) ;
361
361
// this could just be a normal link
362
362
continue ;
363
363
}
@@ -368,7 +368,7 @@ impl<'a, 'tcx> DocFolder for LinkCollector<'a, 'tcx> {
368
368
} else {
369
369
ambiguity_error (
370
370
cx,
371
- & item. attrs ,
371
+ & item,
372
372
path_str,
373
373
& dox,
374
374
link_range,
@@ -381,7 +381,7 @@ impl<'a, 'tcx> DocFolder for LinkCollector<'a, 'tcx> {
381
381
if let Some ( res) = macro_resolve ( cx, path_str) {
382
382
( res, None )
383
383
} else {
384
- resolution_failure ( cx, & item. attrs , path_str, & dox, link_range) ;
384
+ resolution_failure ( cx, & item, path_str, & dox, link_range) ;
385
385
continue
386
386
}
387
387
}
@@ -452,16 +452,24 @@ fn macro_resolve(cx: &DocContext<'_>, path_str: &str) -> Option<Res> {
452
452
/// line containing the failure as a note as well.
453
453
fn resolution_failure (
454
454
cx : & DocContext < ' _ > ,
455
- attrs : & Attributes ,
455
+ item : & Item ,
456
456
path_str : & str ,
457
457
dox : & str ,
458
458
link_range : Option < Range < usize > > ,
459
459
) {
460
+ let hir_id = match cx. as_local_hir_id ( item. def_id ) {
461
+ Some ( hir_id) => hir_id,
462
+ None => {
463
+ // If non-local, no need to check anything.
464
+ return ;
465
+ }
466
+ } ;
467
+ let attrs = & item. attrs ;
460
468
let sp = span_of_attrs ( attrs) ;
461
469
462
470
let mut diag = cx. tcx . struct_span_lint_hir (
463
471
lint:: builtin:: INTRA_DOC_LINK_RESOLUTION_FAILURE ,
464
- hir :: CRATE_HIR_ID ,
472
+ hir_id ,
465
473
sp,
466
474
& format ! ( "`[{}]` cannot be resolved, ignoring it..." , path_str) ,
467
475
) ;
@@ -495,12 +503,20 @@ fn resolution_failure(
495
503
496
504
fn ambiguity_error (
497
505
cx : & DocContext < ' _ > ,
498
- attrs : & Attributes ,
506
+ item : & Item ,
499
507
path_str : & str ,
500
508
dox : & str ,
501
509
link_range : Option < Range < usize > > ,
502
510
candidates : PerNS < Option < Res > > ,
503
511
) {
512
+ let hir_id = match cx. as_local_hir_id ( item. def_id ) {
513
+ Some ( hir_id) => hir_id,
514
+ None => {
515
+ // If non-local, no need to check anything.
516
+ return ;
517
+ }
518
+ } ;
519
+ let attrs = & item. attrs ;
504
520
let sp = span_of_attrs ( attrs) ;
505
521
506
522
let mut msg = format ! ( "`{}` is " , path_str) ;
@@ -532,7 +548,7 @@ fn ambiguity_error(
532
548
533
549
let mut diag = cx. tcx . struct_span_lint_hir (
534
550
lint:: builtin:: INTRA_DOC_LINK_RESOLUTION_FAILURE ,
535
- hir :: CRATE_HIR_ID ,
551
+ hir_id ,
536
552
sp,
537
553
& msg,
538
554
) ;
0 commit comments