]> git.lizzy.rs Git - rust.git/blob - tests/ui/range.rs
Auto merge of #3603 - xfix:random-state-lint, r=phansch
[rust.git] / tests / ui / range.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 struct NotARange;
11 impl NotARange {
12     fn step_by(&self, _: u32) {}
13 }
14
15 #[warn(clippy::iterator_step_by_zero, clippy::range_zip_with_len)]
16 fn main() {
17     let _ = (0..1).step_by(0);
18     // No warning for non-zero step
19     let _ = (0..1).step_by(1);
20
21     let _ = (1..).step_by(0);
22     let _ = (1..=2).step_by(0);
23
24     let x = 0..1;
25     let _ = x.step_by(0);
26
27     // No error, not a range.
28     let y = NotARange;
29     y.step_by(0);
30
31     let v1 = vec![1, 2, 3];
32     let v2 = vec![4, 5];
33     let _x = v1.iter().zip(0..v1.len());
34     let _y = v1.iter().zip(0..v2.len()); // No error
35
36     // check const eval
37     let _ = v1.iter().step_by(2 / 3);
38 }
39
40 #[allow(unused)]
41 fn no_panic_with_fake_range_types() {
42     struct Range {
43         foo: i32,
44     }
45
46     let _ = Range { foo: 0 };
47 }