@@ -485,6 +485,8 @@ fn check_doc<'a, Events: Iterator<Item = (pulldown_cmark::Event<'a>, Range<usize
485
485
let mut in_heading = false ;
486
486
let mut is_rust = false ;
487
487
let mut edition = None ;
488
+ let mut ticks_unbalanced = false ;
489
+ let mut text_to_check = Vec :: new ( ) ;
488
490
for ( event, range) in events {
489
491
match event {
490
492
Start ( CodeBlock ( ref kind) ) => {
@@ -516,34 +518,54 @@ fn check_doc<'a, Events: Iterator<Item = (pulldown_cmark::Event<'a>, Range<usize
516
518
Html ( _html) => ( ) , // HTML is weird, just ignore it
517
519
SoftBreak | HardBreak | TaskListMarker ( _) | Code ( _) | Rule => ( ) ,
518
520
FootnoteReference ( text) | Text ( text) => {
519
- if Some ( & text) == in_link. as_ref ( ) {
521
+ if Some ( & text) == in_link. as_ref ( ) || ticks_unbalanced {
520
522
// Probably a link of the form `<http://example.com>`
521
523
// Which are represented as a link to "http://example.com" with
522
524
// text "http://example.com" by pulldown-cmark
523
525
continue ;
524
526
}
525
- headers. safety |= in_heading && text. trim ( ) == "Safety" ;
526
- headers. errors |= in_heading && text. trim ( ) == "Errors" ;
527
- headers. panics |= in_heading && text. trim ( ) == "Panics" ;
528
- let index = match spans. binary_search_by ( |c| c. 0 . cmp ( & range. start ) ) {
529
- Ok ( o) => o,
530
- Err ( e) => e - 1 ,
531
- } ;
532
- let ( begin, span) = spans[ index] ;
533
- if in_code {
534
- if is_rust {
535
- let edition = edition. unwrap_or_else ( || cx. tcx . sess . edition ( ) ) ;
536
- check_code ( cx, & text, edition, span) ;
537
- }
527
+ if text. contains ( '`' ) && !in_code {
528
+ let ( _, start) = spans[ 0 ] ;
529
+ let span = if let Some ( ( _, end) ) = spans. last ( ) {
530
+ start. with_hi ( end. hi ( ) )
531
+ } else {
532
+ start
533
+ } ;
534
+ span_lint (
535
+ cx,
536
+ DOC_MARKDOWN ,
537
+ span,
538
+ "backticks are unbalanced; one may be missing a pair" ,
539
+ ) ;
540
+ ticks_unbalanced = true ;
538
541
} else {
539
- // Adjust for the beginning of the current `Event`
540
- let span = span. with_lo ( span. lo ( ) + BytePos :: from_usize ( range. start - begin) ) ;
541
-
542
- check_text ( cx, valid_idents, & text, span) ;
542
+ headers. safety |= in_heading && text. trim ( ) == "Safety" ;
543
+ headers. errors |= in_heading && text. trim ( ) == "Errors" ;
544
+ headers. panics |= in_heading && text. trim ( ) == "Panics" ;
545
+ let index = match spans. binary_search_by ( |c| c. 0 . cmp ( & range. start ) ) {
546
+ Ok ( o) => o,
547
+ Err ( e) => e - 1 ,
548
+ } ;
549
+ let ( begin, span) = spans[ index] ;
550
+ if in_code {
551
+ if is_rust {
552
+ let edition = edition. unwrap_or_else ( || cx. tcx . sess . edition ( ) ) ;
553
+ check_code ( cx, & text, edition, span) ;
554
+ }
555
+ } else {
556
+ // Adjust for the beginning of the current `Event`
557
+ let span = span. with_lo ( span. lo ( ) + BytePos :: from_usize ( range. start - begin) ) ;
558
+ text_to_check. push ( ( text, span) ) ;
559
+ }
543
560
}
544
561
} ,
545
562
}
546
563
}
564
+ if !ticks_unbalanced {
565
+ for ( text, span) in text_to_check {
566
+ check_text ( cx, valid_idents, & text, span) ;
567
+ }
568
+ }
547
569
headers
548
570
}
549
571
0 commit comments