+fn check_doc<'a, Events: Iterator<Item = (usize, pulldown_cmark::Event<'a>)>>(
+ cx: &EarlyContext,
+ valid_idents: &[String],
+ docs: Events,
+ spans: &[(usize, Span)],
+) {
+ use pulldown_cmark::Event::*;
+ use pulldown_cmark::Tag::*;
+
+ let mut in_code = false;
+
+ for (offset, event) in docs {
+ match event {
+ Start(CodeBlock(_)) |
+ Start(Code) => in_code = true,
+ End(CodeBlock(_)) |
+ End(Code) => in_code = false,
+ Start(_tag) | End(_tag) => (), // We don't care about other tags
+ Html(_html) |
+ InlineHtml(_html) => (), // HTML is weird, just ignore it
+ SoftBreak => (),
+ HardBreak => (),
+ FootnoteReference(text) |
+ Text(text) => {
+ if !in_code {
+ let index = match spans.binary_search_by(|c| c.0.cmp(&offset)) {
+ Ok(o) => o,
+ Err(e) => e - 1,
+ };
+
+ let (begin, span) = spans[index];
+
+ // Adjust for the begining of the current `Event`
+ let span = Span {
+ lo: span.lo + BytePos::from_usize(offset - begin),
+ ..span
+ };
+
+ check_text(cx, valid_idents, &text, span);
+ }
+ },