2018-10-06 18:18:06 +02:00
|
|
|
// Copyright 2014-2018 The Rust Project Developers. See the COPYRIGHT
|
|
|
|
// file at the top-level directory of this distribution.
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
|
|
|
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
|
|
|
// option. This file may not be copied, modified, or distributed
|
|
|
|
// except according to those terms.
|
|
|
|
|
2017-08-30 19:07:25 +02:00
|
|
|
#![allow(unused)]
|
|
|
|
|
2017-08-15 18:41:59 +02:00
|
|
|
fn main() {
|
|
|
|
mut_range_bound_upper();
|
|
|
|
mut_range_bound_lower();
|
|
|
|
mut_range_bound_both();
|
2017-09-19 02:10:33 +02:00
|
|
|
mut_range_bound_no_mutation();
|
2017-08-15 18:41:59 +02:00
|
|
|
immut_range_bound();
|
2017-09-25 08:00:21 +02:00
|
|
|
mut_borrow_range_bound();
|
|
|
|
immut_borrow_range_bound();
|
2017-08-15 18:41:59 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
fn mut_range_bound_upper() {
|
|
|
|
let mut m = 4;
|
2018-12-09 23:26:16 +01:00
|
|
|
for i in 0..m {
|
|
|
|
m = 5;
|
|
|
|
} // warning
|
2017-08-15 18:41:59 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
fn mut_range_bound_lower() {
|
|
|
|
let mut m = 4;
|
2018-12-09 23:26:16 +01:00
|
|
|
for i in m..10 {
|
|
|
|
m *= 2;
|
|
|
|
} // warning
|
2017-08-15 18:41:59 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
fn mut_range_bound_both() {
|
|
|
|
let mut m = 4;
|
|
|
|
let mut n = 6;
|
2018-12-09 23:26:16 +01:00
|
|
|
for i in m..n {
|
|
|
|
m = 5;
|
|
|
|
n = 7;
|
|
|
|
} // warning (1 for each mutated bound)
|
2017-09-19 02:10:33 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
fn mut_range_bound_no_mutation() {
|
|
|
|
let mut m = 4;
|
2018-12-09 23:26:16 +01:00
|
|
|
for i in 0..m {
|
|
|
|
continue;
|
|
|
|
} // no warning
|
2017-08-15 18:41:59 +02:00
|
|
|
}
|
|
|
|
|
2017-09-19 02:10:33 +02:00
|
|
|
fn mut_borrow_range_bound() {
|
|
|
|
let mut m = 4;
|
|
|
|
for i in 0..m {
|
2018-12-09 23:26:16 +01:00
|
|
|
let n = &mut m; // warning
|
2017-09-26 03:32:05 +02:00
|
|
|
*n += 1;
|
2017-09-25 08:00:21 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn immut_borrow_range_bound() {
|
|
|
|
let mut m = 4;
|
|
|
|
for i in 0..m {
|
2018-12-09 23:26:16 +01:00
|
|
|
let n = &m; // should be no warning?
|
2017-09-19 02:10:33 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-08-15 18:41:59 +02:00
|
|
|
fn immut_range_bound() {
|
|
|
|
let m = 4;
|
2018-12-09 23:26:16 +01:00
|
|
|
for i in 0..m {
|
|
|
|
continue;
|
|
|
|
} // no warning
|
2017-08-15 18:41:59 +02:00
|
|
|
}
|