]> git.lizzy.rs Git - rust.git/blob - src/test/run-pass/pure-sum.rs
Auto merge of #54265 - arielb1:civilize-proc-macros, r=alexcrichton
[rust.git] / src / test / run-pass / pure-sum.rs
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
11 #![allow(dead_code)]
12 // Check that functions can modify local state.
13
14 // pretty-expanded FIXME #23616
15
16 #![feature(box_syntax)]
17
18 fn sums_to(v: Vec<isize> , sum: isize) -> bool {
19     let mut i = 0;
20     let mut sum0 = 0;
21     while i < v.len() {
22         sum0 += v[i];
23         i += 1;
24     }
25     return sum0 == sum;
26 }
27
28 fn sums_to_using_uniq(v: Vec<isize> , sum: isize) -> bool {
29     let mut i = 0;
30     let mut sum0: Box<_> = box 0;
31     while i < v.len() {
32         *sum0 += v[i];
33         i += 1;
34     }
35     return *sum0 == sum;
36 }
37
38 fn sums_to_using_rec(v: Vec<isize> , sum: isize) -> bool {
39     let mut i = 0;
40     let mut sum0 = F {f: 0};
41     while i < v.len() {
42         sum0.f += v[i];
43         i += 1;
44     }
45     return sum0.f == sum;
46 }
47
48 struct F<T> { f: T }
49
50 fn sums_to_using_uniq_rec(v: Vec<isize> , sum: isize) -> bool {
51     let mut i = 0;
52     let mut sum0 = F::<Box<_>> {f: box 0};
53     while i < v.len() {
54         *sum0.f += v[i];
55         i += 1;
56     }
57     return *sum0.f == sum;
58 }
59
60 pub fn main() {
61 }