Skip to content

Commit 0fa94e7

Browse files
committed
Fix some RangeInclusive test cases.
1 parent 4d9b6c9 commit 0fa94e7

File tree

1 file changed

+19
-10
lines changed

1 file changed

+19
-10
lines changed

src/test/run-pass/range_inclusive.rs

+19-10
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,18 @@
1010

1111
// Test inclusive range syntax.
1212

13-
use std::ops::{RangeInclusive, RangeToInclusive};
13+
#![feature(range_is_empty)]
14+
#![allow(unused_comparisons)]
15+
16+
use std::ops::RangeToInclusive;
1417

1518
fn foo() -> isize { 42 }
1619

1720
// Test that range syntax works in return statements
18-
fn return_range_to() -> RangeToInclusive<i32> { return ..=1; }
21+
pub fn return_range_to() -> RangeToInclusive<i32> { return ..=1; }
22+
23+
#[derive(Debug)]
24+
struct P(u8);
1925

2026
pub fn main() {
2127
let mut count = 0;
@@ -26,7 +32,7 @@ pub fn main() {
2632
assert_eq!(count, 55);
2733

2834
let mut count = 0;
29-
let mut range = 0_usize..=10;
35+
let range = 0_usize..=10;
3036
for i in range {
3137
assert!(i >= 0 && i <= 10);
3238
count += i;
@@ -80,7 +86,7 @@ pub fn main() {
8086
short.next();
8187
assert_eq!(long.size_hint(), (255, Some(255)));
8288
assert_eq!(short.size_hint(), (0, Some(0)));
83-
assert_eq!(short, 1..=0);
89+
assert!(short.is_empty());
8490

8591
assert_eq!(long.len(), 255);
8692
assert_eq!(short.len(), 0);
@@ -95,28 +101,31 @@ pub fn main() {
95101
for i in 3..=251 {
96102
assert_eq!(long.next(), Some(i));
97103
}
98-
assert_eq!(long, 1..=0);
104+
assert!(long.is_empty());
99105

100106
// check underflow
101107
let mut narrow = 1..=0;
102108
assert_eq!(narrow.next_back(), None);
103-
assert_eq!(narrow, 1..=0);
109+
assert!(narrow.is_empty());
104110
let mut zero = 0u8..=0;
105111
assert_eq!(zero.next_back(), Some(0));
106112
assert_eq!(zero.next_back(), None);
107-
assert_eq!(zero, 1..=0);
113+
assert!(zero.is_empty());
108114
let mut high = 255u8..=255;
109115
assert_eq!(high.next_back(), Some(255));
110116
assert_eq!(high.next_back(), None);
111-
assert_eq!(high, 1..=0);
117+
assert!(high.is_empty());
112118

113119
// what happens if you have a nonsense range?
114120
let mut nonsense = 10..=5;
115121
assert_eq!(nonsense.next(), None);
116-
assert_eq!(nonsense, 10..=5);
122+
assert!(nonsense.is_empty());
117123

118124
// output
119125
assert_eq!(format!("{:?}", 0..=10), "0..=10");
120126
assert_eq!(format!("{:?}", ..=10), "..=10");
121-
assert_eq!(format!("{:?}", long), "1..=0");
127+
assert_eq!(format!("{:?}", 9..=6), "9..=6");
128+
129+
// ensure that constructing a RangeInclusive does not need PartialOrd bound
130+
assert_eq!(format!("{:?}", P(1)..=P(2)), "P(1)..=P(2)");
122131
}

0 commit comments

Comments
 (0)