File tree 3 files changed +93
-0
lines changed
3 files changed +93
-0
lines changed Original file line number Diff line number Diff line change
1
+ // Copyright 2014 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 range syntax - type errors.
12
+
13
+ pub fn main ( ) {
14
+ // Mixed types.
15
+ let _ = 0 u..10 i;
16
+ //~^ ERROR mismatched types: expected `uint`, found `int`
17
+
18
+ // Float => does not implement iterator.
19
+ for i in 0f32 ..42f32 { }
20
+ //~^ ERROR `for` loop expression has type `core::ops::Range<f32>` which does not implement
21
+
22
+ // Unsized type.
23
+ let arr: & [ _ ] = & [ 1 u, 2 , 3 ] ;
24
+ let range = ( * arr) ..;
25
+ //~^ ERROR the trait `core::kinds::Sized` is not implemented
26
+ }
Original file line number Diff line number Diff line change
1
+ // Copyright 2014 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 range syntax - borrow errors.
12
+
13
+ pub fn main ( ) {
14
+ let x = & 42 i;
15
+ {
16
+ let y = 42 i;
17
+ let r = x..& y;
18
+ //~^ ERROR `y` does not live long enough
19
+ }
20
+
21
+ let r = {
22
+ ( & 42 i) ..& 42
23
+ //~^ ERROR borrowed value does not live long enough
24
+ //~^^ ERROR borrowed value does not live long enough
25
+ } ;
26
+ }
Original file line number Diff line number Diff line change
1
+ // Copyright 2014 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 range syntax.
12
+
13
+ fn foo ( ) -> int { 42 }
14
+
15
+ pub fn main ( ) {
16
+ let mut count = 0 ;
17
+ for i in 0 u..10 {
18
+ assert ! ( i >= 0 && i < 10 ) ;
19
+ count += i;
20
+ }
21
+ assert ! ( count == 45 ) ;
22
+
23
+ let mut count = 0 ;
24
+ let mut range = 0 u..10 ;
25
+ for i in range {
26
+ assert ! ( i >= 0 && i < 10 ) ;
27
+ count += i;
28
+ }
29
+ assert ! ( count == 45 ) ;
30
+
31
+ let mut count = 0 ;
32
+ let mut rf = 3 u..;
33
+ for i in rf. take ( 10 ) {
34
+ assert ! ( i >= 3 && i < 13 ) ;
35
+ count += i;
36
+ }
37
+ assert ! ( count == 75 ) ;
38
+
39
+ let _ = 0 u..4 +4 -3 ;
40
+ let _ = 0 ..foo ( ) ;
41
+ }
You can’t perform that action at this time.
0 commit comments