diff options
| author | Mara Bos <m-ou.se@m-ou.se> | 2020-11-17 10:06:27 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-11-17 10:06:27 +0100 |
| commit | c4abdcf0ac8fd9643f1c196a418e032e85c1988c (patch) | |
| tree | 434c88de803d86f55de167e00001d2a23cb2beae | |
| parent | c459ab3a0f6ddb980d03abf68ed08ffd1bf41307 (diff) | |
| parent | bbd302bab469a1da3804a4b998817ccbf15c874e (diff) | |
| download | rust-c4abdcf0ac8fd9643f1c196a418e032e85c1988c.tar.gz rust-c4abdcf0ac8fd9643f1c196a418e032e85c1988c.zip | |
Rollup merge of #79097 - GuillaumeGomez:code-block-invalid-html-tag-lint, r=jyn514
Code block invalid html tag lint Fixes #79095 r? ``@jyn514``
| -rw-r--r-- | src/librustdoc/passes/html_tags.rs | 7 | ||||
| -rw-r--r-- | src/test/rustdoc-ui/invalid-html-tags.rs | 21 |
2 files changed, 26 insertions, 2 deletions
diff --git a/src/librustdoc/passes/html_tags.rs b/src/librustdoc/passes/html_tags.rs index 01efd07cbcd..70748633117 100644 --- a/src/librustdoc/passes/html_tags.rs +++ b/src/librustdoc/passes/html_tags.rs @@ -4,7 +4,7 @@ use crate::core::DocContext; use crate::fold::DocFolder; use crate::html::markdown::opts; use core::ops::Range; -use pulldown_cmark::{Event, Parser}; +use pulldown_cmark::{Event, Parser, Tag}; use rustc_session::lint; use std::iter::Peekable; use std::str::CharIndices; @@ -196,14 +196,17 @@ impl<'a, 'tcx> DocFolder for InvalidHtmlTagsLinter<'a, 'tcx> { let mut tags = Vec::new(); let mut is_in_comment = None; + let mut in_code_block = false; let p = Parser::new_ext(&dox, opts()).into_offset_iter(); for (event, range) in p { match event { - Event::Html(text) | Event::Text(text) => { + Event::Start(Tag::CodeBlock(_)) => in_code_block = true, + Event::Html(text) | Event::Text(text) if !in_code_block => { extract_tags(&mut tags, &text, range, &mut is_in_comment, &report_diag) } + Event::End(Tag::CodeBlock(_)) => in_code_block = false, _ => {} } } diff --git a/src/test/rustdoc-ui/invalid-html-tags.rs b/src/test/rustdoc-ui/invalid-html-tags.rs index 56ca7e79d43..9c2fc4beb5e 100644 --- a/src/test/rustdoc-ui/invalid-html-tags.rs +++ b/src/test/rustdoc-ui/invalid-html-tags.rs @@ -87,3 +87,24 @@ pub fn h() {} /// <!-- //~^ ERROR Unclosed HTML comment pub fn i() {} + +/// hello +/// +/// ``` +/// uiapp.run(&env::args().collect::<Vec<_>>()); +/// ``` +pub fn j() {} + +// Check that nested codeblocks are working as well +/// hello +/// +/// ``````markdown +/// normal markdown +/// +/// ``` +/// uiapp.run(&env::args().collect::<Vec<_>>()); +/// ``` +/// +/// <Vec<_> shouldn't warn! +/// `````` +pub fn k() {} |
