@@ -4,11 +4,11 @@ use crate::core::DocContext;
44use crate :: fold:: DocFolder ;
55use crate :: html:: markdown:: opts;
66use core:: ops:: Range ;
7- use std:: iter:: Peekable ;
8- use std:: str:: CharIndices ;
97use pulldown_cmark:: { Event , Parser } ;
108use rustc_feature:: UnstableFeatures ;
119use rustc_session:: lint;
10+ use std:: iter:: Peekable ;
11+ use std:: str:: CharIndices ;
1212
1313pub const CHECK_INVALID_HTML_TAGS : Pass = Pass {
1414 name : "check-invalid-html-tags" ,
@@ -104,8 +104,7 @@ fn extract_html_tag(
104104 tag_name. push ( c) ;
105105 } else {
106106 if !tag_name. is_empty ( ) {
107- let mut r =
108- Range { start : range. start + start_pos, end : range. start + pos } ;
107+ let mut r = Range { start : range. start + start_pos, end : range. start + pos } ;
109108 if c == '>' {
110109 // In case we have a tag without attribute, we can consider the span to
111110 // refer to it fully.
@@ -143,6 +142,27 @@ fn extract_html_tag(
143142 }
144143}
145144
145+ fn extract_html_comment (
146+ text : & str ,
147+ range : & Range < usize > ,
148+ start_pos : usize ,
149+ iter : & mut Peekable < CharIndices < ' _ > > ,
150+ f : & impl Fn ( & str , & Range < usize > ) ,
151+ ) {
152+ // We first skip the "!--" part.
153+ let mut iter = iter. skip ( 3 ) ;
154+ while let Some ( ( pos, c) ) = iter. next ( ) {
155+ if c == '-' && text[ pos..] . starts_with ( "-->" ) {
156+ // All good, we can leave!
157+ return ;
158+ }
159+ }
160+ f (
161+ "Unclosed HTML comment" ,
162+ & Range { start : range. start + start_pos, end : range. start + start_pos + 3 } ,
163+ ) ;
164+ }
165+
146166fn extract_tags (
147167 tags : & mut Vec < ( String , Range < usize > ) > ,
148168 text : & str ,
@@ -153,7 +173,11 @@ fn extract_tags(
153173
154174 while let Some ( ( start_pos, c) ) = iter. next ( ) {
155175 if c == '<' {
156- extract_html_tag ( tags, text, & range, start_pos, & mut iter, f) ;
176+ if text[ start_pos..] . starts_with ( "<!--" ) {
177+ extract_html_comment ( text, & range, start_pos, & mut iter, f) ;
178+ } else {
179+ extract_html_tag ( tags, text, & range, start_pos, & mut iter, f) ;
180+ }
157181 }
158182 }
159183}
0 commit comments