]> git.lizzy.rs Git - rust.git/commitdiff
Clean Up code where last whitspace tracking isn't used
authorTibo Delor <delor.thibault@gmail.com>
Sun, 10 Jun 2018 04:07:33 +0000 (14:07 +1000)
committerTibo Delor <delor.thibault@gmail.com>
Sun, 10 Jun 2018 04:07:33 +0000 (14:07 +1000)
src/lib.rs

index 8d4cbb51b5a43be338822bcda0e1672ccaee2cea..35448a087a349588eebf6b3d9a04d84c02eb0d8d 100644 (file)
@@ -517,7 +517,7 @@ fn format_lines(
     report: &FormatReport,
 ) {
     let mut trims = vec![];
-    let mut last_wspace: Option<usize> = None;
+    let mut last_was_space = false;
     let mut line_len = 0;
     let mut cur_line = 1;
     let mut newline_count = 0;
@@ -542,7 +542,7 @@ fn format_lines(
     }
 
     // Iterate over the chars in the file map.
-    for (kind, (b, c)) in CharClasses::new(text.chars().enumerate()) {
+    for (kind, c) in CharClasses::new(text.chars()) {
         if c == '\r' {
             continue;
         }
@@ -563,7 +563,7 @@ fn format_lines(
         if c == '\n' {
             if format_line {
                 // Check for (and record) trailing whitespace.
-                if let Some(..) = last_wspace {
+                if last_was_space {
                     if should_report_error(config, kind, is_string, &ErrorKind::TrailingWhitespace)
                     {
                         trims.push((cur_line, kind, line_buffer.clone()));
@@ -591,19 +591,13 @@ fn format_lines(
             cur_line += 1;
             format_line = config.file_lines().contains_line(name, cur_line);
             newline_count += 1;
-            last_wspace = None;
+            last_was_space = false;
             line_buffer.clear();
             is_string = false;
         } else {
             newline_count = 0;
             line_len += if c == '\t' { config.tab_spaces() } else { 1 };
-            if c.is_whitespace() {
-                if last_wspace.is_none() {
-                    last_wspace = Some(b);
-                }
-            } else {
-                last_wspace = None;
-            }
+            last_was_space = c.is_whitespace();
             line_buffer.push(c);
             if kind.is_string() {
                 is_string = true;