From 1bc29924dc8f88c2c118b688f25ffa7c6a212276 Mon Sep 17 00:00:00 2001
From: fort
Date: Thu, 5 Jun 2014 18:13:30 -0700
Subject: Remove reference to ~str in documentation
---
src/libstd/macros.rs | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
(limited to 'src/libstd')
diff --git a/src/libstd/macros.rs b/src/libstd/macros.rs
index 0b9fc250636..b555c966d2d 100644
--- a/src/libstd/macros.rs
+++ b/src/libstd/macros.rs
@@ -212,7 +212,7 @@ macro_rules! unimplemented(
() => (fail!("not yet implemented"))
)
-/// Use the syntax described in `std::fmt` to create a value of type `~str`.
+/// Use the syntax described in `std::fmt` to create a value of type `String`.
/// See `std::fmt` for more information.
///
/// # Example
--
cgit 1.4.1-3-g733a5
From 1bde6e3fcb32ca00cf8a8dfa0977e47f7f4a77bf Mon Sep 17 00:00:00 2001
From: Aaron Turon
Date: Thu, 5 Jun 2014 23:18:51 -0700
Subject: 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]
---
src/compiletest/runtest.rs | 2 +-
src/libcollections/bitv.rs | 8 +++---
src/libcollections/dlist.rs | 8 +++---
src/libcollections/slice.rs | 2 +-
src/libcollections/smallintmap.rs | 2 +-
src/libcollections/str.rs | 34 +++++++++++------------
src/libcollections/vec.rs | 14 +++++-----
src/libcore/iter.rs | 48 ++++++++++++++++-----------------
src/libcore/slice.rs | 3 +--
src/libcore/str.rs | 3 +--
src/librustc/metadata/encoder.rs | 2 +-
src/librustc/middle/entry.rs | 2 +-
src/librustc/middle/typeck/astconv.rs | 6 ++---
src/librustc/middle/typeck/check/mod.rs | 4 +--
src/librustc/util/ppaux.rs | 2 +-
src/librustdoc/html/render.rs | 2 +-
src/librustdoc/html/toc.rs | 2 +-
src/libstd/num/strconv.rs | 1 -
src/libstd/rand/mod.rs | 12 ++++-----
src/libstd/rt/backtrace.rs | 2 +-
src/test/run-pass/issue-13204.rs | 2 +-
21 files changed, 78 insertions(+), 83 deletions(-)
(limited to 'src/libstd')
diff --git a/src/compiletest/runtest.rs b/src/compiletest/runtest.rs
index 10428244b71..8da984a414b 100644
--- a/src/compiletest/runtest.rs
+++ b/src/compiletest/runtest.rs
@@ -1545,7 +1545,7 @@ fn disassemble_extract(config: &Config, _props: &TestProps,
fn count_extracted_lines(p: &Path) -> uint {
let x = File::open(&p.with_extension("ll")).read_to_end().unwrap();
let x = str::from_utf8(x.as_slice()).unwrap();
- x.lines().len()
+ x.lines().count()
}
diff --git a/src/libcollections/bitv.rs b/src/libcollections/bitv.rs
index 11c777034fe..58f081b25e3 100644
--- a/src/libcollections/bitv.rs
+++ b/src/libcollections/bitv.rs
@@ -241,17 +241,17 @@ enum Op {Union, Intersect, Assign, Difference}
/// bv.set(5, true);
/// bv.set(7, true);
/// println!("{}", bv.to_str());
-/// println!("total bits set to true: {}", bv.iter().count(|x| x));
+/// println!("total bits set to true: {}", bv.iter().filter(|x| *x).count());
///
/// // flip all values in bitvector, producing non-primes less than 10
/// bv.negate();
/// println!("{}", bv.to_str());
-/// println!("total bits set to true: {}", bv.iter().count(|x| x));
+/// println!("total bits set to true: {}", bv.iter().filter(|x| *x).count());
///
/// // reset bitvector to empty
/// bv.clear();
/// println!("{}", bv.to_str());
-/// println!("total bits set to true: {}", bv.iter().count(|x| x));
+/// println!("total bits set to true: {}", bv.iter().filter(|x| *x).count());
/// ```
#[deriving(Clone)]
pub struct Bitv {
@@ -461,7 +461,7 @@ impl Bitv {
/// bv.set(5, true);
/// bv.set(8, true);
/// // Count bits set to 1; result should be 5
- /// println!("{}", bv.iter().count(|x| x));
+ /// println!("{}", bv.iter().filter(|x| *x).count());
/// ```
#[inline]
pub fn iter<'a>(&'a self) -> Bits<'a> {
diff --git a/src/libcollections/dlist.rs b/src/libcollections/dlist.rs
index 8e3a49eecf3..94c617b58e8 100644
--- a/src/libcollections/dlist.rs
+++ b/src/libcollections/dlist.rs
@@ -1131,7 +1131,7 @@ mod tests {
let v = &[0, ..128];
let m: DList = v.iter().map(|&x|x).collect();
b.iter(|| {
- assert!(m.iter().len() == 128);
+ assert!(m.iter().count() == 128);
})
}
#[bench]
@@ -1139,7 +1139,7 @@ mod tests {
let v = &[0, ..128];
let mut m: DList = v.iter().map(|&x|x).collect();
b.iter(|| {
- assert!(m.mut_iter().len() == 128);
+ assert!(m.mut_iter().count() == 128);
})
}
#[bench]
@@ -1147,7 +1147,7 @@ mod tests {
let v = &[0, ..128];
let m: DList = v.iter().map(|&x|x).collect();
b.iter(|| {
- assert!(m.iter().rev().len() == 128);
+ assert!(m.iter().rev().count() == 128);
})
}
#[bench]
@@ -1155,7 +1155,7 @@ mod tests {
let v = &[0, ..128];
let mut m: DList = v.iter().map(|&x|x).collect();
b.iter(|| {
- assert!(m.mut_iter().rev().len() == 128);
+ assert!(m.mut_iter().rev().count() == 128);
})
}
}
diff --git a/src/libcollections/slice.rs b/src/libcollections/slice.rs
index 0b339a97262..e631b8b77cf 100644
--- a/src/libcollections/slice.rs
+++ b/src/libcollections/slice.rs
@@ -2155,7 +2155,7 @@ mod tests {
#[test]
fn test_mut_splitator() {
let mut xs = [0,1,0,2,3,0,0,4,5,0];
- assert_eq!(xs.mut_split(|x| *x == 0).len(), 6);
+ assert_eq!(xs.mut_split(|x| *x == 0).count(), 6);
for slice in xs.mut_split(|x| *x == 0) {
slice.reverse();
}
diff --git a/src/libcollections/smallintmap.rs b/src/libcollections/smallintmap.rs
index 829986e64ee..f3118181bdc 100644
--- a/src/libcollections/smallintmap.rs
+++ b/src/libcollections/smallintmap.rs
@@ -31,7 +31,7 @@ pub struct SmallIntMap {
impl Container for SmallIntMap {
/// Return the number of elements in the map
fn len(&self) -> uint {
- self.v.iter().count(|elt| elt.is_some())
+ self.v.iter().filter(|elt| elt.is_some()).count()
}
/// Return true if there are no elements in the map
diff --git a/src/libcollections/str.rs b/src/libcollections/str.rs
index ab1b1d1bd81..5fd133b450f 100644
--- a/src/libcollections/str.rs
+++ b/src/libcollections/str.rs
@@ -2181,7 +2181,7 @@ mod bench {
let s = "ศไทย中华Việt Nam; Mary had a little lamb, Little lamb";
let len = s.char_len();
- b.iter(|| assert_eq!(s.chars().len(), len));
+ b.iter(|| assert_eq!(s.chars().count(), len));
}
#[bench]
@@ -2194,7 +2194,7 @@ mod bench {
Mary had a little lamb, Little lamb";
let len = s.char_len();
- b.iter(|| assert_eq!(s.chars().len(), len));
+ b.iter(|| assert_eq!(s.chars().count(), len));
}
#[bench]
@@ -2202,7 +2202,7 @@ mod bench {
let s = "ศไทย中华Việt Nam; Mary had a little lamb, Little lamb";
let len = s.char_len();
- b.iter(|| assert_eq!(s.chars().rev().len(), len));
+ b.iter(|| assert_eq!(s.chars().rev().count(), len));
}
#[bench]
@@ -2210,7 +2210,7 @@ mod bench {
let s = "ศไทย中华Việt Nam; Mary had a little lamb, Little lamb";
let len = s.char_len();
- b.iter(|| assert_eq!(s.char_indices().len(), len));
+ b.iter(|| assert_eq!(s.char_indices().count(), len));
}
#[bench]
@@ -2218,14 +2218,14 @@ mod bench {
let s = "ศไทย中华Việt Nam; Mary had a little lamb, Little lamb";
let len = s.char_len();
- b.iter(|| assert_eq!(s.char_indices().rev().len(), len));
+ b.iter(|| assert_eq!(s.char_indices().rev().count(), len));
}
#[bench]
fn split_unicode_ascii(b: &mut Bencher) {
let s = "ประเทศไทย中华Việt Namประเทศไทย中华Việt Nam";
- b.iter(|| assert_eq!(s.split('V').len(), 3));
+ b.iter(|| assert_eq!(s.split('V').count(), 3));
}
#[bench]
@@ -2240,16 +2240,16 @@ mod bench {
}
let s = "ประเทศไทย中华Việt Namประเทศไทย中华Việt Nam";
- b.iter(|| assert_eq!(s.split(NotAscii('V')).len(), 3));
+ b.iter(|| assert_eq!(s.split(NotAscii('V')).count(), 3));
}
#[bench]
fn split_ascii(b: &mut Bencher) {
let s = "Mary had a little lamb, Little lamb, little-lamb.";
- let len = s.split(' ').len();
+ let len = s.split(' ').count();
- b.iter(|| assert_eq!(s.split(' ').len(), len));
+ b.iter(|| assert_eq!(s.split(' ').count(), len));
}
#[bench]
@@ -2264,34 +2264,34 @@ mod bench {
fn only_ascii(&self) -> bool { false }
}
let s = "Mary had a little lamb, Little lamb, little-lamb.";
- let len = s.split(' ').len();
+ let len = s.split(' ').count();
- b.iter(|| assert_eq!(s.split(NotAscii(' ')).len(), len));
+ b.iter(|| assert_eq!(s.split(NotAscii(' ')).count(), len));
}
#[bench]
fn split_extern_fn(b: &mut Bencher) {
let s = "Mary had a little lamb, Little lamb, little-lamb.";
- let len = s.split(' ').len();
+ let len = s.split(' ').count();
fn pred(c: char) -> bool { c == ' ' }
- b.iter(|| assert_eq!(s.split(pred).len(), len));
+ b.iter(|| assert_eq!(s.split(pred).count(), len));
}
#[bench]
fn split_closure(b: &mut Bencher) {
let s = "Mary had a little lamb, Little lamb, little-lamb.";
- let len = s.split(' ').len();
+ let len = s.split(' ').count();
- b.iter(|| assert_eq!(s.split(|c: char| c == ' ').len(), len));
+ b.iter(|| assert_eq!(s.split(|c: char| c == ' ').count(), len));
}
#[bench]
fn split_slice(b: &mut Bencher) {
let s = "Mary had a little lamb, Little lamb, little-lamb.";
- let len = s.split(' ').len();
+ let len = s.split(' ').count();
- b.iter(|| assert_eq!(s.split(&[' ']).len(), len));
+ b.iter(|| assert_eq!(s.split(&[' ']).count(), len));
}
#[bench]
diff --git a/src/libcollections/vec.rs b/src/libcollections/vec.rs
index aa80a131811..6ca21262f51 100644
--- a/src/libcollections/vec.rs
+++ b/src/libcollections/vec.rs
@@ -1772,23 +1772,23 @@ mod tests {
assert_eq!(v.pop(), Some(()));
assert_eq!(v.pop(), None);
- assert_eq!(v.iter().len(), 0);
+ assert_eq!(v.iter().count(), 0);
v.push(());
- assert_eq!(v.iter().len(), 1);
+ assert_eq!(v.iter().count(), 1);
v.push(());
- assert_eq!(v.iter().len(), 2);
+ assert_eq!(v.iter().count(), 2);
for &() in v.iter() {}
- assert_eq!(v.mut_iter().len(), 2);
+ assert_eq!(v.mut_iter().count(), 2);
v.push(());
- assert_eq!(v.mut_iter().len(), 3);
+ assert_eq!(v.mut_iter().count(), 3);
v.push(());
- assert_eq!(v.mut_iter().len(), 4);
+ assert_eq!(v.mut_iter().count(), 4);
for &() in v.mut_iter() {}
unsafe { v.set_len(0); }
- assert_eq!(v.mut_iter().len(), 0);
+ assert_eq!(v.mut_iter().count(), 0);
}
#[test]
diff --git a/src/libcore/iter.rs b/src/libcore/iter.rs
index 875c852d8ae..64c53b658ef 100644
--- a/src/libcore/iter.rs
+++ b/src/libcore/iter.rs
@@ -529,11 +529,11 @@ pub trait Iterator {
/// ```rust
/// let a = [1, 2, 3, 4, 5];
/// let mut it = a.iter();
- /// assert!(it.len() == 5);
- /// assert!(it.len() == 0);
+ /// assert!(it.count() == 5);
+ /// assert!(it.count() == 0);
/// ```
#[inline]
- fn len(&mut self) -> uint {
+ fn count(&mut self) -> uint {
self.fold(0, |cnt, _x| cnt + 1)
}
@@ -591,16 +591,6 @@ pub trait Iterator {
None
}
- /// Count the number of elements satisfying the specified predicate
- #[inline]
- fn count(&mut self, predicate: |A| -> bool) -> uint {
- let mut i = 0;
- for x in *self {
- if predicate(x) { i += 1 }
- }
- i
- }
-
/// Return the element that gives the maximum value from the
/// specified function.
///
@@ -738,6 +728,14 @@ pub trait ExactSize : DoubleEndedIterator {
}
None
}
+
+ #[inline]
+ /// Return the exact length of the iterator.
+ fn len(&self) -> uint {
+ let (lower, upper) = self.size_hint();
+ assert!(upper == Some(lower));
+ lower
+ }
}
// All adaptors that preserve the size of the wrapped iterator are fine
@@ -2594,9 +2592,9 @@ mod tests {
#[test]
fn test_iterator_len() {
let v = &[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
- assert_eq!(v.slice(0, 4).iter().len(), 4);
- assert_eq!(v.slice(0, 10).iter().len(), 10);
- assert_eq!(v.slice(0, 0).iter().len(), 0);
+ assert_eq!(v.slice(0, 4).iter().count(), 4);
+ assert_eq!(v.slice(0, 10).iter().count(), 10);
+ assert_eq!(v.slice(0, 0).iter().count(), 0);
}
#[test]
@@ -2712,9 +2710,9 @@ mod tests {
#[test]
fn test_count() {
let xs = &[1, 2, 2, 1, 5, 9, 0, 2];
- assert_eq!(xs.iter().count(|x| *x == 2), 3);
- assert_eq!(xs.iter().count(|x| *x == 5), 1);
- assert_eq!(xs.iter().count(|x| *x == 95), 0);
+ assert_eq!(xs.iter().filter(|x| **x == 2).count(), 3);
+ assert_eq!(xs.iter().filter(|x| **x == 5).count(), 1);
+ assert_eq!(xs.iter().filter(|x| **x == 95).count(), 0);
}
#[test]
@@ -3044,10 +3042,10 @@ mod tests {
assert!(range(-10i, -1).collect::>() ==
vec![-10, -9, -8, -7, -6, -5, -4, -3, -2]);
assert!(range(0i, 5).rev().collect::>() == vec![4, 3, 2, 1, 0]);
- assert_eq!(range(200, -5).len(), 0);
- assert_eq!(range(200, -5).rev().len(), 0);
- assert_eq!(range(200, 200).len(), 0);
- assert_eq!(range(200, 200).rev().len(), 0);
+ assert_eq!(range(200, -5).count(), 0);
+ assert_eq!(range(200, -5).rev().count(), 0);
+ assert_eq!(range(200, 200).count(), 0);
+ assert_eq!(range(200, 200).rev().count(), 0);
assert_eq!(range(0i, 100).size_hint(), (100, Some(100)));
// this test is only meaningful when sizeof uint < sizeof u64
@@ -3062,8 +3060,8 @@ mod tests {
vec![0i, 1, 2, 3, 4, 5]);
assert!(range_inclusive(0i, 5).rev().collect::>() ==
vec![5i, 4, 3, 2, 1, 0]);
- assert_eq!(range_inclusive(200, -5).len(), 0);
- assert_eq!(range_inclusive(200, -5).rev().len(), 0);
+ assert_eq!(range_inclusive(200, -5).count(), 0);
+ assert_eq!(range_inclusive(200, -5).rev().count(), 0);
assert!(range_inclusive(200, 200).collect::>() == vec![200]);
assert!(range_inclusive(200, 200).rev().collect::>() == vec![200]);
}
diff --git a/src/libcore/slice.rs b/src/libcore/slice.rs
index 0257911e8c0..4dea1fd75a4 100644
--- a/src/libcore/slice.rs
+++ b/src/libcore/slice.rs
@@ -252,7 +252,7 @@ pub mod traits {
use super::*;
use cmp::{PartialEq, PartialOrd, Eq, Ord, Ordering, Equiv};
- use iter::{order, Iterator};
+ use iter::order;
use container::Container;
impl<'a,T:PartialEq> PartialEq for &'a [T] {
@@ -1141,7 +1141,6 @@ impl<'a, T:Clone> MutableCloneableVector for &'a mut [T] {
/// Unsafe operations
pub mod raw {
use mem::transmute;
- use iter::Iterator;
use ptr::RawPtr;
use raw::Slice;
use option::{None, Option, Some};
diff --git a/src/libcore/str.rs b/src/libcore/str.rs
index c08f30152d5..936b698d4b1 100644
--- a/src/libcore/str.rs
+++ b/src/libcore/str.rs
@@ -867,7 +867,6 @@ static TAG_CONT_U8: u8 = 128u8;
pub mod raw {
use mem;
use container::Container;
- use iter::Iterator;
use ptr::RawPtr;
use raw::Slice;
use slice::{ImmutableVector};
@@ -1725,7 +1724,7 @@ impl<'a> StrSlice<'a> for &'a str {
fn is_alphanumeric(&self) -> bool { self.chars().all(char::is_alphanumeric) }
#[inline]
- fn char_len(&self) -> uint { self.chars().len() }
+ fn char_len(&self) -> uint { self.chars().count() }
#[inline]
fn slice(&self, begin: uint, end: uint) -> &'a str {
diff --git a/src/librustc/metadata/encoder.rs b/src/librustc/metadata/encoder.rs
index e2d0a858d42..cd2f3360f83 100644
--- a/src/librustc/metadata/encoder.rs
+++ b/src/librustc/metadata/encoder.rs
@@ -351,7 +351,7 @@ fn encode_enum_variant_info(ecx: &EncodeContext,
fn encode_path + Clone>(ebml_w: &mut Encoder,
mut path: PI) {
ebml_w.start_tag(tag_path);
- ebml_w.wr_tagged_u32(tag_path_len, path.clone().len() as u32);
+ ebml_w.wr_tagged_u32(tag_path_len, path.clone().count() as u32);
for pe in path {
let tag = match pe {
ast_map::PathMod(_) => tag_path_elem_mod,
diff --git a/src/librustc/middle/entry.rs b/src/librustc/middle/entry.rs
index 1b7ed90237f..9a5f226bb73 100644
--- a/src/librustc/middle/entry.rs
+++ b/src/librustc/middle/entry.rs
@@ -82,7 +82,7 @@ fn find_item(item: &Item, ctxt: &mut EntryContext) {
ItemFn(..) => {
if item.ident.name == ctxt.main_name {
ctxt.ast_map.with_path(item.id, |mut path| {
- if path.len() == 1 {
+ if path.count() == 1 {
// This is a top-level function so can be 'main'
if ctxt.main_fn.is_none() {
ctxt.main_fn = Some((item.id, item.span));
diff --git a/src/librustc/middle/typeck/astconv.rs b/src/librustc/middle/typeck/astconv.rs
index f8821a86e71..bdb23aea067 100644
--- a/src/librustc/middle/typeck/astconv.rs
+++ b/src/librustc/middle/typeck/astconv.rs
@@ -191,11 +191,11 @@ fn ast_path_substs(
};
// Convert the type parameters supplied by the user.
- let supplied_ty_param_count = path.segments.iter().flat_map(|s| s.types.iter()).len();
+ let supplied_ty_param_count = path.segments.iter().flat_map(|s| s.types.iter()).count();
let formal_ty_param_count = decl_generics.type_param_defs().len();
let required_ty_param_count = decl_generics.type_param_defs().iter()
.take_while(|x| x.default.is_none())
- .len();
+ .count();
if supplied_ty_param_count < required_ty_param_count {
let expected = if required_ty_param_count < formal_ty_param_count {
"expected at least"
@@ -407,7 +407,7 @@ pub fn ast_ty_to_builtin_ty 1 {
+ .count() > 1 {
this.tcx()
.sess
.span_err(path.span,
diff --git a/src/librustc/middle/typeck/check/mod.rs b/src/librustc/middle/typeck/check/mod.rs
index a09c92d4db0..d25fc9cc5bc 100644
--- a/src/librustc/middle/typeck/check/mod.rs
+++ b/src/librustc/middle/typeck/check/mod.rs
@@ -1615,7 +1615,7 @@ fn check_type_parameter_positions_in_path(function_context: &FnCtxt,
let formal_ty_param_count = generics.type_param_defs().len();
let required_ty_param_count = generics.type_param_defs().iter()
.take_while(|x| x.default.is_none())
- .len();
+ .count();
let supplied_ty_param_count = trait_segment.types.len();
if supplied_ty_param_count < required_ty_param_count {
let msg = if required_ty_param_count < generics.type_param_defs().len() {
@@ -3876,7 +3876,7 @@ pub fn instantiate_path(fcx: &FnCtxt,
let ty_param_count = tpt.generics.type_param_defs().len();
let ty_param_req = tpt.generics.type_param_defs().iter()
.take_while(|x| x.default.is_none())
- .len();
+ .count();
let mut ty_substs_len = 0;
for segment in pth.segments.iter() {
ty_substs_len += segment.types.len()
diff --git a/src/librustc/util/ppaux.rs b/src/librustc/util/ppaux.rs
index a9ac1e76f11..eb84ed32335 100644
--- a/src/librustc/util/ppaux.rs
+++ b/src/librustc/util/ppaux.rs
@@ -456,7 +456,7 @@ pub fn parameterized(cx: &ctxt,
Some(default) => default.subst(cx, &substs) == actual,
None => false
}
- }).len()
+ }).count()
} else {
0
};
diff --git a/src/librustdoc/html/render.rs b/src/librustdoc/html/render.rs
index 086232104e3..20d4d677bc0 100644
--- a/src/librustdoc/html/render.rs
+++ b/src/librustdoc/html/render.rs
@@ -2043,7 +2043,7 @@ fn build_sidebar(m: &clean::Module) -> HashMap> {
impl<'a> fmt::Show for Source<'a> {
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
let Source(s) = *self;
- let lines = s.lines().len();
+ let lines = s.lines().count();
let mut cols = 0;
let mut tmp = lines;
while tmp > 0 {
diff --git a/src/librustdoc/html/toc.rs b/src/librustdoc/html/toc.rs
index 2356d4c754f..5bc6d8031ac 100644
--- a/src/librustdoc/html/toc.rs
+++ b/src/librustdoc/html/toc.rs
@@ -32,7 +32,7 @@ pub struct Toc {
impl Toc {
fn count_entries_with_level(&self, level: u32) -> uint {
- self.entries.iter().count(|e| e.level == level)
+ self.entries.iter().filter(|e| e.level == level).count()
}
}
diff --git a/src/libstd/num/strconv.rs b/src/libstd/num/strconv.rs
index 54ca5797804..133a8db90fa 100644
--- a/src/libstd/num/strconv.rs
+++ b/src/libstd/num/strconv.rs
@@ -13,7 +13,6 @@
use char;
use clone::Clone;
use container::Container;
-use iter::Iterator;
use num::{NumCast, Zero, One, cast, Int};
use num::{Float, FPNaN, FPInfinite, ToPrimitive};
use num;
diff --git a/src/libstd/rand/mod.rs b/src/libstd/rand/mod.rs
index 61a2ffd383d..ee193562887 100644
--- a/src/libstd/rand/mod.rs
+++ b/src/libstd/rand/mod.rs
@@ -353,17 +353,17 @@ mod test {
#[test]
fn test_gen_ascii_str() {
let mut r = task_rng();
- assert_eq!(r.gen_ascii_chars().take(0).len(), 0u);
- assert_eq!(r.gen_ascii_chars().take(10).len(), 10u);
- assert_eq!(r.gen_ascii_chars().take(16).len(), 16u);
+ assert_eq!(r.gen_ascii_chars().take(0).count(), 0u);
+ assert_eq!(r.gen_ascii_chars().take(10).count(), 10u);
+ assert_eq!(r.gen_ascii_chars().take(16).count(), 16u);
}
#[test]
fn test_gen_vec() {
let mut r = task_rng();
- assert_eq!(r.gen_iter::().take(0).len(), 0u);
- assert_eq!(r.gen_iter::().take(10).len(), 10u);
- assert_eq!(r.gen_iter::().take(16).len(), 16u);
+ assert_eq!(r.gen_iter::().take(0).count(), 0u);
+ assert_eq!(r.gen_iter::().take(10).count(), 10u);
+ assert_eq!(r.gen_iter::().take(16).count(), 16u);
}
#[test]
diff --git a/src/libstd/rt/backtrace.rs b/src/libstd/rt/backtrace.rs
index ac421bf78be..fe6d84d4d2e 100644
--- a/src/libstd/rt/backtrace.rs
+++ b/src/libstd/rt/backtrace.rs
@@ -84,7 +84,7 @@ fn demangle(writer: &mut Writer, s: &str) -> IoResult<()> {
if i == 0 {
valid = chars.next().is_none();
break
- } else if chars.by_ref().take(i - 1).len() != i - 1 {
+ } else if chars.by_ref().take(i - 1).count() != i - 1 {
valid = false;
}
}
diff --git a/src/test/run-pass/issue-13204.rs b/src/test/run-pass/issue-13204.rs
index 5fb9119849c..f9b542dea56 100644
--- a/src/test/run-pass/issue-13204.rs
+++ b/src/test/run-pass/issue-13204.rs
@@ -14,7 +14,7 @@
pub trait Foo {
fn bar<'a, I: Iterator<&'a ()>>(&self, it: I) -> uint {
let mut xs = it.filter(|_| true);
- xs.len()
+ xs.count()
}
}
--
cgit 1.4.1-3-g733a5
From b662aa5ec0eb1971111bf10f9c3ef2a8f226bb0a Mon Sep 17 00:00:00 2001
From: Steven Fackler
Date: Thu, 5 Jun 2014 23:22:01 -0700
Subject: Implement Eq for HashSet and HashMap
Also fix documentation references to PartialEq.
---
src/libstd/collections/hashmap.rs | 10 +++++++---
1 file changed, 7 insertions(+), 3 deletions(-)
(limited to 'src/libstd')
diff --git a/src/libstd/collections/hashmap.rs b/src/libstd/collections/hashmap.rs
index 5dba7a533a1..571c5794704 100644
--- a/src/libstd/collections/hashmap.rs
+++ b/src/libstd/collections/hashmap.rs
@@ -684,8 +684,8 @@ impl DefaultResizePolicy {
/// denial-of-service attacks (Hash DoS). This behaviour can be
/// overridden with one of the constructors.
///
-/// It is required that the keys implement the `PartialEq` and `Hash` traits, although
-/// this can frequently be achieved by using `#[deriving(PartialEq, Hash)]`.
+/// It is required that the keys implement the `Eq` and `Hash` traits, although
+/// this can frequently be achieved by using `#[deriving(Eq, Hash)]`.
///
/// Relevant papers/articles:
///
@@ -1422,6 +1422,8 @@ impl, V: PartialEq, S, H: Hasher> PartialEq for HashMap, V: Eq, S, H: Hasher> Eq for HashMap {}
+
impl + Show, V: Show, S, H: Hasher> Show for HashMap {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
try!(write!(f, r"\{"));
@@ -1486,7 +1488,7 @@ pub type SetMoveItems =
/// An implementation of a hash set using the underlying representation of a
/// HashMap where the value is (). As with the `HashMap` type, a `HashSet`
-/// requires that the elements implement the `PartialEq` and `Hash` traits.
+/// requires that the elements implement the `Eq` and `Hash` traits.
#[deriving(Clone)]
pub struct HashSet {
map: HashMap
@@ -1500,6 +1502,8 @@ impl, S, H: Hasher> PartialEq for HashSet {
}
}
+impl, S, H: Hasher> Eq for HashSet {}
+
impl, S, H: Hasher> Container for HashSet {
fn len(&self) -> uint { self.map.len() }
}
--
cgit 1.4.1-3-g733a5
From cb12e7ab743e4a0118a3de53a437a70cf332e5b1 Mon Sep 17 00:00:00 2001
From: Alex Crichton
Date: Fri, 6 Jun 2014 09:22:19 -0700
Subject: mk: Run doc tests with --cfg dox
There were a few examples in the macros::builtin module that weren't being run
because they were being #[cfg]'d out.
Closes #14697
---
mk/tests.mk | 2 +-
src/libstd/macros.rs | 6 +++++-
2 files changed, 6 insertions(+), 2 deletions(-)
(limited to 'src/libstd')
diff --git a/mk/tests.mk b/mk/tests.mk
index c67fa0042f8..dacea3a4bfc 100644
--- a/mk/tests.mk
+++ b/mk/tests.mk
@@ -818,7 +818,7 @@ endif
ifeq ($(2),$$(CFG_BUILD))
$$(call TEST_OK_FILE,$(1),$(2),$(3),doc-crate-$(4)): $$(CRATEDOCTESTDEP_$(1)_$(2)_$(3)_$(4))
@$$(call E, run doc-crate-$(4) [$(2)])
- $$(Q)$$(RUSTDOC_$(1)_T_$(2)_H_$(3)) --test \
+ $$(Q)$$(RUSTDOC_$(1)_T_$(2)_H_$(3)) --test --cfg dox \
$$(CRATEFILE_$(4)) --test-args "$$(TESTARGS)" && touch $$@
else
$$(call TEST_OK_FILE,$(1),$(2),$(3),doc-crate-$(4)):
diff --git a/src/libstd/macros.rs b/src/libstd/macros.rs
index b555c966d2d..805da8021ed 100644
--- a/src/libstd/macros.rs
+++ b/src/libstd/macros.rs
@@ -465,7 +465,7 @@ pub mod builtin {
/// ```
/// let rust = bytes!("r", 'u', "st", 255);
/// assert_eq!(rust[1], 'u' as u8);
- /// assert_eq!(rust[5], 255);
+ /// assert_eq!(rust[4], 255);
/// ```
#[macro_export]
macro_rules! bytes( ($($e:expr),*) => ({ /* compiler built-in */ }) )
@@ -482,10 +482,14 @@ pub mod builtin {
/// # Example
///
/// ```
+ /// #![feature(concat_idents)]
+ ///
+ /// # fn main() {
/// fn foobar() -> int { 23 }
///
/// let f = concat_idents!(foo, bar);
/// println!("{}", f());
+ /// # }
/// ```
#[macro_export]
macro_rules! concat_idents( ($($e:ident),*) => ({ /* compiler built-in */ }) )
--
cgit 1.4.1-3-g733a5
From 59157631061744947df9a7751ac55fe2304e67ad Mon Sep 17 00:00:00 2001
From: Axel Viala
Date: Sat, 7 Jun 2014 00:43:45 +0200
Subject: Removing unused wrapper to libc::close.
---
src/libstd/os.rs | 6 ------
1 file changed, 6 deletions(-)
(limited to 'src/libstd')
diff --git a/src/libstd/os.rs b/src/libstd/os.rs
index 1f75754f4d5..381ebc08200 100644
--- a/src/libstd/os.rs
+++ b/src/libstd/os.rs
@@ -56,12 +56,6 @@ use libc::c_char;
#[cfg(windows)]
use str::OwnedStr;
-/// Delegates to the libc close() function, returning the same return value.
-pub fn close(fd: int) -> int {
- unsafe {
- libc::close(fd as c_int) as int
- }
-}
pub static TMPBUF_SZ : uint = 1000u;
static BUF_BYTES : uint = 2048u;
--
cgit 1.4.1-3-g733a5
From e5bbbca33e11d9e22dbbe32c975f908710d4155c Mon Sep 17 00:00:00 2001
From: Alex Crichton
Date: Fri, 6 Jun 2014 09:12:18 -0700
Subject: rustdoc: Submit examples to play.rust-lang.org
This grows a new option inside of rustdoc to add the ability to submit examples
to an external website. If the `--markdown-playground-url` command line option
or crate doc attribute `html_playground_url` is present, then examples will have
a button on hover to submit the code to the playground specified.
This commit enables submission of example code to play.rust-lang.org. The code
submitted is that which is tested by rustdoc, not necessarily the exact code
shown in the example.
Closes #14654
---
mk/docs.mk | 4 +++-
src/doc/footer.inc | 2 ++
src/doc/rust.css | 13 +++++++++++++
src/libcollections/lib.rs | 3 ++-
src/libcore/lib.rs | 3 ++-
src/libgetopts/lib.rs | 3 ++-
src/libglob/lib.rs | 4 ++--
src/libgreen/lib.rs | 3 ++-
src/liblog/lib.rs | 3 ++-
src/libnum/lib.rs | 3 ++-
src/librand/lib.rs | 3 ++-
src/libregex/lib.rs | 3 ++-
src/librustdoc/html/highlight.rs | 13 ++++++++++---
src/librustdoc/html/layout.rs | 13 +++++++++++--
src/librustdoc/html/markdown.rs | 35 +++++++++++++++++++++++++++++------
src/librustdoc/html/render.rs | 15 +++++++++++++--
src/librustdoc/html/static/main.css | 13 ++++++++++++-
src/librustdoc/html/static/main.js | 2 +-
src/librustdoc/html/static/playpen.js | 29 +++++++++++++++++++++++++++++
src/librustdoc/lib.rs | 4 +++-
src/librustdoc/markdown.rs | 13 ++++++++++++-
src/librustdoc/test.rs | 24 ++++++++++++++++--------
src/libserialize/lib.rs | 3 ++-
src/libstd/lib.rs | 3 ++-
src/libsync/lib.rs | 3 ++-
src/libterm/lib.rs | 3 ++-
src/libtime/lib.rs | 3 ++-
src/liburl/lib.rs | 3 ++-
src/libuuid/lib.rs | 3 ++-
29 files changed, 186 insertions(+), 43 deletions(-)
create mode 100644 src/librustdoc/html/static/playpen.js
(limited to 'src/libstd')
diff --git a/mk/docs.mk b/mk/docs.mk
index 90f85079464..dab40cb1654 100644
--- a/mk/docs.mk
+++ b/mk/docs.mk
@@ -43,7 +43,9 @@ L10N_LANGS := ja
# The options are passed to the documentation generators.
RUSTDOC_HTML_OPTS_NO_CSS = --markdown-before-content=doc/version_info.html \
- --markdown-in-header=doc/favicon.inc --markdown-after-content=doc/footer.inc
+ --markdown-in-header=doc/favicon.inc \
+ --markdown-after-content=doc/footer.inc \
+ --markdown-playground-url='http://play.rust-lang.org/'
RUSTDOC_HTML_OPTS = $(RUSTDOC_HTML_OPTS_NO_CSS) --markdown-css rust.css
diff --git a/src/doc/footer.inc b/src/doc/footer.inc
index a103a4908f6..4e7d60586f2 100644
--- a/src/doc/footer.inc
+++ b/src/doc/footer.inc
@@ -5,3 +5,5 @@ or the MIT license, at your opt
This file may not be copied, modified, or distributed except according to those terms.
+
+
diff --git a/src/doc/rust.css b/src/doc/rust.css
index d60dd54a67d..3957231a195 100644
--- a/src/doc/rust.css
+++ b/src/doc/rust.css
@@ -313,6 +313,19 @@ table th {
padding: 5px;
}
+/* Code snippets */
+
+.rusttest { display: none; }
+pre.rust { position: relative; }
+pre.rust a { transform: scaleX(-1); }
+.test-arrow {
+ display: inline-block;
+ position: absolute;
+ top: 0;
+ right: 10px;
+ font-size: 150%;
+}
+
@media (min-width: 1170px) {
pre {
font-size: 15px;
diff --git a/src/libcollections/lib.rs b/src/libcollections/lib.rs
index 2004285ecb9..a65c06107ce 100644
--- a/src/libcollections/lib.rs
+++ b/src/libcollections/lib.rs
@@ -17,7 +17,8 @@
#![license = "MIT/ASL2"]
#![doc(html_logo_url = "http://www.rust-lang.org/logos/rust-logo-128x128-blk-v2.png",
html_favicon_url = "http://www.rust-lang.org/favicon.ico",
- html_root_url = "http://doc.rust-lang.org/")]
+ html_root_url = "http://doc.rust-lang.org/",
+ html_playground_url = "http://play.rust-lang.org/")]
#![feature(macro_rules, managed_boxes, default_type_params, phase, globs)]
#![no_std]
diff --git a/src/libcore/lib.rs b/src/libcore/lib.rs
index 6aa07415e9c..2ccf431fc22 100644
--- a/src/libcore/lib.rs
+++ b/src/libcore/lib.rs
@@ -50,7 +50,8 @@
#![crate_type = "rlib"]
#![doc(html_logo_url = "http://www.rust-lang.org/logos/rust-logo-128x128-blk-v2.png",
html_favicon_url = "http://www.rust-lang.org/favicon.ico",
- html_root_url = "http://doc.rust-lang.org/")]
+ html_root_url = "http://doc.rust-lang.org/",
+ html_playground_url = "http://play.rust-lang.org/")]
#![no_std]
#![feature(globs, macro_rules, managed_boxes, phase, simd)]
diff --git a/src/libgetopts/lib.rs b/src/libgetopts/lib.rs
index ddfe8380e09..10584223486 100644
--- a/src/libgetopts/lib.rs
+++ b/src/libgetopts/lib.rs
@@ -84,7 +84,8 @@
#![license = "MIT/ASL2"]
#![doc(html_logo_url = "http://www.rust-lang.org/logos/rust-logo-128x128-blk-v2.png",
html_favicon_url = "http://www.rust-lang.org/favicon.ico",
- html_root_url = "http://doc.rust-lang.org/")]
+ html_root_url = "http://doc.rust-lang.org/",
+ html_playground_url = "http://play.rust-lang.org/")]
#![feature(globs, phase)]
#![deny(missing_doc)]
#![deny(deprecated_owned_vector)]
diff --git a/src/libglob/lib.rs b/src/libglob/lib.rs
index 86753fbb811..f3e1da77ce5 100644
--- a/src/libglob/lib.rs
+++ b/src/libglob/lib.rs
@@ -29,8 +29,8 @@
#![license = "MIT/ASL2"]
#![doc(html_logo_url = "http://www.rust-lang.org/logos/rust-logo-128x128-blk-v2.png",
html_favicon_url = "http://www.rust-lang.org/favicon.ico",
- html_root_url = "http://doc.rust-lang.org/")]
-
+ html_root_url = "http://doc.rust-lang.org/",
+ html_playground_url = "http://play.rust-lang.org/")]
#![deny(deprecated_owned_vector)]
use std::cell::Cell;
diff --git a/src/libgreen/lib.rs b/src/libgreen/lib.rs
index 31fd8950c80..c75d69480ce 100644
--- a/src/libgreen/lib.rs
+++ b/src/libgreen/lib.rs
@@ -203,7 +203,8 @@
#![crate_type = "dylib"]
#![doc(html_logo_url = "http://www.rust-lang.org/logos/rust-logo-128x128-blk-v2.png",
html_favicon_url = "http://www.rust-lang.org/favicon.ico",
- html_root_url = "http://doc.rust-lang.org/")]
+ html_root_url = "http://doc.rust-lang.org/",
+ html_playground_url = "http://play.rust-lang.org/")]
// NB this does *not* include globs, please keep it that way.
#![feature(macro_rules, phase)]
diff --git a/src/liblog/lib.rs b/src/liblog/lib.rs
index ff580559969..daacf8b3c47 100644
--- a/src/liblog/lib.rs
+++ b/src/liblog/lib.rs
@@ -111,7 +111,8 @@ if logging is disabled, none of the components of the log will be executed.
#![crate_type = "dylib"]
#![doc(html_logo_url = "http://www.rust-lang.org/logos/rust-logo-128x128-blk-v2.png",
html_favicon_url = "http://www.rust-lang.org/favicon.ico",
- html_root_url = "http://doc.rust-lang.org/")]
+ html_root_url = "http://doc.rust-lang.org/",
+ html_playground_url = "http://play.rust-lang.org/")]
#![feature(macro_rules)]
#![deny(missing_doc, deprecated_owned_vector)]
diff --git a/src/libnum/lib.rs b/src/libnum/lib.rs
index 29cf769ffc9..fae21e80f30 100644
--- a/src/libnum/lib.rs
+++ b/src/libnum/lib.rs
@@ -50,7 +50,8 @@
#![license = "MIT/ASL2"]
#![doc(html_logo_url = "http://www.rust-lang.org/logos/rust-logo-128x128-blk-v2.png",
html_favicon_url = "http://www.rust-lang.org/favicon.ico",
- html_root_url = "http://doc.rust-lang.org/")]
+ html_root_url = "http://doc.rust-lang.org/",
+ html_playground_url = "http://play.rust-lang.org/")]
#![deny(deprecated_owned_vector)]
diff --git a/src/librand/lib.rs b/src/librand/lib.rs
index 3ed086e9b13..7a12dcf9f7f 100644
--- a/src/librand/lib.rs
+++ b/src/librand/lib.rs
@@ -21,7 +21,8 @@
#![crate_type = "rlib"]
#![doc(html_logo_url = "http://www.rust-lang.org/logos/rust-logo-128x128-blk.png",
html_favicon_url = "http://www.rust-lang.org/favicon.ico",
- html_root_url = "http://doc.rust-lang.org/")]
+ html_root_url = "http://doc.rust-lang.org/",
+ html_playground_url = "http://play.rust-lang.org/")]
#![feature(macro_rules, phase, globs)]
#![no_std]
diff --git a/src/libregex/lib.rs b/src/libregex/lib.rs
index a48760913c1..44c206162ab 100644
--- a/src/libregex/lib.rs
+++ b/src/libregex/lib.rs
@@ -360,7 +360,8 @@
#![license = "MIT/ASL2"]
#![doc(html_logo_url = "http://www.rust-lang.org/logos/rust-logo-128x128-blk-v2.png",
html_favicon_url = "http://www.rust-lang.org/favicon.ico",
- html_root_url = "http://doc.rust-lang.org/")]
+ html_root_url = "http://doc.rust-lang.org/",
+ html_playground_url = "http://play.rust-lang.org/")]
#![feature(macro_rules, phase)]
#![deny(missing_doc, deprecated_owned_vector)]
diff --git a/src/librustdoc/html/highlight.rs b/src/librustdoc/html/highlight.rs
index f544e1e0973..3c9358b03a9 100644
--- a/src/librustdoc/html/highlight.rs
+++ b/src/librustdoc/html/highlight.rs
@@ -25,7 +25,7 @@ use html::escape::Escape;
use t = syntax::parse::token;
/// Highlights some source code, returning the HTML output.
-pub fn highlight(src: &str, class: Option<&str>) -> String {
+pub fn highlight(src: &str, class: Option<&str>, id: Option<&str>) -> String {
debug!("highlighting: ================\n{}\n==============", src);
let sess = parse::new_parse_sess();
let fm = parse::string_to_filemap(&sess,
@@ -36,6 +36,7 @@ pub fn highlight(src: &str, class: Option<&str>) -> String {
doit(&sess,
lexer::StringReader::new(&sess.span_diagnostic, fm),
class,
+ id,
&mut out).unwrap();
str::from_utf8_lossy(out.unwrap().as_slice()).to_string()
}
@@ -47,11 +48,17 @@ pub fn highlight(src: &str, class: Option<&str>) -> String {
/// it's used. All source code emission is done as slices from the source map,
/// not from the tokens themselves, in order to stay true to the original
/// source.
-fn doit(sess: &parse::ParseSess, mut lexer: lexer::StringReader, class: Option<&str>,
+fn doit(sess: &parse::ParseSess, mut lexer: lexer::StringReader,
+ class: Option<&str>, id: Option<&str>,
out: &mut Writer) -> io::IoResult<()> {
use syntax::parse::lexer::Reader;
- try!(write!(out, "\n", class.unwrap_or("")));
+ try!(write!(out, " try!(write!(out, "id='{}' ", id)),
+ None => {}
+ }
+ try!(write!(out, "class='rust {}'>\n", class.unwrap_or("")));
let mut last = BytePos(0);
let mut is_attribute = false;
let mut is_macro = false;
diff --git a/src/librustdoc/html/layout.rs b/src/librustdoc/html/layout.rs
index 80653878247..e2fa57148c2 100644
--- a/src/librustdoc/html/layout.rs
+++ b/src/librustdoc/html/layout.rs
@@ -16,6 +16,7 @@ pub struct Layout {
pub logo: String,
pub favicon: String,
pub krate: String,
+ pub playground_url: String,
}
pub struct Page<'a> {
@@ -108,11 +109,13 @@ r##"
+ {play_js}