rust/tests/run-pass/mut_range_bound_tmp.rs

48 lines
862 B
Rust
Raw Normal View History

2017-08-15 11:41:59 -05:00
#![feature(plugin)]
#![plugin(clippy)]
2017-08-30 12:07:25 -05:00
#![allow(unused)]
2017-08-15 11:41:59 -05:00
fn main() {
mut_range_bound_upper();
mut_range_bound_lower();
mut_range_bound_both();
mut_range_bound_no_mutation();
2017-08-15 11:41:59 -05:00
immut_range_bound();
}
fn mut_range_bound_upper() {
let mut m = 4;
for i in 0..m { m = 5; } // warning
2017-08-15 11:41:59 -05:00
}
fn mut_range_bound_lower() {
let mut m = 4;
for i in m..10 { m *= 2; } // warning
2017-08-15 11:41:59 -05:00
}
fn mut_range_bound_both() {
let mut m = 4;
let mut n = 6;
for i in m..n { m = 5; n = 7; } // warning (1 for each mutated bound)
}
fn mut_range_bound_no_mutation() {
let mut m = 4;
for i in 0..m { continue; } // no warning
2017-08-15 11:41:59 -05:00
}
fn mut_borrow_range_bound() {
let mut m = 4;
for i in 0..m {
let n = &mut m;
*n += 1;
}
}
2017-08-15 11:41:59 -05:00
fn immut_range_bound() {
let m = 4;
for i in 0..m { continue; } // no warning
}