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