@@ -321,7 +321,7 @@ impl<'a, 'tcx> DocFolder for LinkCollector<'a, 'tcx> {
321321 if let Ok ( res) = self . resolve ( path_str, ns, & current_item, parent_node) {
322322 res
323323 } else {
324- resolution_failure ( cx, & item. attrs , path_str, & dox, link_range) ;
324+ resolution_failure ( cx, & item, path_str, & dox, link_range) ;
325325 // This could just be a normal link or a broken link
326326 // we could potentially check if something is
327327 // "intra-doc-link-like" and warn in that case.
@@ -332,7 +332,7 @@ impl<'a, 'tcx> DocFolder for LinkCollector<'a, 'tcx> {
332332 if let Ok ( res) = self . resolve ( path_str, ns, & current_item, parent_node) {
333333 res
334334 } else {
335- resolution_failure ( cx, & item. attrs , path_str, & dox, link_range) ;
335+ resolution_failure ( cx, & item, path_str, & dox, link_range) ;
336336 // This could just be a normal link.
337337 continue ;
338338 }
@@ -357,7 +357,7 @@ impl<'a, 'tcx> DocFolder for LinkCollector<'a, 'tcx> {
357357 } ;
358358
359359 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) ;
361361 // this could just be a normal link
362362 continue ;
363363 }
@@ -368,7 +368,7 @@ impl<'a, 'tcx> DocFolder for LinkCollector<'a, 'tcx> {
368368 } else {
369369 ambiguity_error (
370370 cx,
371- & item. attrs ,
371+ & item,
372372 path_str,
373373 & dox,
374374 link_range,
@@ -381,7 +381,7 @@ impl<'a, 'tcx> DocFolder for LinkCollector<'a, 'tcx> {
381381 if let Some ( res) = macro_resolve ( cx, path_str) {
382382 ( res, None )
383383 } else {
384- resolution_failure ( cx, & item. attrs , path_str, & dox, link_range) ;
384+ resolution_failure ( cx, & item, path_str, & dox, link_range) ;
385385 continue
386386 }
387387 }
@@ -452,16 +452,24 @@ fn macro_resolve(cx: &DocContext<'_>, path_str: &str) -> Option<Res> {
452452/// line containing the failure as a note as well.
453453fn resolution_failure (
454454 cx : & DocContext < ' _ > ,
455- attrs : & Attributes ,
455+ item : & Item ,
456456 path_str : & str ,
457457 dox : & str ,
458458 link_range : Option < Range < usize > > ,
459459) {
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 ;
460468 let sp = span_of_attrs ( attrs) ;
461469
462470 let mut diag = cx. tcx . struct_span_lint_hir (
463471 lint:: builtin:: INTRA_DOC_LINK_RESOLUTION_FAILURE ,
464- hir :: CRATE_HIR_ID ,
472+ hir_id ,
465473 sp,
466474 & format ! ( "`[{}]` cannot be resolved, ignoring it..." , path_str) ,
467475 ) ;
@@ -495,12 +503,20 @@ fn resolution_failure(
495503
496504fn ambiguity_error (
497505 cx : & DocContext < ' _ > ,
498- attrs : & Attributes ,
506+ item : & Item ,
499507 path_str : & str ,
500508 dox : & str ,
501509 link_range : Option < Range < usize > > ,
502510 candidates : PerNS < Option < Res > > ,
503511) {
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 ;
504520 let sp = span_of_attrs ( attrs) ;
505521
506522 let mut msg = format ! ( "`{}` is " , path_str) ;
@@ -532,7 +548,7 @@ fn ambiguity_error(
532548
533549 let mut diag = cx. tcx . struct_span_lint_hir (
534550 lint:: builtin:: INTRA_DOC_LINK_RESOLUTION_FAILURE ,
535- hir :: CRATE_HIR_ID ,
551+ hir_id ,
536552 sp,
537553 & msg,
538554 ) ;
0 commit comments