From bfc31536c74a30b49ba84c6539620a0aecc1504a Mon Sep 17 00:00:00 2001 From: Manish Goregaokar Date: Mon, 25 Sep 2017 18:32:05 -0700 Subject: [PATCH] Make it a ui test, update --- tests/run-pass/mut_range_bound.rs | 15 -------- .../mut_range_bound.rs} | 6 ++-- tests/ui/mut_range_bound.stderr | 34 +++++++++++++++++++ 3 files changed, 37 insertions(+), 18 deletions(-) delete mode 100644 tests/run-pass/mut_range_bound.rs rename tests/{run-pass/mut_range_bound_tmp.rs => ui/mut_range_bound.rs} (88%) create mode 100644 tests/ui/mut_range_bound.stderr diff --git a/tests/run-pass/mut_range_bound.rs b/tests/run-pass/mut_range_bound.rs deleted file mode 100644 index e08babe31..000000000 --- a/tests/run-pass/mut_range_bound.rs +++ /dev/null @@ -1,15 +0,0 @@ -#![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(); -} diff --git a/tests/run-pass/mut_range_bound_tmp.rs b/tests/ui/mut_range_bound.rs similarity index 88% rename from tests/run-pass/mut_range_bound_tmp.rs rename to tests/ui/mut_range_bound.rs index 1a7159c33..835ceeedc 100644 --- a/tests/run-pass/mut_range_bound_tmp.rs +++ b/tests/ui/mut_range_bound.rs @@ -15,7 +15,7 @@ fn main() { fn mut_range_bound_upper() { let mut m = 4; - for i in 0..m { m = 5; } // warning + for i in 0..m { m = 5; } // warning } fn mut_range_bound_lower() { @@ -37,8 +37,8 @@ fn mut_range_bound_no_mutation() { fn mut_borrow_range_bound() { let mut m = 4; for i in 0..m { - let n = &mut m; // warning here? - *n += 1; // or here? + let n = &mut m; // warning + *n += 1; } } diff --git a/tests/ui/mut_range_bound.stderr b/tests/ui/mut_range_bound.stderr new file mode 100644 index 000000000..d7be7ae1e --- /dev/null +++ b/tests/ui/mut_range_bound.stderr @@ -0,0 +1,34 @@ +error: attempt to mutate range bound within loop; note that the range of the loop is unchanged + --> $DIR/mut_range_bound.rs:18:21 + | +18 | for i in 0..m { m = 5; } // warning + | ^^^^^ + | + = note: `-D mut-range-bound` implied by `-D warnings` + +error: attempt to mutate range bound within loop; note that the range of the loop is unchanged + --> $DIR/mut_range_bound.rs:23:22 + | +23 | for i in m..10 { m *= 2; } // warning + | ^^^^^^ + +error: attempt to mutate range bound within loop; note that the range of the loop is unchanged + --> $DIR/mut_range_bound.rs:29:21 + | +29 | for i in m..n { m = 5; n = 7; } // warning (1 for each mutated bound) + | ^^^^^ + +error: attempt to mutate range bound within loop; note that the range of the loop is unchanged + --> $DIR/mut_range_bound.rs:29:28 + | +29 | for i in m..n { m = 5; n = 7; } // warning (1 for each mutated bound) + | ^^^^^ + +error: attempt to mutate range bound within loop; note that the range of the loop is unchanged + --> $DIR/mut_range_bound.rs:40:22 + | +40 | let n = &mut m; // warning + | ^ + +error: aborting due to 5 previous errors +