@@ -20,7 +20,39 @@ pub fn check(librustdoc_path: &Path, bad: &mut bool) {
20
20
21
21
while let Some ( ( pos, line) ) = lines. next ( ) {
22
22
let line = line. trim ( ) ;
23
- if TAGS . iter ( ) . any ( |( _, tag) | line. ends_with ( tag) ) {
23
+ if let Some ( need_next_line_check) = TAGS . iter ( ) . find_map ( |( tag, end_tag) | {
24
+ // We first check if the line ends with a jinja tag.
25
+ if !line. ends_with ( end_tag) {
26
+ return None ;
27
+ // Then we check if this a comment tag.
28
+ } else if * tag != "{#" {
29
+ return Some ( false ) ;
30
+ // And finally we check if the comment is empty (ie, only there to strip
31
+ // extra whitespace characters).
32
+ } else if let Some ( start_pos) = line. rfind ( tag) {
33
+ Some ( line[ start_pos + 2 ..] . trim ( ) == "#}" )
34
+ } else {
35
+ Some ( false )
36
+ }
37
+ } ) {
38
+ // All good, the line is ending is a jinja tag. But maybe this tag is useless
39
+ // if the next line starts with a jinja tag as well!
40
+ //
41
+ // However, only (empty) comment jinja tags are concerned about it.
42
+ if need_next_line_check
43
+ && lines. peek ( ) . is_some_and ( |( _, next_line) | {
44
+ let next_line = next_line. trim_start ( ) ;
45
+ TAGS . iter ( ) . any ( |( tag, _) | next_line. starts_with ( tag) )
46
+ } )
47
+ {
48
+ // It seems like ending this line with a jinja tag is not needed after all.
49
+ tidy_error ! (
50
+ bad,
51
+ "`{}` at line {}: unneeded `{{# #}}` tag at the end of the line" ,
52
+ path. path( ) . display( ) ,
53
+ pos + 1 ,
54
+ ) ;
55
+ }
24
56
continue ;
25
57
}
26
58
let Some ( next_line) = lines. peek ( ) . map ( |( _, next_line) | next_line. trim ( ) ) else {
0 commit comments