]> git.lizzy.rs Git - rust.git/blobdiff - src/issues.rs
rewrite_string: retain blank lines that are trailing
[rust.git] / src / issues.rs
index 2efd61a3d7d458851c4f05770134a368b15264b9..ad7babca118109a3278f94880bf0c98afb64b761 100644 (file)
 
 use std::fmt;
 
-pub use config::ReportTactic;
+use config::ReportTactic;
 
 const TO_DO_CHARS: &[char] = &['t', 'o', 'd', 'o'];
 const FIX_ME_CHARS: &[char] = &['f', 'i', 'x', 'm', 'e'];
 
 // Enabled implementation detail is here because it is
 // irrelevant outside the issues module
-impl ReportTactic {
-    fn is_enabled(&self) -> bool {
-        *self != ReportTactic::Never
-    }
+fn is_enabled(report_tactic: ReportTactic) -> bool {
+    report_tactic != ReportTactic::Never
 }
 
 #[derive(Clone, Copy)]
@@ -95,6 +93,10 @@ pub fn new(report_todo: ReportTactic, report_fixme: ReportTactic) -> BadIssueSee
         }
     }
 
+    pub fn is_disabled(&self) -> bool {
+        !is_enabled(self.report_todo) && !is_enabled(self.report_fixme)
+    }
+
     // Check whether or not the current char is conclusive evidence for an
     // unnumbered TO-DO or FIX-ME.
     pub fn inspect(&mut self, c: char) -> Option<Issue> {
@@ -128,7 +130,7 @@ pub fn inspect(&mut self, c: char) -> Option<Issue> {
 
     fn inspect_issue(&mut self, c: char, mut todo_idx: usize, mut fixme_idx: usize) -> Seeking {
         if let Some(lower_case_c) = c.to_lowercase().next() {
-            if self.report_todo.is_enabled() && lower_case_c == TO_DO_CHARS[todo_idx] {
+            if is_enabled(self.report_todo) && lower_case_c == TO_DO_CHARS[todo_idx] {
                 todo_idx += 1;
                 if todo_idx == TO_DO_CHARS.len() {
                     return Seeking::Number {
@@ -144,7 +146,7 @@ fn inspect_issue(&mut self, c: char, mut todo_idx: usize, mut fixme_idx: usize)
                     };
                 }
                 fixme_idx = 0;
-            } else if self.report_fixme.is_enabled() && lower_case_c == FIX_ME_CHARS[fixme_idx] {
+            } else if is_enabled(self.report_fixme) && lower_case_c == FIX_ME_CHARS[fixme_idx] {
                 // Exploit the fact that the character sets of todo and fixme
                 // are disjoint by adding else.
                 fixme_idx += 1;
@@ -225,13 +227,13 @@ fn check_fail(text: &str, failing_pos: usize) {
         let mut seeker = BadIssueSeeker::new(ReportTactic::Unnumbered, ReportTactic::Unnumbered);
         assert_eq!(
             Some(failing_pos),
-            text.chars().position(|c| seeker.inspect(c).is_some())
+            text.find(|c| seeker.inspect(c).is_some())
         );
     }
 
     fn check_pass(text: &str) {
         let mut seeker = BadIssueSeeker::new(ReportTactic::Unnumbered, ReportTactic::Unnumbered);
-        assert_eq!(None, text.chars().position(|c| seeker.inspect(c).is_some()));
+        assert_eq!(None, text.find(|c| seeker.inspect(c).is_some()));
     }
 
     check_fail("TODO\n", 4);