add lint declaration and example that should trigger the lint

This commit is contained in:
Laura Peskin 2017-08-11 02:21:43 +03:00
parent 4ab2223e59
commit b091fb9b24
3 changed files with 25 additions and 1 deletions

View File

@ -328,6 +328,14 @@ declare_lint! {
"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 @@ impl LintPass for Pass {
EMPTY_LOOP,
WHILE_LET_ON_ITERATOR,
FOR_KV_MAP,
NEVER_LOOP
NEVER_LOOP,
MUT_RANGE_BOUND
)
}
}

BIN
mut_range_bound Executable file

Binary file not shown.

View File

@ -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();
}