@@ -451,17 +451,9 @@ pub fn span_of_attrs(attrs: &Attributes) -> syntax_pos::Span {
451
451
452
452
/// Reports a resolution failure diagnostic.
453
453
///
454
- /// Ideally we can report the diagnostic with the actual span in the source where the link failure
455
- /// occurred. However, there's a mismatch between the span in the source code and the span in the
456
- /// markdown, so we have to do a bit of work to figure out the correspondence.
457
- ///
458
- /// It's not too hard to find the span for sugared doc comments (`///` and `/**`), because the
459
- /// source will match the markdown exactly, excluding the comment markers. However, it's much more
460
- /// difficult to calculate the spans for unsugared docs, because we have to deal with escaping and
461
- /// other source features. So, we attempt to find the exact source span of the resolution failure
462
- /// in sugared docs, but use the span of the documentation attributes themselves for unsugared
463
- /// docs. Because this span might be overly large, we display the markdown line containing the
464
- /// failure as a note.
454
+ /// If we cannot find the exact source span of the resolution failure, we use the span of the
455
+ /// documentation attributes themselves. This is a little heavy-handed, so we display the markdown
456
+ /// line containing the failure as a note as well.
465
457
fn resolution_failure (
466
458
cx : & DocContext ,
467
459
attrs : & Attributes ,
@@ -473,54 +465,7 @@ fn resolution_failure(
473
465
let msg = format ! ( "`[{}]` cannot be resolved, ignoring it..." , path_str) ;
474
466
475
467
let mut diag = if let Some ( link_range) = link_range {
476
- let src = cx. sess ( ) . source_map ( ) . span_to_snippet ( sp) ;
477
- let is_all_sugared_doc = attrs. doc_strings . iter ( ) . all ( |frag| match frag {
478
- DocFragment :: SugaredDoc ( ..) => true ,
479
- _ => false ,
480
- } ) ;
481
-
482
- if let ( Ok ( src) , true ) = ( src, is_all_sugared_doc) {
483
- // The number of markdown lines up to and including the resolution failure.
484
- let num_lines = dox[ ..link_range. start ] . lines ( ) . count ( ) ;
485
-
486
- // We use `split_terminator('\n')` instead of `lines()` when counting bytes to ensure
487
- // that DOS-style line endings do not cause the spans to be calculated incorrectly.
488
- let mut src_lines = src. split_terminator ( '\n' ) ;
489
- let mut md_lines = dox. split_terminator ( '\n' ) . take ( num_lines) . peekable ( ) ;
490
-
491
- // The number of bytes from the start of the source span to the resolution failure that
492
- // are *not* part of the markdown, like comment markers.
493
- let mut extra_src_bytes = 0 ;
494
-
495
- while let Some ( md_line) = md_lines. next ( ) {
496
- loop {
497
- let source_line = src_lines
498
- . next ( )
499
- . expect ( "could not find markdown line in source" ) ;
500
-
501
- match source_line. find ( md_line) {
502
- Some ( offset) => {
503
- extra_src_bytes += if md_lines. peek ( ) . is_some ( ) {
504
- source_line. len ( ) - md_line. len ( )
505
- } else {
506
- offset
507
- } ;
508
- break ;
509
- }
510
- None => {
511
- // Since this is a source line that doesn't include a markdown line,
512
- // we have to count the newline that we split from earlier.
513
- extra_src_bytes += source_line. len ( ) + 1 ;
514
- }
515
- }
516
- }
517
- }
518
-
519
- let sp = sp. from_inner_byte_pos (
520
- link_range. start + extra_src_bytes,
521
- link_range. end + extra_src_bytes,
522
- ) ;
523
-
468
+ if let Some ( sp) = super :: source_span_for_markdown_range ( cx, dox, & link_range, attrs) {
524
469
let mut diag = cx. tcx . struct_span_lint_node (
525
470
lint:: builtin:: INTRA_DOC_LINK_RESOLUTION_FAILURE ,
526
471
NodeId :: from_u32 ( 0 ) ,
0 commit comments