2012-12-10 17:32:48 -08:00
// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
2013-04-18 16:48:33 -07:00
// does the second one subsume the first?
// xfail-test
2012-09-19 13:59:44 -07:00
// xfail-fast
2013-04-18 16:48:33 -07:00
// notes on this test case:
// On Thu, Apr 18, 2013 at 6:30 PM, John Clements <clements@brinckerhoff.org> wrote:
// the "issue-2185.rs" test was xfailed with a ref to #2263. Issue #2263 is now fixed, so I tried it again, and after adding some &self parameters, I got this error:
2013-05-03 19:25:04 -04:00
//
2013-04-18 16:48:33 -07:00
// Running /usr/local/bin/rustc:
// issue-2185.rs:24:0: 26:1 error: conflicting implementations for a trait
2013-11-19 17:36:32 -08:00
// issue-2185.rs:24 impl iterable<uint> for 'static ||uint|| {
2013-11-19 16:34:19 -08:00
// issue-2185.rs:25 fn iter(&self, blk: |v: uint|) { self( |i| blk(i) ) }
2013-04-18 16:48:33 -07:00
// issue-2185.rs:26 }
// issue-2185.rs:20:0: 22:1 note: note conflicting implementation here
2013-11-19 16:34:19 -08:00
// issue-2185.rs:20 impl<A> iterable<A> for 'static ||A|| {
// issue-2185.rs:21 fn iter(&self, blk: |A|) { self(blk); }
2013-04-18 16:48:33 -07:00
// issue-2185.rs:22 }
2013-05-03 19:25:04 -04:00
//
2013-04-18 16:48:33 -07:00
// … so it looks like it's just not possible to implement both the generic iterable<uint> and iterable<A> for the type iterable<uint>. Is it okay if I just remove this test?
//
// but Niko responded:
// think it's fine to remove this test, just because it's old and cruft and not hard to reproduce. *However* it should eventually be possible to implement the same interface for the same type multiple times with different type parameters, it's just that our current trait implementation has accidental limitations.
// so I'm leaving it in.
2013-04-30 10:39:20 -07:00
// actually, it looks like this is related to bug #3429. I'll rename this bug.
2013-04-18 16:48:33 -07:00
2012-07-31 10:27:51 -07:00
// This test had to do with an outdated version of the iterable trait.
2012-04-11 21:45:18 -07:00
// However, the condition it was testing seemed complex enough to
// warrant still having a test, so I inlined the old definitions.
2012-07-31 10:27:51 -07:00
trait iterable < A > {
2013-11-19 16:34:19 -08:00
fn iter ( & self , blk : | A | ) ;
2012-04-11 21:45:18 -07:00
}
2013-11-19 16:34:19 -08:00
impl < A > iterable < A > for 'static | | A | | {
fn iter ( & self , blk : | A | ) { self ( blk ) ; }
2012-04-11 21:45:18 -07:00
}
2013-11-19 16:34:19 -08:00
impl iterable < uint > for 'static | | uint | | {
fn iter ( & self , blk : | v : uint | ) { self ( | i | blk ( i ) ) }
2012-04-11 21:45:18 -07:00
}
2013-11-19 16:34:19 -08:00
fn filter < A , IA :iterable < A > > ( self : IA , prd : 'static | A | -> bool , blk : | A | ) {
2012-06-30 16:19:07 -07:00
do self . iter | a | {
2012-04-11 21:45:18 -07:00
if prd ( a ) { blk ( a ) }
}
}
2013-11-19 16:34:19 -08:00
fn foldl < A , B , IA :iterable < A > > ( self : IA , b0 : B , blk : | B , A | -> B ) -> B {
2013-02-15 02:44:18 -08:00
let mut b = b0 ;
2012-06-30 16:19:07 -07:00
do self . iter | a | {
2013-02-15 02:44:18 -08:00
b = blk ( b , a ) ;
2012-04-11 21:45:18 -07:00
}
2013-02-15 02:44:18 -08:00
b
2012-04-11 21:45:18 -07:00
}
2012-04-23 09:25:14 +02:00
2013-11-19 16:34:19 -08:00
fn range ( lo : uint , hi : uint , it : | uint | ) {
2012-05-26 00:32:08 -07:00
let mut i = lo ;
while i < hi {
it ( i ) ;
i + = 1 u ;
}
}
2013-02-01 19:43:17 -08:00
pub fn main ( ) {
2013-11-19 16:34:19 -08:00
let range : 'static | | uint | | = | a | range ( 0 u , 1000 u , a ) ;
let filt : 'static | | v : uint | | = | a | filter (
2012-04-11 21:45:18 -07:00
range ,
2012-06-30 16:19:07 -07:00
| & & n : uint | n % 3 u ! = 0 u & & n % 5 u ! = 0 u ,
a ) ;
let sum = foldl ( filt , 0 u , | accum , & & n : uint | accum + n ) ;
2012-04-23 09:25:14 +02:00
2013-09-24 22:16:43 -07:00
println! ( " {} " , sum ) ;
2012-08-10 18:15:08 -07:00
}