about summary refs log tree commit diff
diff options
context:
space:
mode:
authorNilstrieb <48135649+Nilstrieb@users.noreply.github.com>2022-10-07 19:38:38 +0200
committerDylan DPC <dylan.dpc@gmail.com>2022-10-12 17:49:10 +0530
commitce3560979d029e102777f5bf3aec840f4ff9c0fe (patch)
treea3efa94ea061ac3a01361791edc3dc16a1bb8c67
parent7bfef19844f20514cda40437847880ec8a663926 (diff)
downloadrust-ce3560979d029e102777f5bf3aec840f4ff9c0fe.tar.gz
rust-ce3560979d029e102777f5bf3aec840f4ff9c0fe.zip
Error if tidy-alphabetical-end was not found
-rw-r--r--src/tools/tidy/src/alphabetical.rs23
1 files changed, 19 insertions, 4 deletions
diff --git a/src/tools/tidy/src/alphabetical.rs b/src/tools/tidy/src/alphabetical.rs
index e02b2d98f42..c9f1dfb707f 100644
--- a/src/tools/tidy/src/alphabetical.rs
+++ b/src/tools/tidy/src/alphabetical.rs
@@ -29,18 +29,29 @@ fn is_close_bracket(c: char) -> bool {
     matches!(c, ')' | ']' | '}')
 }
 
+const START_COMMENT: &str = "// tidy-alphabetical-start";
+const END_COMMENT: &str = "// tidy-alphabetical-end";
+
 fn check_section<'a>(
     file: impl Display,
     lines: impl Iterator<Item = (usize, &'a str)>,
     bad: &mut bool,
 ) {
-    let content_lines = lines.take_while(|(_, line)| !line.contains("// tidy-alphabetical-end"));
+    let content_lines = lines.take_while(|(_, line)| !line.contains(END_COMMENT));
 
     let mut prev_line = String::new();
     let mut first_indent = None;
     let mut in_split_line = None;
 
     for (line_idx, line) in content_lines {
+        if line.contains(START_COMMENT) {
+            tidy_error!(
+                bad,
+                "{file}:{} found `// tidy-alphabetical-start` expecting `// tidy-alphabetical-end`",
+                line_idx
+            )
+        }
+
         let indent = first_indent.unwrap_or_else(|| {
             let indent = indentation(line);
             first_indent = Some(indent);
@@ -82,16 +93,20 @@ fn check_section<'a>(
     }
 }
 
-const START_COMMENT: &str = "// tidy-alphabetical-start";
-
 pub fn check(path: &Path, bad: &mut bool) {
     walk(path, &mut filter_dirs, &mut |entry, contents| {
         let file = &entry.path().display();
 
-        let mut lines = contents.lines().enumerate();
+        let mut lines = contents.lines().enumerate().peekable();
         while let Some((_, line)) = lines.next() {
             if line.contains(START_COMMENT) {
                 check_section(file, &mut lines, bad);
+                if lines.peek().is_none() {
+                    tidy_error!(
+                        bad,
+                        "{file}: reached end of file expecting `// tidy-alphabetical-end`"
+                    )
+                }
             }
         }
     });