@@ -480,18 +480,21 @@ fn check_doc<'a, Events: Iterator<Item = (pulldown_cmark::Event<'a>, Range<usize
480
480
errors : false ,
481
481
panics : false ,
482
482
} ;
483
- let mut in_code = false ;
483
+ let mut in_code_block = false ;
484
484
let mut in_link = None ;
485
485
let mut in_heading = false ;
486
486
let mut is_rust = false ;
487
487
let mut edition = None ;
488
488
let mut ticks_inverted = false ;
489
- let mut prev_was_ticks : Option < Span > = None ;
489
+ let mut prev_was_code : Option < Span > = None ;
490
490
for ( event, range) in events {
491
- let in_ticks = matches ! ( event, Code ( _) ) ;
491
+ let in_code = matches ! ( event, Code ( _) ) ;
492
+ if !matches ! ( event, FootnoteReference ( _) | Text ( _) | Code ( _) ) {
493
+ prev_was_code = None ;
494
+ }
492
495
match event {
493
496
Start ( CodeBlock ( ref kind) ) => {
494
- in_code = true ;
497
+ in_code_block = true ;
495
498
if let CodeBlockKind :: Fenced ( lang) = kind {
496
499
for item in lang. split ( ',' ) {
497
500
if item == "ignore" {
@@ -506,50 +509,28 @@ fn check_doc<'a, Events: Iterator<Item = (pulldown_cmark::Event<'a>, Range<usize
506
509
}
507
510
}
508
511
}
509
- prev_was_ticks = None ;
510
512
} ,
511
513
End ( CodeBlock ( _) ) => {
512
- in_code = false ;
514
+ in_code_block = false ;
513
515
is_rust = false ;
514
- prev_was_ticks = None ;
515
- } ,
516
- Start ( Link ( _, url, _) ) => {
517
- prev_was_ticks = None ;
518
- in_link = Some ( url) ;
519
- } ,
520
- End ( Link ( ..) ) => {
521
- prev_was_ticks = None ;
522
- in_link = None ;
523
- } ,
524
- Start ( Heading ( _) ) => {
525
- prev_was_ticks = None ;
526
- in_heading = true ;
527
- } ,
528
- End ( Heading ( _) ) => {
529
- prev_was_ticks = None ;
530
- in_heading = false ;
531
- } ,
532
- Start ( _tag) | End ( _tag) => {
533
- // We don't care about other tags
534
- prev_was_ticks = None ;
535
- } ,
536
- Html ( _html) => {
537
- // HTML is weird, just ignore it
538
- prev_was_ticks = None ;
539
- } ,
540
- SoftBreak | HardBreak | TaskListMarker ( _) | Rule => {
541
- prev_was_ticks = None ;
542
516
} ,
517
+ Start ( Link ( _, url, _) ) => in_link = Some ( url) ,
518
+ End ( Link ( ..) ) => in_link = None ,
519
+ Start ( Heading ( _) ) => in_heading = true ,
520
+ End ( Heading ( _) ) => in_heading = false ,
521
+ Start ( _tag) | End ( _tag) => ( ) , // We don't care about other tags
522
+ Html ( _html) => ( ) , // HTML is weird, just ignore it
523
+ SoftBreak | HardBreak | TaskListMarker ( _) | Rule => ( ) ,
543
524
FootnoteReference ( text) | Text ( text) | Code ( text) => {
544
525
let index = match spans. binary_search_by ( |c| c. 0 . cmp ( & range. start ) ) {
545
526
Ok ( o) => o,
546
527
Err ( e) => e - 1 ,
547
528
} ;
548
529
let ( begin, span) = spans[ index] ;
549
- if ticks_inverted && !in_ticks || !ticks_inverted && in_ticks {
530
+ if ticks_inverted && !in_code || !ticks_inverted && in_code {
550
531
let span = span. with_lo ( span. lo ( ) + BytePos :: from_usize ( range. start - begin) ) ;
551
532
let span = span. with_hi ( span. lo ( ) + BytePos :: from_usize ( 1 ) ) ;
552
- prev_was_ticks = Some ( span) ;
533
+ prev_was_code = Some ( span) ;
553
534
} else {
554
535
if Some ( & text) == in_link. as_ref ( ) {
555
536
// Probably a link of the form `<http://example.com>`
@@ -560,17 +541,16 @@ fn check_doc<'a, Events: Iterator<Item = (pulldown_cmark::Event<'a>, Range<usize
560
541
headers. safety |= in_heading && text. trim ( ) == "Safety" ;
561
542
headers. errors |= in_heading && text. trim ( ) == "Errors" ;
562
543
headers. panics |= in_heading && text. trim ( ) == "Panics" ;
563
- if in_code {
544
+ if in_code_block {
564
545
if is_rust {
565
546
let edition = edition. unwrap_or_else ( || cx. tcx . sess . edition ( ) ) ;
566
547
check_code ( cx, & text, edition, span) ;
567
548
}
568
549
} else {
569
550
// Adjust for the beginning of the current `Event`
570
551
let span = span. with_lo ( span. lo ( ) + BytePos :: from_usize ( range. start - begin) ) ;
571
- check_text ( cx, valid_idents, & text, span, & prev_was_ticks , & mut ticks_inverted) ;
552
+ check_text ( cx, valid_idents, & text, span, & prev_was_code , & mut ticks_inverted) ;
572
553
}
573
- prev_was_ticks = None ;
574
554
}
575
555
} ,
576
556
}
@@ -654,11 +634,11 @@ fn check_text(
654
634
valid_idents : & FxHashSet < String > ,
655
635
text : & str ,
656
636
span : Span ,
657
- prev_was_ticks : & Option < Span > ,
637
+ prev_was_code : & Option < Span > ,
658
638
ticks_inverted : & mut bool ,
659
639
) {
660
640
if_chain ! {
661
- if let Some ( prev_span) = prev_was_ticks ;
641
+ if let Some ( prev_span) = prev_was_code ;
662
642
let words = text. split( char :: is_whitespace) . collect_vec( ) ;
663
643
if words. len( ) == 1 ;
664
644
if should_have_backticks( text) ;
0 commit comments