@@ -1957,20 +1957,28 @@ fn resolution_failure(
19571957
19581958/// Report an anchor failure.
19591959fn anchor_failure ( cx : & DocContext < ' _ > , diag_info : DiagnosticInfo < ' _ > , failure : AnchorFailure ) {
1960- let msg = match failure {
1960+ let ( msg, anchor_idx ) = match failure {
19611961 AnchorFailure :: MultipleAnchors => {
1962- format ! ( "`{}` contains multiple anchors" , diag_info. ori_link)
1962+ ( format ! ( "`{}` contains multiple anchors" , diag_info. ori_link) , 1 )
19631963 }
1964- AnchorFailure :: RustdocAnchorConflict ( res) => format ! (
1965- "`{}` contains an anchor, but links to {kind}s are already anchored" ,
1966- diag_info. ori_link,
1967- kind = res. descr( ) ,
1964+ AnchorFailure :: RustdocAnchorConflict ( res) => (
1965+ format ! (
1966+ "`{}` contains an anchor, but links to {kind}s are already anchored" ,
1967+ diag_info. ori_link,
1968+ kind = res. descr( ) ,
1969+ ) ,
1970+ 0 ,
19681971 ) ,
19691972 } ;
19701973
19711974 report_diagnostic ( cx. tcx , BROKEN_INTRA_DOC_LINKS , & msg, & diag_info, |diag, sp| {
1972- if let Some ( sp) = sp {
1973- diag. span_label ( sp, "contains invalid anchor" ) ;
1975+ if let Some ( mut sp) = sp {
1976+ if let Some ( ( fragment_offset, _) ) =
1977+ diag_info. ori_link . char_indices ( ) . filter ( |( _, x) | * x == '#' ) . nth ( anchor_idx)
1978+ {
1979+ sp = sp. with_lo ( sp. lo ( ) + rustc_span:: BytePos ( fragment_offset as _ ) ) ;
1980+ }
1981+ diag. span_label ( sp, "invalid anchor" ) ;
19741982 }
19751983 if let AnchorFailure :: RustdocAnchorConflict ( Res :: Primitive ( _) ) = failure {
19761984 diag. note ( "this restriction may be lifted in a future release" ) ;
0 commit comments