Skip to content

Commit ca162df

Browse files
committed
---
yaml --- r: 140717 b: refs/heads/try2 c: 82f963e h: refs/heads/master i: 140715: a0a8e0c v: v3
1 parent 4b8f9aa commit ca162df

22 files changed

+86
-69
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ refs/heads/snap-stage3: 78a7676898d9f80ab540c6df5d4c9ce35bb50463
55
refs/heads/try: 519addf6277dbafccbb4159db4b710c37eaa2ec5
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
8-
refs/heads/try2: f2f10bdc7a2f1d1501abb04f3625356c0c251d92
8+
refs/heads/try2: 82f963e347fa16ac3824e81c53f5d15155fe319b
99
refs/heads/dist-snap: ba4081a5a8573875fed17545846f6f6902c8ba8d
1010
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596
1111
refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503

branches/try2/doc/tutorial.md

Lines changed: 31 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ we have a file `hello.rs` containing this program:
129129

130130
~~~~
131131
fn main() {
132-
println("hello?");
132+
io::println("hello?");
133133
}
134134
~~~~
135135

@@ -139,12 +139,12 @@ Windows) which, upon running, will likely do exactly what you expect.
139139

140140
The Rust compiler tries to provide useful information when it encounters an
141141
error. If you introduce an error into the program (for example, by changing
142-
`println` to some nonexistent function), and then compile it, you'll see
142+
`io::println` to some nonexistent function), and then compile it, you'll see
143143
an error message like this:
144144

145145
~~~~ {.notrust}
146-
hello.rs:2:4: 2:16 error: unresolved name: print_with_unicorns
147-
hello.rs:2 print_with_unicorns("hello?");
146+
hello.rs:2:4: 2:16 error: unresolved name: io::print_with_unicorns
147+
hello.rs:2 io::print_with_unicorns("hello?");
148148
^~~~~~~~~~~~~~~~~~~~~~~
149149
~~~~
150150

@@ -227,7 +227,7 @@ let hi = "hi";
227227
let mut count = 0;
228228
229229
while count < 10 {
230-
println(fmt!("count: %?", count));
230+
io::println(fmt!("count: %?", count));
231231
count += 1;
232232
}
233233
~~~~
@@ -400,10 +400,10 @@ don't match the types of the arguments.
400400
~~~~
401401
# let mystery_object = ();
402402
403-
println(fmt!("%s is %d", "the answer", 43));
403+
io::println(fmt!("%s is %d", "the answer", 43));
404404
405405
// %? will conveniently print any type
406-
println(fmt!("what is this thing: %?", mystery_object));
406+
io::println(fmt!("what is this thing: %?", mystery_object));
407407
~~~~
408408

409409
[pf]: http://en.cppreference.com/w/cpp/io/c/fprintf
@@ -422,11 +422,11 @@ compulsory, an `if` can have an optional `else` clause, and multiple
422422

423423
~~~~
424424
if false {
425-
println("that's odd");
425+
io::println("that's odd");
426426
} else if true {
427-
println("right");
427+
io::println("right");
428428
} else {
429-
println("neither true nor false");
429+
io::println("neither true nor false");
430430
}
431431
~~~~
432432

@@ -454,10 +454,10 @@ executes its corresponding arm.
454454
~~~~
455455
# let my_number = 1;
456456
match my_number {
457-
0 => println("zero"),
458-
1 | 2 => println("one or two"),
459-
3..10 => println("three to ten"),
460-
_ => println("something else")
457+
0 => io::println("zero"),
458+
1 | 2 => io::println("one or two"),
459+
3..10 => io::println("three to ten"),
460+
_ => io::println("something else")
461461
}
462462
~~~~
463463

@@ -483,8 +483,8 @@ commas are optional.
483483
~~~
484484
# let my_number = 1;
485485
match my_number {
486-
0 => { println("zero") }
487-
_ => { println("something else") }
486+
0 => { io::println("zero") }
487+
_ => { io::println("something else") }
488488
}
489489
~~~
490490

@@ -560,7 +560,7 @@ let mut x = 5;
560560
loop {
561561
x += x - 3;
562562
if x % 5 == 0 { break; }
563-
println(int::to_str(x));
563+
io::println(int::to_str(x));
564564
}
565565
~~~~
566566

@@ -614,8 +614,8 @@ origin.y += 1.0; // ERROR: assigning to immutable field
614614
# struct Point { x: float, y: float }
615615
# let mypoint = Point { x: 0.0, y: 0.0 };
616616
match mypoint {
617-
Point { x: 0.0, y: yy } => { println(yy.to_str()); }
618-
Point { x: xx, y: yy } => { println(xx.to_str() + " " + yy.to_str()); }
617+
Point { x: 0.0, y: yy } => { io::println(yy.to_str()); }
618+
Point { x: xx, y: yy } => { io::println(xx.to_str() + " " + yy.to_str()); }
619619
}
620620
~~~~
621621

@@ -630,7 +630,7 @@ reuses the field name as the binding name.
630630
# struct Point { x: float, y: float }
631631
# let mypoint = Point { x: 0.0, y: 0.0 };
632632
match mypoint {
633-
Point { x, _ } => { println(x.to_str()) }
633+
Point { x, _ } => { io::println(x.to_str()) }
634634
}
635635
~~~
636636

@@ -1231,7 +1231,7 @@ something silly like
12311231
~~~
12321232
# struct Point { x: float, y: float }
12331233
let point = &@~Point { x: 10f, y: 20f };
1234-
println(fmt!("%f", point.x));
1234+
io::println(fmt!("%f", point.x));
12351235
~~~
12361236
12371237
The indexing operator (`[]`) also auto-dereferences.
@@ -1373,6 +1373,7 @@ and [`core::str`]. Here are some examples.
13731373
[`core::str`]: core/str.html
13741374

13751375
~~~
1376+
# use core::io::println;
13761377
# enum Crayon {
13771378
# Almond, AntiqueBrass, Apricot,
13781379
# Aquamarine, Asparagus, AtomicTangerine,
@@ -1427,6 +1428,7 @@ Rust also supports _closures_, functions that can access variables in
14271428
the enclosing scope.
14281429

14291430
~~~~
1431+
# use println = core::io::println;
14301432
fn call_closure_with_ten(b: &fn(int)) { b(10); }
14311433
14321434
let captured_var = 20;
@@ -1488,7 +1490,7 @@ fn mk_appender(suffix: ~str) -> @fn(~str) -> ~str {
14881490
14891491
fn main() {
14901492
let shout = mk_appender(~"!");
1491-
println(shout(~"hey ho, let's go"));
1493+
io::println(shout(~"hey ho, let's go"));
14921494
}
14931495
~~~~
14941496

@@ -1630,6 +1632,7 @@ And using this function to iterate over a vector:
16301632

16311633
~~~~
16321634
# use each = core::vec::each;
1635+
# use println = core::io::println;
16331636
each([2, 4, 8, 5, 16], |n| {
16341637
if *n % 2 != 0 {
16351638
println("found odd number!");
@@ -1646,6 +1649,7 @@ to the next iteration, write `loop`.
16461649

16471650
~~~~
16481651
# use each = core::vec::each;
1652+
# use println = core::io::println;
16491653
for each([2, 4, 8, 5, 16]) |n| {
16501654
if *n % 2 != 0 {
16511655
println("found odd number!");
@@ -1978,7 +1982,7 @@ struct TimeBomb {
19781982
impl Drop for TimeBomb {
19791983
fn finalize(&self) {
19801984
for old_iter::repeat(self.explosivity) {
1981-
println("blam!");
1985+
io::println("blam!");
19821986
}
19831987
}
19841988
}
@@ -2010,11 +2014,11 @@ and `~str`.
20102014
~~~~
20112015
# trait Printable { fn print(&self); }
20122016
impl Printable for int {
2013-
fn print(&self) { println(fmt!("%d", *self)) }
2017+
fn print(&self) { io::println(fmt!("%d", *self)) }
20142018
}
20152019
20162020
impl Printable for ~str {
2017-
fn print(&self) { println(*self) }
2021+
fn print(&self) { io::println(*self) }
20182022
}
20192023
20202024
# 1.print();
@@ -2303,7 +2307,7 @@ mod farm {
23032307
}
23042308
23052309
fn main() {
2306-
println(farm::chicken());
2310+
io::println(farm::chicken());
23072311
}
23082312
~~~~
23092313

@@ -2503,7 +2507,7 @@ pub fn explore() -> &str { "world" }
25032507
~~~~ {.xfail-test}
25042508
// main.rs
25052509
extern mod world;
2506-
fn main() { println(~"hello " + world::explore()); }
2510+
fn main() { io::println(~"hello " + world::explore()); }
25072511
~~~~
25082512

25092513
Now compile and run like this (adjust to your platform if necessary):

branches/try2/src/libcore/core

9.02 MB
Binary file not shown.

branches/try2/src/libcore/old_iter.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ pub trait CopyableNonstrictIter<A:Copy> {
9393
// Like "each", but copies out the value. If the receiver is mutated while
9494
// iterating over it, the semantics must not be memory-unsafe but are
9595
// otherwise undefined.
96-
fn each_val(&const self, f: &fn(A) -> bool);
96+
fn each_val(&const self, f: &fn(A) -> bool) -> bool;
9797
}
9898

9999
// A trait for sequences that can be built by imperatively pushing elements

branches/try2/src/libcore/vec.rs

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2945,34 +2945,37 @@ impl<A:Copy + Ord> old_iter::CopyableOrderedIter<A> for @[A] {
29452945
}
29462946

29472947
impl<'self,A:Copy> old_iter::CopyableNonstrictIter<A> for &'self [A] {
2948-
fn each_val(&const self, f: &fn(A) -> bool) {
2948+
fn each_val(&const self, f: &fn(A) -> bool) -> bool {
29492949
let mut i = 0;
29502950
while i < self.len() {
2951-
if !f(copy self[i]) { break; }
2951+
if !f(copy self[i]) { return false; }
29522952
i += 1;
29532953
}
2954+
return true;
29542955
}
29552956
}
29562957

29572958
// FIXME(#4148): This should be redundant
29582959
impl<A:Copy> old_iter::CopyableNonstrictIter<A> for ~[A] {
2959-
fn each_val(&const self, f: &fn(A) -> bool) {
2960+
fn each_val(&const self, f: &fn(A) -> bool) -> bool {
29602961
let mut i = 0;
29612962
while i < uniq_len(self) {
2962-
if !f(copy self[i]) { break; }
2963+
if !f(copy self[i]) { return false; }
29632964
i += 1;
29642965
}
2966+
return true;
29652967
}
29662968
}
29672969

29682970
// FIXME(#4148): This should be redundant
29692971
impl<A:Copy> old_iter::CopyableNonstrictIter<A> for @[A] {
2970-
fn each_val(&const self, f: &fn(A) -> bool) {
2972+
fn each_val(&const self, f: &fn(A) -> bool) -> bool {
29712973
let mut i = 0;
29722974
while i < self.len() {
2973-
if !f(copy self[i]) { break; }
2975+
if !f(copy self[i]) { return false; }
29742976
i += 1;
29752977
}
2978+
return true;
29762979
}
29772980
}
29782981

@@ -4688,4 +4691,14 @@ mod tests {
46884691
i += 1;
46894692
}
46904693
}
4694+
4695+
#[test]
4696+
fn test_each_val() {
4697+
use old_iter::CopyableNonstrictIter;
4698+
let mut i = 0;
4699+
for [1, 2, 3].each_val |v| {
4700+
i += v;
4701+
}
4702+
assert!(i == 6);
4703+
}
46914704
}

branches/try2/src/librustc/middle/resolve.rs

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1007,7 +1007,7 @@ pub impl Resolver {
10071007
let ns = namespace_for_duplicate_checking_mode(
10081008
duplicate_checking_mode);
10091009
self.session.span_err(sp,
1010-
fmt!("duplicate definition of %s `%s`",
1010+
fmt!("duplicate definition of %s %s",
10111011
namespace_to_str(ns),
10121012
*self.session.str_of(name)));
10131013
for child.span_for_namespace(ns).each |sp| {
@@ -1959,7 +1959,7 @@ pub impl Resolver {
19591959
match self.resolve_import_for_module(module, import_directive) {
19601960
Failed => {
19611961
// We presumably emitted an error. Continue.
1962-
let msg = fmt!("failed to resolve import `%s`",
1962+
let msg = fmt!("failed to resolve import: %s",
19631963
*self.import_path_to_str(
19641964
import_directive.module_path,
19651965
*import_directive.subclass));
@@ -2488,7 +2488,7 @@ pub impl Resolver {
24882488
self.session.span_err(span {lo: span.lo, hi: span.lo +
24892489
BytePos(str::len(*segment_name)), expn_info:
24902490
span.expn_info}, fmt!("unresolved import. maybe \
2491-
a missing `extern mod %s`?",
2491+
a missing 'extern mod %s'?",
24922492
*segment_name));
24932493
return Failed;
24942494
}
@@ -2511,7 +2511,7 @@ pub impl Resolver {
25112511
// Not a module.
25122512
self.session.span_err(span,
25132513
fmt!("not a \
2514-
module `%s`",
2514+
module: %s",
25152515
*self.session.
25162516
str_of(
25172517
name)));
@@ -2525,7 +2525,7 @@ pub impl Resolver {
25252525
None => {
25262526
// There are no type bindings at all.
25272527
self.session.span_err(span,
2528-
fmt!("not a module `%s`",
2528+
fmt!("not a module: %s",
25292529
*self.session.str_of(
25302530
name)));
25312531
return Failed;
@@ -2976,7 +2976,7 @@ pub impl Resolver {
29762976
}
29772977

29782978
// We're out of luck.
2979-
debug!("(resolving name in module) failed to resolve `%s`",
2979+
debug!("(resolving name in module) failed to resolve %s",
29802980
*self.session.str_of(name));
29812981
return Failed;
29822982
}
@@ -4158,7 +4158,7 @@ pub impl Resolver {
41584158
// in the same disjunct, which is an
41594159
// error
41604160
self.session.span_err(pattern.span,
4161-
fmt!("Identifier `%s` is bound more \
4161+
fmt!("Identifier %s is bound more \
41624162
than once in the same pattern",
41634163
path_to_str(path, self.session
41644164
.intr())));
@@ -4199,7 +4199,7 @@ pub impl Resolver {
41994199
Some(_) => {
42004200
self.session.span_err(
42014201
path.span,
4202-
fmt!("`%s` is not an enum variant or constant",
4202+
fmt!("not an enum variant or constant: %s",
42034203
*self.session.str_of(
42044204
*path.idents.last())));
42054205
}
@@ -4227,7 +4227,7 @@ pub impl Resolver {
42274227
Some(_) => {
42284228
self.session.span_err(
42294229
path.span,
4230-
fmt!("`%s` is not an enum variant, struct or const",
4230+
fmt!("not an enum variant, struct or const: %s",
42314231
*self.session.str_of(
42324232
*path.idents.last())));
42334233
}
@@ -4723,8 +4723,8 @@ pub impl Resolver {
47234723
path.idents);
47244724
if self.name_exists_in_scope_struct(wrong_name) {
47254725
self.session.span_err(expr.span,
4726-
fmt!("unresolved name `%s`. \
4727-
Did you mean `self.%s`?",
4726+
fmt!("unresolved name: `%s`. \
4727+
Did you mean: `self.%s`?",
47284728
wrong_name,
47294729
wrong_name));
47304730
}
@@ -4734,13 +4734,13 @@ pub impl Resolver {
47344734
match self.find_best_match_for_name(wrong_name, 5) {
47354735
Some(m) => {
47364736
self.session.span_err(expr.span,
4737-
fmt!("unresolved name `%s`. \
4738-
Did you mean `%s`?",
4737+
fmt!("unresolved name: `%s`. \
4738+
Did you mean: `%s`?",
47394739
wrong_name, m));
47404740
}
47414741
None => {
47424742
self.session.span_err(expr.span,
4743-
fmt!("unresolved name `%s`.",
4743+
fmt!("unresolved name: `%s`.",
47444744
wrong_name));
47454745
}
47464746
}

0 commit comments

Comments
 (0)