Skip to content

Commit 0fdcaa8

Browse files
committed
clean up code
1 parent d194de2 commit 0fdcaa8

File tree

1 file changed

+21
-41
lines changed

1 file changed

+21
-41
lines changed

clippy_lints/src/doc.rs

+21-41
Original file line numberDiff line numberDiff line change
@@ -480,18 +480,21 @@ fn check_doc<'a, Events: Iterator<Item = (pulldown_cmark::Event<'a>, Range<usize
480480
errors: false,
481481
panics: false,
482482
};
483-
let mut in_code = false;
483+
let mut in_code_block = false;
484484
let mut in_link = None;
485485
let mut in_heading = false;
486486
let mut is_rust = false;
487487
let mut edition = None;
488488
let mut ticks_inverted = false;
489-
let mut prev_was_ticks: Option<Span> = None;
489+
let mut prev_was_code: Option<Span> = None;
490490
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+
}
492495
match event {
493496
Start(CodeBlock(ref kind)) => {
494-
in_code = true;
497+
in_code_block = true;
495498
if let CodeBlockKind::Fenced(lang) = kind {
496499
for item in lang.split(',') {
497500
if item == "ignore" {
@@ -506,50 +509,28 @@ fn check_doc<'a, Events: Iterator<Item = (pulldown_cmark::Event<'a>, Range<usize
506509
}
507510
}
508511
}
509-
prev_was_ticks = None;
510512
},
511513
End(CodeBlock(_)) => {
512-
in_code = false;
514+
in_code_block = false;
513515
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;
542516
},
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 => (),
543524
FootnoteReference(text) | Text(text) | Code(text) => {
544525
let index = match spans.binary_search_by(|c| c.0.cmp(&range.start)) {
545526
Ok(o) => o,
546527
Err(e) => e - 1,
547528
};
548529
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 {
550531
let span = span.with_lo(span.lo() + BytePos::from_usize(range.start - begin));
551532
let span = span.with_hi(span.lo() + BytePos::from_usize(1));
552-
prev_was_ticks = Some(span);
533+
prev_was_code = Some(span);
553534
} else {
554535
if Some(&text) == in_link.as_ref() {
555536
// 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
560541
headers.safety |= in_heading && text.trim() == "Safety";
561542
headers.errors |= in_heading && text.trim() == "Errors";
562543
headers.panics |= in_heading && text.trim() == "Panics";
563-
if in_code {
544+
if in_code_block {
564545
if is_rust {
565546
let edition = edition.unwrap_or_else(|| cx.tcx.sess.edition());
566547
check_code(cx, &text, edition, span);
567548
}
568549
} else {
569550
// Adjust for the beginning of the current `Event`
570551
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);
572553
}
573-
prev_was_ticks = None;
574554
}
575555
},
576556
}
@@ -654,11 +634,11 @@ fn check_text(
654634
valid_idents: &FxHashSet<String>,
655635
text: &str,
656636
span: Span,
657-
prev_was_ticks: &Option<Span>,
637+
prev_was_code: &Option<Span>,
658638
ticks_inverted: &mut bool,
659639
) {
660640
if_chain! {
661-
if let Some(prev_span) = prev_was_ticks;
641+
if let Some(prev_span) = prev_was_code;
662642
let words = text.split(char::is_whitespace).collect_vec();
663643
if words.len() == 1;
664644
if should_have_backticks(text);

0 commit comments

Comments
 (0)