Skip to content

Commit c4abdcf

Browse files
authored
Rollup merge of #79097 - GuillaumeGomez:code-block-invalid-html-tag-lint, r=jyn514
Code block invalid html tag lint Fixes #79095 r? ``@jyn514``
2 parents c459ab3 + bbd302b commit c4abdcf

File tree

2 files changed

+26
-2
lines changed

2 files changed

+26
-2
lines changed

src/librustdoc/passes/html_tags.rs

+5-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use crate::core::DocContext;
44
use crate::fold::DocFolder;
55
use crate::html::markdown::opts;
66
use core::ops::Range;
7-
use pulldown_cmark::{Event, Parser};
7+
use pulldown_cmark::{Event, Parser, Tag};
88
use rustc_session::lint;
99
use std::iter::Peekable;
1010
use std::str::CharIndices;
@@ -196,14 +196,17 @@ impl<'a, 'tcx> DocFolder for InvalidHtmlTagsLinter<'a, 'tcx> {
196196

197197
let mut tags = Vec::new();
198198
let mut is_in_comment = None;
199+
let mut in_code_block = false;
199200

200201
let p = Parser::new_ext(&dox, opts()).into_offset_iter();
201202

202203
for (event, range) in p {
203204
match event {
204-
Event::Html(text) | Event::Text(text) => {
205+
Event::Start(Tag::CodeBlock(_)) => in_code_block = true,
206+
Event::Html(text) | Event::Text(text) if !in_code_block => {
205207
extract_tags(&mut tags, &text, range, &mut is_in_comment, &report_diag)
206208
}
209+
Event::End(Tag::CodeBlock(_)) => in_code_block = false,
207210
_ => {}
208211
}
209212
}

src/test/rustdoc-ui/invalid-html-tags.rs

+21
Original file line numberDiff line numberDiff line change
@@ -87,3 +87,24 @@ pub fn h() {}
8787
/// <!--
8888
//~^ ERROR Unclosed HTML comment
8989
pub fn i() {}
90+
91+
/// hello
92+
///
93+
/// ```
94+
/// uiapp.run(&env::args().collect::<Vec<_>>());
95+
/// ```
96+
pub fn j() {}
97+
98+
// Check that nested codeblocks are working as well
99+
/// hello
100+
///
101+
/// ``````markdown
102+
/// normal markdown
103+
///
104+
/// ```
105+
/// uiapp.run(&env::args().collect::<Vec<_>>());
106+
/// ```
107+
///
108+
/// <Vec<_> shouldn't warn!
109+
/// ``````
110+
pub fn k() {}

0 commit comments

Comments
 (0)