Graydon Hoare | d1affff | 2012-12-11 01:32:48 | [diff] [blame] | 1 | // Copyright 2012 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 | |
Graydon Hoare | ce72993 | 2011-06-15 18:19:50 | [diff] [blame] | 11 | |
| 12 | |
Patrick Walton | d18f785 | 2013-03-07 22:38:38 | [diff] [blame] | 13 | fn pairs(it: &fn((int, int))) { |
Niko Matsakis | dc07280 | 2012-03-22 15:39:41 | [diff] [blame] | 14 | let mut i: int = 0; |
| 15 | let mut j: int = 0; |
Marijn Haverbeke | 050170d | 2011-10-21 11:14:28 | [diff] [blame] | 16 | while i < 10 { it((i, j)); i += 1; j += i; } |
Graydon Hoare | d6b7c96 | 2010-06-24 04:03:09 | [diff] [blame] | 17 | } |
| 18 | |
Graydon Hoare | 89c8ef7 | 2013-02-02 03:43:17 | [diff] [blame] | 19 | pub fn main() { |
Niko Matsakis | dc07280 | 2012-03-22 15:39:41 | [diff] [blame] | 20 | let mut i: int = 10; |
| 21 | let mut j: int = 0; |
Brian Anderson | d1fc2b5 | 2012-06-30 23:19:07 | [diff] [blame] | 22 | do pairs() |p| { |
Marijn Haverbeke | 050170d | 2011-10-21 11:14:28 | [diff] [blame] | 23 | let (_0, _1) = p; |
Huon Wilson | e4f7561 | 2013-07-16 17:08:08 | [diff] [blame] | 24 | info!(_0); |
| 25 | info!(_1); |
Corey Richardson | cc57ca0 | 2013-05-19 02:02:45 | [diff] [blame] | 26 | assert_eq!(_0 + 10, i); |
Graydon Hoare | ce72993 | 2011-06-15 18:19:50 | [diff] [blame] | 27 | i += 1; |
Marijn Haverbeke | 050170d | 2011-10-21 11:14:28 | [diff] [blame] | 28 | j = _1; |
| 29 | }; |
Corey Richardson | cc57ca0 | 2013-05-19 02:02:45 | [diff] [blame] | 30 | assert_eq!(j, 45); |
Lindsey Kuper | f91351a | 2011-08-16 04:54:52 | [diff] [blame] | 31 | } |