mirror of
https://github.com/rust-lang/rust-clippy
synced 2024-12-23 03:23:33 +00:00
38d4ac7cea
Discussion previously happened in https://github.com/rust-lang/rust/pull/43498
63 lines
1.1 KiB
Rust
63 lines
1.1 KiB
Rust
#![allow(unused)]
|
|
|
|
fn main() {
|
|
mut_range_bound_upper();
|
|
mut_range_bound_lower();
|
|
mut_range_bound_both();
|
|
mut_range_bound_no_mutation();
|
|
immut_range_bound();
|
|
mut_borrow_range_bound();
|
|
immut_borrow_range_bound();
|
|
}
|
|
|
|
fn mut_range_bound_upper() {
|
|
let mut m = 4;
|
|
for i in 0..m {
|
|
m = 5;
|
|
} // warning
|
|
}
|
|
|
|
fn mut_range_bound_lower() {
|
|
let mut m = 4;
|
|
for i in m..10 {
|
|
m *= 2;
|
|
} // warning
|
|
}
|
|
|
|
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
|
|
}
|
|
|
|
fn mut_borrow_range_bound() {
|
|
let mut m = 4;
|
|
for i in 0..m {
|
|
let n = &mut m; // warning
|
|
*n += 1;
|
|
}
|
|
}
|
|
|
|
fn immut_borrow_range_bound() {
|
|
let mut m = 4;
|
|
for i in 0..m {
|
|
let n = &m; // should be no warning?
|
|
}
|
|
}
|
|
|
|
fn immut_range_bound() {
|
|
let m = 4;
|
|
for i in 0..m {
|
|
continue;
|
|
} // no warning
|
|
}
|