Skip to content

Commit d4d856b

Browse files
committed
auto merge of #8582 : thestinger/rust/container, r=thestinger
5f3a637 r=huonw 934a5eb r=thestinger 0f6e90a r=cmr
2 parents 48dded9 + 0f6e90a commit d4d856b

40 files changed

+284
-319
lines changed

configure

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -739,6 +739,7 @@ do
739739
make_dir $h/test/doc-tutorial-ffi
740740
make_dir $h/test/doc-tutorial-macros
741741
make_dir $h/test/doc-tutorial-borrowed-ptr
742+
make_dir $h/test/doc-tutorial-container
742743
make_dir $h/test/doc-tutorial-tasks
743744
make_dir $h/test/doc-tutorial-conditions
744745
make_dir $h/test/doc-rust

doc/rust.md

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2864,17 +2864,16 @@ the vtable pointer for the `T` implementation of `R`, and the pointer value of `
28642864
An example of an object type:
28652865

28662866
~~~~~~~~
2867-
# use std::int;
28682867
trait Printable {
2869-
fn to_str(&self) -> ~str;
2868+
fn to_string(&self) -> ~str;
28702869
}
28712870
28722871
impl Printable for int {
2873-
fn to_str(&self) -> ~str { int::to_str(*self) }
2872+
fn to_string(&self) -> ~str { self.to_str() }
28742873
}
28752874
28762875
fn print(a: @Printable) {
2877-
println(a.to_str());
2876+
println(a.to_string());
28782877
}
28792878
28802879
fn main() {

doc/tutorial-container.md

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ assert_eq!(sum, 57);
163163
The `for` keyword can be used as sugar for iterating through any iterator:
164164
165165
~~~
166-
let xs = [2, 3, 5, 7, 11, 13, 17];
166+
let xs = [2u, 3, 5, 7, 11, 13, 17];
167167

168168
// print out all the elements in the vector
169169
for x in xs.iter() {
@@ -219,7 +219,7 @@ Containers can provide conversion from iterators through `collect` by
219219
implementing the `FromIterator` trait. For example, the implementation for
220220
vectors is as follows:
221221
222-
~~~
222+
~~~ {.xfail-test}
223223
impl<A> FromIterator<A> for ~[A] {
224224
pub fn from_iterator<T: Iterator<A>>(iterator: &mut T) -> ~[A] {
225225
let (lower, _) = iterator.size_hint();
@@ -237,7 +237,7 @@ impl<A> FromIterator<A> for ~[A] {
237237
The `Iterator` trait provides a `size_hint` default method, returning a lower
238238
bound and optionally on upper bound on the length of the iterator:
239239

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

@@ -319,6 +319,16 @@ for x in it.invert() {
319319
}
320320
~~~
321321

322+
The `reverse_` method is also available for any double-ended iterator yielding
323+
mutable references. It can be used to reverse a container in-place. Note that
324+
the trailing underscore is a workaround for issue #5898 and will be removed.
325+
326+
~~~
327+
let mut ys = [1, 2, 3, 4, 5];
328+
ys.mut_iter().reverse_();
329+
assert_eq!(ys, [5, 4, 3, 2, 1]);
330+
~~~
331+
322332
## Random-access iterators
323333

324334
The `RandomAccessIterator` trait represents an iterator offering random access

doc/tutorial.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -555,12 +555,11 @@ while cake_amount > 0 {
555555
`loop` denotes an infinite loop, and is the preferred way of writing `while true`:
556556

557557
~~~~
558-
use std::int;
559-
let mut x = 5;
558+
let mut x = 5u;
560559
loop {
561560
x += x - 3;
562561
if x % 5 == 0 { break; }
563-
println(int::to_str(x));
562+
println(x.to_str());
564563
}
565564
~~~~
566565

mk/tests.mk

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ TEST_CRATES = $(TEST_TARGET_CRATES) $(TEST_HOST_CRATES)
2020

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

2525
######################################################################
2626
# Environment configuration

src/libextra/crypto/digest.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
use std::uint;
1211
use std::vec;
1312

1413

@@ -71,7 +70,7 @@ pub trait Digest {
7170
fn to_hex(rr: &[u8]) -> ~str {
7271
let mut s = ~"";
7372
for b in rr.iter() {
74-
let hex = uint::to_str_radix(*b as uint, 16u);
73+
let hex = (*b as uint).to_str_radix(16u);
7574
if hex.len() == 1 {
7675
s.push_char('0');
7776
}

src/libextra/extra.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,6 @@ pub mod flatpipes;
5555

5656
pub mod container;
5757
pub mod bitv;
58-
pub mod fun_treemap;
5958
pub mod list;
6059
pub mod ringbuf;
6160
pub mod priority_queue;

src/libextra/fun_treemap.rs

Lines changed: 0 additions & 84 deletions
This file was deleted.

src/libextra/md4.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
// except according to those terms.
1010

1111

12-
use std::uint;
1312
use std::vec;
1413

1514
struct Quad {
@@ -121,7 +120,7 @@ pub fn md4_str(msg: &[u8]) -> ~str {
121120
if byte <= 16u8 {
122121
result.push_char('0')
123122
}
124-
result.push_str(uint::to_str_radix(byte as uint, 16u));
123+
result.push_str((byte as uint).to_str_radix(16u));
125124
i += 1u32;
126125
}
127126
}

src/libextra/num/bigint.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -525,7 +525,7 @@ impl ToStrRadix for BigUint {
525525
if v.is_empty() { return ~"0" }
526526
let mut s = str::with_capacity(v.len() * l);
527527
for n in v.rev_iter() {
528-
let ss = uint::to_str_radix(*n as uint, radix);
528+
let ss = (*n as uint).to_str_radix(radix);
529529
s.push_str("0".repeat(l - ss.len()));
530530
s.push_str(ss);
531531
}

src/libextra/time.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@
1010

1111
#[allow(missing_doc)];
1212

13-
14-
use std::int;
1513
use std::io;
1614
use std::num;
1715
use std::str;
@@ -824,7 +822,7 @@ fn do_strftime(format: &str, tm: &Tm) -> ~str {
824822
//'U' {}
825823
'u' => {
826824
let i = tm.tm_wday as int;
827-
int::to_str(if i == 0 { 7 } else { i })
825+
(if i == 0 { 7 } else { i }).to_str()
828826
}
829827
//'V' {}
830828
'v' => {
@@ -834,10 +832,10 @@ fn do_strftime(format: &str, tm: &Tm) -> ~str {
834832
parse_type('Y', tm))
835833
}
836834
//'W' {}
837-
'w' => int::to_str(tm.tm_wday as int),
835+
'w' => (tm.tm_wday as int).to_str(),
838836
//'X' {}
839837
//'x' {}
840-
'Y' => int::to_str(tm.tm_year as int + 1900),
838+
'Y' => (tm.tm_year as int + 1900).to_str(),
841839
'y' => fmt!("%02d", (tm.tm_year as int + 1900) % 100),
842840
'Z' => tm.tm_zone.clone(),
843841
'z' => {

src/librustc/driver/driver.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ use util::common::time;
2626
use util::ppaux;
2727

2828
use std::hashmap::{HashMap,HashSet};
29-
use std::int;
3029
use std::io;
3130
use std::os;
3231
use std::vec;
@@ -454,21 +453,21 @@ pub fn pretty_print_input(sess: Session, cfg: ast::CrateConfig, input: &input,
454453
match node {
455454
pprust::node_item(s, item) => {
456455
pp::space(s.s);
457-
pprust::synth_comment(s, int::to_str(item.id));
456+
pprust::synth_comment(s, item.id.to_str());
458457
}
459458
pprust::node_block(s, ref blk) => {
460459
pp::space(s.s);
461460
pprust::synth_comment(
462-
s, ~"block " + int::to_str(blk.id));
461+
s, ~"block " + blk.id.to_str());
463462
}
464463
pprust::node_expr(s, expr) => {
465464
pp::space(s.s);
466-
pprust::synth_comment(s, int::to_str(expr.id));
465+
pprust::synth_comment(s, expr.id.to_str());
467466
pprust::pclose(s);
468467
}
469468
pprust::node_pat(s, pat) => {
470469
pp::space(s.s);
471-
pprust::synth_comment(s, ~"pat " + int::to_str(pat.id));
470+
pprust::synth_comment(s, ~"pat " + pat.id.to_str());
472471
}
473472
}
474473
}

src/librustc/metadata/encoder.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ use std::hash::HashUtil;
2525
use std::hashmap::{HashMap, HashSet};
2626
use std::io;
2727
use std::str;
28-
use std::uint;
2928
use std::vec;
3029
use extra::flate;
3130
use extra::serialize::Encodable;
@@ -303,7 +302,7 @@ fn encode_disr_val(_: &EncodeContext,
303302
ebml_w: &mut writer::Encoder,
304303
disr_val: uint) {
305304
ebml_w.start_tag(tag_disr_val);
306-
let s = uint::to_str(disr_val);
305+
let s = disr_val.to_str();
307306
ebml_w.writer.write(s.as_bytes());
308307
ebml_w.end_tag();
309308
}

src/librustc/metadata/tyencode.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ use middle::ty;
1717
use std::hashmap::HashMap;
1818
use std::io::WriterUtil;
1919
use std::io;
20-
use std::uint;
2120
use syntax::abi::AbiSet;
2221
use syntax::ast;
2322
use syntax::ast::*;
@@ -324,7 +323,7 @@ fn enc_sty(w: @io::Writer, cx: @ctxt, st: &ty::sty) {
324323
w.write_char('p');
325324
w.write_str((cx.ds)(did));
326325
w.write_char('|');
327-
w.write_str(uint::to_str(id));
326+
w.write_str(id.to_str());
328327
}
329328
ty::ty_self(did) => {
330329
w.write_char('s');

src/librustc/middle/trans/base.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,6 @@ use std::hash;
7171
use std::hashmap::HashMap;
7272
use std::io;
7373
use std::libc::c_uint;
74-
use std::uint;
7574
use std::vec;
7675
use std::local_data;
7776
use extra::time;
@@ -719,7 +718,7 @@ pub fn iter_structural_ty(cx: @mut Block, av: ValueRef, t: ty::t,
719718
for variant in (*variants).iter() {
720719
let variant_cx =
721720
sub_block(cx, ~"enum-iter-variant-" +
722-
uint::to_str(variant.disr_val));
721+
variant.disr_val.to_str());
723722
let variant_cx =
724723
iter_variant(variant_cx, repr, av, *variant,
725724
substs.tps, |x,y,z| f(x,y,z));

src/librustc/middle/ty.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ use std::ops;
3333
use std::ptr::to_unsafe_ptr;
3434
use std::to_bytes;
3535
use std::to_str::ToStr;
36-
use std::u32;
3736
use std::vec;
3837
use syntax::ast::*;
3938
use syntax::ast_util::is_local;
@@ -1944,7 +1943,7 @@ impl ops::Sub<TypeContents,TypeContents> for TypeContents {
19441943

19451944
impl ToStr for TypeContents {
19461945
fn to_str(&self) -> ~str {
1947-
fmt!("TypeContents(%s)", u32::to_str_radix(self.bits, 2))
1946+
fmt!("TypeContents(%s)", self.bits.to_str_radix(2))
19481947
}
19491948
}
19501949

src/librustc/middle/typeck/infer/to_str.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ use middle::typeck::infer::InferCtxt;
1717
use middle::typeck::infer::unify::{Redirect, Root, VarValue};
1818
use util::ppaux::{mt_to_str, ty_to_str, trait_ref_to_str};
1919

20-
use std::uint;
2120
use syntax::ast;
2221

2322
pub trait InferStr {
@@ -72,7 +71,7 @@ impl<V:Vid + ToStr,T:InferStr> InferStr for VarValue<V, T> {
7271
match *self {
7372
Redirect(ref vid) => fmt!("Redirect(%s)", vid.to_str()),
7473
Root(ref pt, rk) => fmt!("Root(%s, %s)", pt.inf_str(cx),
75-
uint::to_str_radix(rk, 10u))
74+
rk.to_str_radix(10u))
7675
}
7776
}
7877
}

src/libstd/container.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ pub trait Map<K, V>: Container {
3838
fn find<'a>(&'a self, key: &K) -> Option<&'a V>;
3939

4040
/// Return true if the map contains a value for the specified key
41+
#[inline]
4142
fn contains_key(&self, key: &K) -> bool {
4243
self.find(key).is_some()
4344
}

0 commit comments

Comments
 (0)