]> git.lizzy.rs Git - rust.git/blob - tests/ui/mut_range_bound.rs
Auto merge of #3603 - xfix:random-state-lint, r=phansch
[rust.git] / tests / ui / mut_range_bound.rs
1 // Copyright 2014-2018 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution.
3 //
4 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
5 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
6 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
7 // option. This file may not be copied, modified, or distributed
8 // except according to those terms.
9
10 #![allow(unused)]
11
12 fn main() {
13     mut_range_bound_upper();
14     mut_range_bound_lower();
15     mut_range_bound_both();
16     mut_range_bound_no_mutation();
17     immut_range_bound();
18     mut_borrow_range_bound();
19     immut_borrow_range_bound();
20 }
21
22 fn mut_range_bound_upper() {
23     let mut m = 4;
24     for i in 0..m {
25         m = 5;
26     } // warning
27 }
28
29 fn mut_range_bound_lower() {
30     let mut m = 4;
31     for i in m..10 {
32         m *= 2;
33     } // warning
34 }
35
36 fn mut_range_bound_both() {
37     let mut m = 4;
38     let mut n = 6;
39     for i in m..n {
40         m = 5;
41         n = 7;
42     } // warning (1 for each mutated bound)
43 }
44
45 fn mut_range_bound_no_mutation() {
46     let mut m = 4;
47     for i in 0..m {
48         continue;
49     } // no warning
50 }
51
52 fn mut_borrow_range_bound() {
53     let mut m = 4;
54     for i in 0..m {
55         let n = &mut m; // warning
56         *n += 1;
57     }
58 }
59
60 fn immut_borrow_range_bound() {
61     let mut m = 4;
62     for i in 0..m {
63         let n = &m; // should be no warning?
64     }
65 }
66
67 fn immut_range_bound() {
68     let m = 4;
69     for i in 0..m {
70         continue;
71     } // no warning
72 }