]> git.lizzy.rs Git - rust.git/commitdiff
add lint declaration and example that should trigger the lint
authorLaura Peskin <laura.peskin@gmail.com>
Thu, 10 Aug 2017 23:21:43 +0000 (02:21 +0300)
committerLaura Peskin <laura.peskin@gmail.com>
Sun, 24 Sep 2017 19:40:16 +0000 (15:40 -0400)
clippy_lints/src/loops.rs
mut_range_bound [new file with mode: 0755]
tests/run-pass/mut_range_bound.rs [new file with mode: 0644]

index 42b31f8eaaaf5eafcee0a7d5a16d7f58ad77fa00..e994b88fdcfc889132835f19c8e18d1cdbe667d8 100644 (file)
     "any loop that will always `break` or `return`"
 }
 
+/// TODO: add documentation
+
+declare_lint! {
+    pub MUT_RANGE_BOUND,
+    Warn,
+    "for loop over a range where one of the bounds is a mutable variable"
+}
+
 #[derive(Copy, Clone)]
 pub struct Pass;
 
@@ -348,7 +356,8 @@ fn get_lints(&self) -> LintArray {
             EMPTY_LOOP,
             WHILE_LET_ON_ITERATOR,
             FOR_KV_MAP,
-            NEVER_LOOP
+            NEVER_LOOP, 
+            MUT_RANGE_BOUND
         )
     }
 }
diff --git a/mut_range_bound b/mut_range_bound
new file mode 100755 (executable)
index 0000000..fdf917d
Binary files /dev/null and b/mut_range_bound differ
diff --git a/tests/run-pass/mut_range_bound.rs b/tests/run-pass/mut_range_bound.rs
new file mode 100644 (file)
index 0000000..e08babe
--- /dev/null
@@ -0,0 +1,15 @@
+#![feature(plugin)]
+#![plugin(clippy)]
+
+// cause the build to fail if this warning is invoked
+#![deny(check_for_loop_mut_bound)]
+
+// an example
+fn mut_range_bound() {
+    let mut m = 4;
+    for i in 0..m { continue; } // ERROR One of the range bounds is mutable
+}
+
+fn main(){
+    mut_range_bound();
+}