Skip to content

Commit 8aa0795

Browse files
committed
---
yaml --- r: 272827 b: refs/heads/beta c: 69719df h: refs/heads/master i: 272825: 7fb6547 272823: b01a101
1 parent 9a507a5 commit 8aa0795

File tree

6 files changed

+237
-1
lines changed

6 files changed

+237
-1
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ refs/tags/0.9: 36870b185fc5f5486636d4515f0e22677493f225
2323
refs/tags/0.10: ac33f2b15782272ae348dbd7b14b8257b2148b5a
2424
refs/tags/0.11.0: e1247cb1d0d681be034adb4b558b5a0c0d5720f9
2525
refs/tags/0.12.0: f0c419429ef30723ceaf6b42f9b5a2aeb5d2e2d1
26-
refs/heads/beta: 37a4cb32121bed9165f9bac696953f055f691aef
26+
refs/heads/beta: 69719df6116b584b71ee5a8d22974835c33b13be
2727
refs/tags/1.0.0-alpha: e42bd6d93a1d3433c486200587f8f9e12590a4d7
2828
refs/heads/tmp: e06d2ad9fcd5027bcaac5b08fc9aa39a49d0ecd3
2929
refs/tags/1.0.0-alpha.2: 4c705f6bc559886632d3871b04f58aab093bfa2f
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
// Make sure that #![feature(inclusive_range)] is required.
12+
13+
#![feature(inclusive_range_syntax)]
14+
// #![feature(inclusive_range)]
15+
16+
pub fn main() {
17+
let _: std::ops::RangeInclusive<_> = 1...10;
18+
//~^ ERROR use of unstable library feature 'inclusive_range'
19+
}
20+
21+
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
// Make sure that inclusive ranges with no end point don't parse.
12+
13+
#![feature(inclusive_range_syntax, inclusive_range)]
14+
15+
pub fn main() {
16+
for _ in 1... {}
17+
} //~ ERROR expected one of
18+
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
// Make sure that #![feature(inclusive_range_syntax)] is required.
12+
13+
// #![feature(inclusive_range_syntax, inclusive_range)]
14+
15+
macro_rules! m {
16+
() => { for _ in 1...10 {} } //~ ERROR inclusive range syntax is experimental
17+
}
18+
19+
#[cfg(nope)]
20+
fn f() {}
21+
#[cfg(not(nope))]
22+
fn f() {
23+
for _ in 1...10 {} //~ ERROR inclusive range syntax is experimental
24+
}
25+
26+
#[cfg(nope)]
27+
macro_rules! n { () => {} }
28+
#[cfg(not(nope))]
29+
macro_rules! n {
30+
() => { for _ in 1...10 {} } //~ ERROR inclusive range syntax is experimental
31+
}
32+
33+
macro_rules! o {
34+
() => {{
35+
#[cfg(nope)]
36+
fn g() {}
37+
#[cfg(not(nope))]
38+
fn g() {
39+
for _ in 1...10 {} //~ ERROR inclusive range syntax is experimental
40+
}
41+
42+
g();
43+
}}
44+
}
45+
46+
#[cfg(nope)]
47+
macro_rules! p { () => {} }
48+
#[cfg(not(nope))]
49+
macro_rules! p {
50+
() => {{
51+
#[cfg(nope)]
52+
fn h() {}
53+
#[cfg(not(nope))]
54+
fn h() {
55+
for _ in 1...10 {} //~ ERROR inclusive range syntax is experimental
56+
}
57+
58+
h();
59+
}}
60+
}
61+
62+
pub fn main() {
63+
for _ in 1...10 {} //~ ERROR inclusive range syntax is experimental
64+
for _ in ...10 {} //~ ERROR inclusive range syntax is experimental
65+
66+
f(); // not allowed in cfg'ed functions
67+
68+
m!(); // not allowed in macros
69+
n!(); // not allowed in cfg'ed macros
70+
o!(); // not allowed in macros that output cfgs
71+
p!(); // not allowed in cfg'ed macros that output cfgs
72+
}
73+
74+
Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
// Test inclusive range syntax.
12+
13+
#![feature(inclusive_range_syntax, inclusive_range)]
14+
15+
use std::ops::{RangeInclusive, RangeToInclusive};
16+
17+
fn foo() -> isize { 42 }
18+
19+
// Test that range syntax works in return statements
20+
fn return_range_to() -> RangeToInclusive<i32> { return ...1; }
21+
22+
pub fn main() {
23+
let mut count = 0;
24+
for i in 0_usize...10 {
25+
assert!(i >= 0 && i <= 10);
26+
count += i;
27+
}
28+
assert_eq!(count, 55);
29+
30+
let mut count = 0;
31+
let mut range = 0_usize...10;
32+
for i in range {
33+
assert!(i >= 0 && i <= 10);
34+
count += i;
35+
}
36+
assert_eq!(count, 55);
37+
38+
/* FIXME
39+
let mut count = 0;
40+
for i in (0_usize...10).step_by(2) {
41+
assert!(i >= 0 && i <= 10 && i % 2 == 0);
42+
count += i;
43+
}
44+
assert_eq!(count, 30);
45+
*/
46+
47+
let _ = 0_usize...4+4-3;
48+
let _ = 0...foo();
49+
50+
let _ = { &42...&100 }; // references to literals are OK
51+
let _ = ...42_usize;
52+
53+
// Test we can use two different types with a common supertype.
54+
let x = &42;
55+
{
56+
let y = 42;
57+
let _ = x...&y;
58+
}
59+
60+
// test the size hints and emptying
61+
let mut long = 0...255u8;
62+
let mut short = 42...42;
63+
assert_eq!(long.size_hint(), (256, Some(256)));
64+
assert_eq!(short.size_hint(), (1, Some(1)));
65+
long.next();
66+
short.next();
67+
assert_eq!(long.size_hint(), (255, Some(255)));
68+
assert_eq!(short.size_hint(), (0, Some(0)));
69+
assert_eq!(short, RangeInclusive::Empty { at: 42 });
70+
71+
assert_eq!(long.len(), 255);
72+
assert_eq!(short.len(), 0);
73+
74+
// test iterating backwards
75+
assert_eq!(long.next_back(), Some(255));
76+
assert_eq!(long.next_back(), Some(254));
77+
assert_eq!(long.next_back(), Some(253));
78+
assert_eq!(long.next(), Some(1));
79+
assert_eq!(long.next(), Some(2));
80+
assert_eq!(long.next_back(), Some(252));
81+
for i in 3...251 {
82+
assert_eq!(long.next(), Some(i));
83+
}
84+
assert_eq!(long, RangeInclusive::Empty { at: 251 });
85+
86+
// what happens if you have a nonsense range?
87+
let mut nonsense = 10...5;
88+
assert_eq!(nonsense.next(), None);
89+
assert_eq!(nonsense, RangeInclusive::Empty { at: 10 });
90+
91+
// conversion
92+
assert_eq!(0...9, (0..10).into());
93+
assert_eq!(0...0, (0..1).into());
94+
assert_eq!(RangeInclusive::Empty { at: 1 }, (1..0).into());
95+
96+
// output
97+
assert_eq!(format!("{:?}", 0...10), "0...10");
98+
assert_eq!(format!("{:?}", ...10), "...10");
99+
assert_eq!(format!("{:?}", long), "[empty range @ 251]");
100+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
// Test that you only need the syntax gate if you don't mention the structs.
12+
13+
#![feature(inclusive_range_syntax)]
14+
15+
fn main() {
16+
let mut count = 0;
17+
for i in 0_usize...10 {
18+
assert!(i >= 0 && i <= 10);
19+
count += i;
20+
}
21+
assert_eq!(count, 55);
22+
}
23+

0 commit comments

Comments
 (0)