diff --git a/src/librustdoc/passes/html_tags.rs b/src/librustdoc/passes/html_tags.rs
index 01efd07cbcde7..70748633117fb 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 56ca7e79d4358..9c2fc4beb5eb1 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() {}
///