]> git.lizzy.rs Git - rust.git/blob - src/test/run-pass/issue-2185.rs
auto merge of #19514 : jbranchaud/rust/add-btree-set-bitor, r=Gankro
[rust.git] / src / test / run-pass / issue-2185.rs
1 // Copyright 2012-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 // ignore-test
12 // ignore-lexer-test FIXME #15881
13
14 // notes on this test case:
15 // On Thu, Apr 18, 2013-2014 at 6:30 PM, John Clements <clements@brinckerhoff.org> wrote:
16 // the "issue-2185.rs" test was ignored with a ref to #2263. Issue #2263 is now fixed,
17 // so I tried it again, and after adding some &self parameters, I got this error:
18 //
19 // Running /usr/local/bin/rustc:
20 // issue-2185.rs:24:0: 26:1 error: conflicting implementations for a trait
21 // issue-2185.rs:24 impl iterable<uint> for 'static ||uint|| {
22 // issue-2185.rs:25     fn iter(&self, blk: |v: uint|) { self( |i| blk(i) ) }
23 // issue-2185.rs:26 }
24 // issue-2185.rs:20:0: 22:1 note: note conflicting implementation here
25 // issue-2185.rs:20 impl<A> iterable<A> for 'static ||A|| {
26 // issue-2185.rs:21     fn iter(&self, blk: |A|) { self(blk); }
27 // issue-2185.rs:22 }
28 //
29 // … so it looks like it's just not possible to implement both
30 // the generic iterable<uint> and iterable<A> for the type iterable<uint>.
31 // Is it okay if I just remove this test?
32 //
33 // but Niko responded:
34 // think it's fine to remove this test, just because it's old and cruft and not hard to reproduce.
35 // *However* it should eventually be possible to implement the same interface for the same type
36 // multiple times with different type parameters, it's just that our current trait implementation
37 // has accidental limitations.
38
39 // so I'm leaving it in.
40 // actually, it looks like this is related to bug #3429. I'll rename this bug.
41
42 // This test had to do with an outdated version of the iterable trait.
43 // However, the condition it was testing seemed complex enough to
44 // warrant still having a test, so I inlined the old definitions.
45
46 trait iterable<A> {
47     fn iter(&self, blk: |A|);
48 }
49
50 impl<A> iterable<A> for 'static ||A|| {
51     fn iter(&self, blk: |A|) { self(blk); }
52 }
53
54 impl iterable<uint> for 'static ||uint|| {
55     fn iter(&self, blk: |v: uint|) { self( |i| blk(i) ) }
56 }
57
58 fn filter<A,IA:iterable<A>>(self: IA, prd: 'static |A| -> bool, blk: |A|) {
59     self.iter(|a| {
60         if prd(a) { blk(a) }
61     });
62 }
63
64 fn foldl<A,B,IA:iterable<A>>(self: IA, b0: B, blk: |B, A| -> B) -> B {
65     let mut b = b0;
66     self.iter(|a| {
67         b = blk(b, a);
68     });
69     b
70 }
71
72 fn range(lo: uint, hi: uint, it: |uint|) {
73     let mut i = lo;
74     while i < hi {
75         it(i);
76         i += 1u;
77     }
78 }
79
80 pub fn main() {
81     let range: 'static ||uint|| = |a| range(0u, 1000u, a);
82     let filt: 'static ||v: uint|| = |a| filter(
83         range,
84         |&&n: uint| n % 3u != 0u && n % 5u != 0u,
85         a);
86     let sum = foldl(filt, 0u, |accum, &&n: uint| accum + n );
87
88     println!("{}", sum);
89 }