From: Laura Peskin Date: Thu, 10 Aug 2017 23:21:43 +0000 (+0300) Subject: add lint declaration and example that should trigger the lint X-Git-Url: https://git.lizzy.rs/?a=commitdiff_plain;h=b091fb9b2464907a34279ab99aeffd0552827192;p=rust.git add lint declaration and example that should trigger the lint --- diff --git a/clippy_lints/src/loops.rs b/clippy_lints/src/loops.rs index 42b31f8eaaa..e994b88fdcf 100644 --- a/clippy_lints/src/loops.rs +++ b/clippy_lints/src/loops.rs @@ -328,6 +328,14 @@ "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 index 00000000000..fdf917d5158 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 index 00000000000..e08babe3137 --- /dev/null +++ b/tests/run-pass/mut_range_bound.rs @@ -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(); +}