Skip to content

Commit a34727f

Browse files
committed
auto merge of #11416 : bjz/rust/remove-print-fns, r=alexcrichton
The `print!` and `println!` macros are now the preferred method of printing, and so there is no reason to export the `stdio` functions in the prelude. The functions have also been replaced by their macro counterparts in the tutorial and other documentation so that newcomers don't get confused about what they should be using.
2 parents 5a6ca45 + 4fc0452 commit a34727f

File tree

130 files changed

+350
-336
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

130 files changed

+350
-336
lines changed

doc/guide-conditions.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,7 @@ fn main() {
275275
276276
};
277277
if result.is_err() {
278-
println("parsing failed");
278+
println!("parsing failed");
279279
}
280280
}
281281

doc/guide-container.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -218,12 +218,12 @@ let xs = [2u, 3, 5, 7, 11, 13, 17];
218218

219219
// print out all the elements in the vector
220220
for x in xs.iter() {
221-
println(x.to_str())
221+
println!("{}", *x)
222222
}
223223

224224
// print out all but the first 3 elements in the vector
225225
for x in xs.iter().skip(3) {
226-
println(x.to_str())
226+
println!("{}", *x)
227227
}
228228
~~~
229229

doc/guide-pointers.md

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ struct Point {
222222
fn main() {
223223
let a = Point { x: 10, y: 20 };
224224
do spawn {
225-
println(a.x.to_str());
225+
println!("{}", a.x);
226226
}
227227
}
228228
~~~
@@ -239,7 +239,7 @@ struct Point {
239239
fn main() {
240240
let a = ~Point { x: 10, y: 20 };
241241
do spawn {
242-
println(a.x.to_str());
242+
println!("{}", a.x);
243243
}
244244
}
245245
~~~
@@ -270,18 +270,22 @@ struct Point {
270270
fn main() {
271271
let a = ~Point { x: 10, y: 20 };
272272
let b = a;
273-
println(b.x.to_str());
274-
println(a.x.to_str());
273+
println!("{}", b.x);
274+
println!("{}", a.x);
275275
}
276276
~~~
277277

278278
You'll get this error:
279279

280280
~~~ {.notrust}
281-
test.rs:10:12: 10:13 error: use of moved value: `a`
282-
test.rs:10 println(a.x.to_str());
283-
^
284-
test.rs:8:8: 8:9 note: `a` moved here because it has type `~Point`, which is moved by default (use `ref` to override)
281+
test.rs:10:20: 10:21 error: use of moved value: `a`
282+
test.rs:10 println!("{}", a.x);
283+
^
284+
note: in expansion of format_args!
285+
<std-macros>:158:27: 158:81 note: expansion site
286+
<std-macros>:157:5: 159:6 note: in expansion of println!
287+
test.rs:10:5: 10:25 note: expansion site
288+
test.rs:8:9: 8:10 note: `a` moved here because it has type `~Point`, which is moved by default (use `ref` to override)
285289
test.rs:8 let b = a;
286290
^
287291
~~~
@@ -297,8 +301,8 @@ struct Point {
297301
fn main() {
298302
let a = @Point { x: 10, y: 20 };
299303
let b = a;
300-
println(b.x.to_str());
301-
println(a.x.to_str());
304+
println!("{}", b.x);
305+
println!("{}", a.x);
302306
}
303307
~~~
304308

@@ -367,7 +371,7 @@ compile?
367371

368372
~~~rust{.xfail-test}
369373
fn main() {
370-
println(x.to_str());
374+
println!("{}", x);
371375
let x = 5;
372376
}
373377
~~~

doc/guide-rustpkg.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ Next, let's add a source file:
143143
#[license = "MIT"];
144144
145145
pub fn world() {
146-
println("Hello, world.");
146+
println!("Hello, world.");
147147
}
148148
~~~
149149

doc/guide-tasks.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,15 +72,15 @@ closure in the new task.
7272
# use std::task::spawn;
7373
7474
// Print something profound in a different task using a named function
75-
fn print_message() { println("I am running in a different task!"); }
75+
fn print_message() { println!("I am running in a different task!"); }
7676
spawn(print_message);
7777
7878
// Print something more profound in a different task using a lambda expression
79-
spawn(proc() println("I am also running in a different task!") );
79+
spawn(proc() println!("I am also running in a different task!") );
8080
8181
// The canonical way to spawn is using `do` notation
8282
do spawn {
83-
println("I too am running in a different task!");
83+
println!("I too am running in a different task!");
8484
}
8585
~~~~
8686

doc/rust.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2668,7 +2668,7 @@ An example:
26682668
let mut i = 0;
26692669
26702670
while i < 10 {
2671-
println("hello\n");
2671+
println!("hello");
26722672
i = i + 1;
26732673
}
26742674
~~~~
@@ -3267,7 +3267,7 @@ impl Printable for int {
32673267
}
32683268
32693269
fn print(a: @Printable) {
3270-
println(a.to_string());
3270+
println!("{}", a.to_string());
32713271
}
32723272
32733273
fn main() {

0 commit comments

Comments
 (0)