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