]> git.proxmox.com Git - rustc.git/blob - src/test/run-pass/while-let.rs
Imported Upstream version 1.7.0+dfsg1
[rustc.git] / src / test / run-pass / while-let.rs
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
12 #![feature(binary_heap_extras)]
13
14 use std::collections::BinaryHeap;
15
16 fn make_pq() -> BinaryHeap<isize> {
17 BinaryHeap::from(vec![1,2,3])
18 }
19
20 pub fn main() {
21 let mut pq = make_pq();
22 let mut sum = 0;
23 while let Some(x) = pq.pop() {
24 sum += x;
25 }
26 assert_eq!(sum, 6);
27
28 pq = make_pq();
29 sum = 0;
30 'a: while let Some(x) = pq.pop() {
31 sum += x;
32 if x == 2 {
33 break 'a;
34 }
35 }
36 assert_eq!(sum, 5);
37
38 pq = make_pq();
39 sum = 0;
40 'a: while let Some(x) = pq.pop() {
41 if x == 3 {
42 continue 'a;
43 }
44 sum += x;
45 }
46 assert_eq!(sum, 3);
47
48 let mut pq1 = make_pq();
49 sum = 0;
50 while let Some(x) = pq1.pop() {
51 let mut pq2 = make_pq();
52 while let Some(y) = pq2.pop() {
53 sum += x * y;
54 }
55 }
56 assert_eq!(sum, 6 + 12 + 18);
57 }