2017-06-18 13:14:46 +00:00
|
|
|
#![feature(iterator_step_by)]
|
2016-04-26 11:31:52 +00:00
|
|
|
#![feature(inclusive_range_syntax)]
|
2017-09-18 10:47:33 +00:00
|
|
|
|
|
|
|
|
2015-08-15 16:55:25 +00:00
|
|
|
|
|
|
|
struct NotARange;
|
|
|
|
impl NotARange {
|
|
|
|
fn step_by(&self, _: u32) {}
|
|
|
|
}
|
|
|
|
|
2017-06-18 13:14:46 +00:00
|
|
|
#[warn(iterator_step_by_zero, range_zip_with_len)]
|
2015-08-15 16:55:25 +00:00
|
|
|
fn main() {
|
2017-07-05 06:51:33 +00:00
|
|
|
let _ = (0..1).step_by(0);
|
2015-08-15 16:55:25 +00:00
|
|
|
// No warning for non-zero step
|
2017-07-05 06:14:24 +00:00
|
|
|
let _ = (0..1).step_by(1);
|
2015-08-15 16:55:25 +00:00
|
|
|
|
2017-07-05 06:51:33 +00:00
|
|
|
let _ = (1..).step_by(0);
|
2017-09-28 17:40:19 +00:00
|
|
|
let _ = (1..=2).step_by(0);
|
2017-07-05 06:51:33 +00:00
|
|
|
|
|
|
|
let x = 0..1;
|
|
|
|
let _ = x.step_by(0);
|
|
|
|
|
2015-08-15 16:55:25 +00:00
|
|
|
// No error, not a range.
|
|
|
|
let y = NotARange;
|
|
|
|
y.step_by(0);
|
2015-11-03 14:42:52 +00:00
|
|
|
|
2015-12-13 05:35:35 +00:00
|
|
|
let v1 = vec![1,2,3];
|
|
|
|
let v2 = vec![4,5];
|
2017-02-08 13:58:07 +00:00
|
|
|
let _x = v1.iter().zip(0..v1.len());
|
2015-12-13 05:35:35 +00:00
|
|
|
let _y = v1.iter().zip(0..v2.len()); // No error
|
2017-07-05 06:51:33 +00:00
|
|
|
|
|
|
|
// check const eval
|
|
|
|
let _ = v1.iter().step_by(2/3);
|
2015-08-15 16:55:25 +00:00
|
|
|
}
|
2017-10-12 14:24:21 +00:00
|
|
|
|
|
|
|
#[allow(unused)]
|
|
|
|
fn no_panic_with_fake_range_types() {
|
|
|
|
struct Range {
|
|
|
|
foo: i32,
|
|
|
|
}
|
|
|
|
|
|
|
|
let _ = Range { foo: 0 };
|
|
|
|
}
|