rust/src/test/run-pass/issue-13204.rs
Aaron Turon 1bde6e3fcb Rename Iterator::len to count
This commit carries out the request from issue #14678:

> The method `Iterator::len()` is surprising, as all the other uses of
> `len()` do not consume the value. `len()` would make more sense to be
> called `count()`, but that would collide with the current
> `Iterator::count(|T| -> bool) -> unit` method. That method, however, is
> a bit redundant, and can be easily replaced with
> `iter.filter(|x| x < 5).count()`.
> After this change, we could then define the `len()` method
> on `iter::ExactSize`.

Closes #14678.

[breaking-change]
2014-06-06 19:51:31 -07:00

33 lines
1006 B
Rust

// Copyright 2012-2014 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.
// Test that when instantiating trait default methods, typeck handles
// lifetime parameters defined on the method bound correctly.
pub trait Foo {
fn bar<'a, I: Iterator<&'a ()>>(&self, it: I) -> uint {
let mut xs = it.filter(|_| true);
xs.count()
}
}
pub struct Baz;
impl Foo for Baz {
// When instantiating `Foo::bar` for `Baz` here, typeck used to
// ICE due to the lifetime parameter of `bar`.
}
fn main() {
let x = Baz;
let y = vec!((), (), ());
assert_eq!(x.bar(y.iter()), 3);
}