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