Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Code block invalid html tag lint #79097

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions src/librustdoc/passes/html_tags.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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,
jyn514 marked this conversation as resolved.
Show resolved Hide resolved
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,
_ => {}
}
}
Expand Down
21 changes: 21 additions & 0 deletions src/test/rustdoc-ui/invalid-html-tags.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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() {}