Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

container/iterator improvements + small changes #8582

Closed
wants to merge 10 commits into from
1 change: 1 addition & 0 deletions configure
Original file line number Diff line number Diff line change
Expand Up @@ -739,6 +739,7 @@ do
make_dir $h/test/doc-tutorial-ffi
make_dir $h/test/doc-tutorial-macros
make_dir $h/test/doc-tutorial-borrowed-ptr
make_dir $h/test/doc-tutorial-container
make_dir $h/test/doc-tutorial-tasks
make_dir $h/test/doc-tutorial-conditions
make_dir $h/test/doc-rust
Expand Down
7 changes: 3 additions & 4 deletions doc/rust.md
Original file line number Diff line number Diff line change
Expand Up @@ -2864,17 +2864,16 @@ the vtable pointer for the `T` implementation of `R`, and the pointer value of `
An example of an object type:

~~~~~~~~
# use std::int;
trait Printable {
fn to_str(&self) -> ~str;
fn to_string(&self) -> ~str;
}

impl Printable for int {
fn to_str(&self) -> ~str { int::to_str(*self) }
fn to_string(&self) -> ~str { self.to_str() }
}

fn print(a: @Printable) {
println(a.to_str());
println(a.to_string());
}

fn main() {
Expand Down
16 changes: 13 additions & 3 deletions doc/tutorial-container.md
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ assert_eq!(sum, 57);
The `for` keyword can be used as sugar for iterating through any iterator:

~~~
let xs = [2, 3, 5, 7, 11, 13, 17];
let xs = [2u, 3, 5, 7, 11, 13, 17];

// print out all the elements in the vector
for x in xs.iter() {
Expand Down Expand Up @@ -219,7 +219,7 @@ Containers can provide conversion from iterators through `collect` by
implementing the `FromIterator` trait. For example, the implementation for
vectors is as follows:

~~~
~~~ {.xfail-test}
impl<A> FromIterator<A> for ~[A] {
pub fn from_iterator<T: Iterator<A>>(iterator: &mut T) -> ~[A] {
let (lower, _) = iterator.size_hint();
Expand All @@ -237,7 +237,7 @@ impl<A> FromIterator<A> for ~[A] {
The `Iterator` trait provides a `size_hint` default method, returning a lower
bound and optionally on upper bound on the length of the iterator:

~~~
~~~ {.xfail-test}
fn size_hint(&self) -> (uint, Option<uint>) { (0, None) }
~~~

Expand Down Expand Up @@ -319,6 +319,16 @@ for x in it.invert() {
}
~~~

The `reverse_` method is also available for any double-ended iterator yielding
mutable references. It can be used to reverse a container in-place. Note that
the trailing underscore is a workaround for issue #5898 and will be removed.

~~~
let mut ys = [1, 2, 3, 4, 5];
ys.mut_iter().reverse_();
assert_eq!(ys, [5, 4, 3, 2, 1]);
~~~

## Random-access iterators

The `RandomAccessIterator` trait represents an iterator offering random access
Expand Down
5 changes: 2 additions & 3 deletions doc/tutorial.md
Original file line number Diff line number Diff line change
Expand Up @@ -555,12 +555,11 @@ while cake_amount > 0 {
`loop` denotes an infinite loop, and is the preferred way of writing `while true`:

~~~~
use std::int;
let mut x = 5;
let mut x = 5u;
loop {
x += x - 3;
if x % 5 == 0 { break; }
println(int::to_str(x));
println(x.to_str());
}
~~~~

Expand Down
2 changes: 1 addition & 1 deletion mk/tests.mk
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ TEST_CRATES = $(TEST_TARGET_CRATES) $(TEST_HOST_CRATES)

# Markdown files under doc/ that should have their code extracted and run
DOC_TEST_NAMES = tutorial tutorial-ffi tutorial-macros tutorial-borrowed-ptr \
tutorial-tasks tutorial-conditions rust
tutorial-tasks tutorial-conditions tutorial-container rust

######################################################################
# Environment configuration
Expand Down
3 changes: 1 addition & 2 deletions src/libextra/crypto/digest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

use std::uint;
use std::vec;


Expand Down Expand Up @@ -71,7 +70,7 @@ pub trait Digest {
fn to_hex(rr: &[u8]) -> ~str {
let mut s = ~"";
for b in rr.iter() {
let hex = uint::to_str_radix(*b as uint, 16u);
let hex = (*b as uint).to_str_radix(16u);
if hex.len() == 1 {
s.push_char('0');
}
Expand Down
1 change: 0 additions & 1 deletion src/libextra/extra.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ pub mod flatpipes;

pub mod container;
pub mod bitv;
pub mod fun_treemap;
pub mod list;
pub mod ringbuf;
pub mod priority_queue;
Expand Down
84 changes: 0 additions & 84 deletions src/libextra/fun_treemap.rs

This file was deleted.

3 changes: 1 addition & 2 deletions src/libextra/md4.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
// except according to those terms.


use std::uint;
use std::vec;

struct Quad {
Expand Down Expand Up @@ -121,7 +120,7 @@ pub fn md4_str(msg: &[u8]) -> ~str {
if byte <= 16u8 {
result.push_char('0')
}
result.push_str(uint::to_str_radix(byte as uint, 16u));
result.push_str((byte as uint).to_str_radix(16u));
i += 1u32;
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/libextra/num/bigint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -525,7 +525,7 @@ impl ToStrRadix for BigUint {
if v.is_empty() { return ~"0" }
let mut s = str::with_capacity(v.len() * l);
for n in v.rev_iter() {
let ss = uint::to_str_radix(*n as uint, radix);
let ss = (*n as uint).to_str_radix(radix);
s.push_str("0".repeat(l - ss.len()));
s.push_str(ss);
}
Expand Down
8 changes: 3 additions & 5 deletions src/libextra/time.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@

#[allow(missing_doc)];


use std::int;
use std::io;
use std::num;
use std::str;
Expand Down Expand Up @@ -824,7 +822,7 @@ fn do_strftime(format: &str, tm: &Tm) -> ~str {
//'U' {}
'u' => {
let i = tm.tm_wday as int;
int::to_str(if i == 0 { 7 } else { i })
(if i == 0 { 7 } else { i }).to_str()
}
//'V' {}
'v' => {
Expand All @@ -834,10 +832,10 @@ fn do_strftime(format: &str, tm: &Tm) -> ~str {
parse_type('Y', tm))
}
//'W' {}
'w' => int::to_str(tm.tm_wday as int),
'w' => (tm.tm_wday as int).to_str(),
//'X' {}
//'x' {}
'Y' => int::to_str(tm.tm_year as int + 1900),
'Y' => (tm.tm_year as int + 1900).to_str(),
'y' => fmt!("%02d", (tm.tm_year as int + 1900) % 100),
'Z' => tm.tm_zone.clone(),
'z' => {
Expand Down
9 changes: 4 additions & 5 deletions src/librustc/driver/driver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ use util::common::time;
use util::ppaux;

use std::hashmap::{HashMap,HashSet};
use std::int;
use std::io;
use std::os;
use std::vec;
Expand Down Expand Up @@ -454,21 +453,21 @@ pub fn pretty_print_input(sess: Session, cfg: ast::CrateConfig, input: &input,
match node {
pprust::node_item(s, item) => {
pp::space(s.s);
pprust::synth_comment(s, int::to_str(item.id));
pprust::synth_comment(s, item.id.to_str());
}
pprust::node_block(s, ref blk) => {
pp::space(s.s);
pprust::synth_comment(
s, ~"block " + int::to_str(blk.id));
s, ~"block " + blk.id.to_str());
}
pprust::node_expr(s, expr) => {
pp::space(s.s);
pprust::synth_comment(s, int::to_str(expr.id));
pprust::synth_comment(s, expr.id.to_str());
pprust::pclose(s);
}
pprust::node_pat(s, pat) => {
pp::space(s.s);
pprust::synth_comment(s, ~"pat " + int::to_str(pat.id));
pprust::synth_comment(s, ~"pat " + pat.id.to_str());
}
}
}
Expand Down
3 changes: 1 addition & 2 deletions src/librustc/metadata/encoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ use std::hash::HashUtil;
use std::hashmap::{HashMap, HashSet};
use std::io;
use std::str;
use std::uint;
use std::vec;
use extra::flate;
use extra::serialize::Encodable;
Expand Down Expand Up @@ -303,7 +302,7 @@ fn encode_disr_val(_: &EncodeContext,
ebml_w: &mut writer::Encoder,
disr_val: uint) {
ebml_w.start_tag(tag_disr_val);
let s = uint::to_str(disr_val);
let s = disr_val.to_str();
ebml_w.writer.write(s.as_bytes());
ebml_w.end_tag();
}
Expand Down
3 changes: 1 addition & 2 deletions src/librustc/metadata/tyencode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ use middle::ty;
use std::hashmap::HashMap;
use std::io::WriterUtil;
use std::io;
use std::uint;
use syntax::abi::AbiSet;
use syntax::ast;
use syntax::ast::*;
Expand Down Expand Up @@ -324,7 +323,7 @@ fn enc_sty(w: @io::Writer, cx: @ctxt, st: &ty::sty) {
w.write_char('p');
w.write_str((cx.ds)(did));
w.write_char('|');
w.write_str(uint::to_str(id));
w.write_str(id.to_str());
}
ty::ty_self(did) => {
w.write_char('s');
Expand Down
3 changes: 1 addition & 2 deletions src/librustc/middle/trans/base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ use std::hash;
use std::hashmap::HashMap;
use std::io;
use std::libc::c_uint;
use std::uint;
use std::vec;
use std::local_data;
use extra::time;
Expand Down Expand Up @@ -719,7 +718,7 @@ pub fn iter_structural_ty(cx: @mut Block, av: ValueRef, t: ty::t,
for variant in (*variants).iter() {
let variant_cx =
sub_block(cx, ~"enum-iter-variant-" +
uint::to_str(variant.disr_val));
variant.disr_val.to_str());
let variant_cx =
iter_variant(variant_cx, repr, av, *variant,
substs.tps, |x,y,z| f(x,y,z));
Expand Down
3 changes: 1 addition & 2 deletions src/librustc/middle/ty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ use std::ops;
use std::ptr::to_unsafe_ptr;
use std::to_bytes;
use std::to_str::ToStr;
use std::u32;
use std::vec;
use syntax::ast::*;
use syntax::ast_util::is_local;
Expand Down Expand Up @@ -1944,7 +1943,7 @@ impl ops::Sub<TypeContents,TypeContents> for TypeContents {

impl ToStr for TypeContents {
fn to_str(&self) -> ~str {
fmt!("TypeContents(%s)", u32::to_str_radix(self.bits, 2))
fmt!("TypeContents(%s)", self.bits.to_str_radix(2))
}
}

Expand Down
3 changes: 1 addition & 2 deletions src/librustc/middle/typeck/infer/to_str.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ use middle::typeck::infer::InferCtxt;
use middle::typeck::infer::unify::{Redirect, Root, VarValue};
use util::ppaux::{mt_to_str, ty_to_str, trait_ref_to_str};

use std::uint;
use syntax::ast;

pub trait InferStr {
Expand Down Expand Up @@ -72,7 +71,7 @@ impl<V:Vid + ToStr,T:InferStr> InferStr for VarValue<V, T> {
match *self {
Redirect(ref vid) => fmt!("Redirect(%s)", vid.to_str()),
Root(ref pt, rk) => fmt!("Root(%s, %s)", pt.inf_str(cx),
uint::to_str_radix(rk, 10u))
rk.to_str_radix(10u))
}
}
}
Expand Down
1 change: 1 addition & 0 deletions src/libstd/container.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ pub trait Map<K, V>: Container {
fn find<'a>(&'a self, key: &K) -> Option<&'a V>;

/// Return true if the map contains a value for the specified key
#[inline]
fn contains_key(&self, key: &K) -> bool {
self.find(key).is_some()
}
Expand Down
Loading