Skip to content

Commit

Permalink
auto merge of #11416 : bjz/rust/remove-print-fns, r=alexcrichton
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
bors committed Jan 11, 2014
2 parents 5a6ca45 + 4fc0452 commit a34727f
Show file tree
Hide file tree
Showing 130 changed files with 350 additions and 336 deletions.
2 changes: 1 addition & 1 deletion doc/guide-conditions.md
Expand Up @@ -275,7 +275,7 @@ fn main() {
};
if result.is_err() {
println("parsing failed");
println!("parsing failed");
}
}
Expand Down
4 changes: 2 additions & 2 deletions doc/guide-container.md
Expand Up @@ -218,12 +218,12 @@ let xs = [2u, 3, 5, 7, 11, 13, 17];
// print out all the elements in the vector
for x in xs.iter() {
println(x.to_str())
println!("{}", *x)
}
// print out all but the first 3 elements in the vector
for x in xs.iter().skip(3) {
println(x.to_str())
println!("{}", *x)
}
~~~

Expand Down
26 changes: 15 additions & 11 deletions doc/guide-pointers.md
Expand Up @@ -222,7 +222,7 @@ struct Point {
fn main() {
let a = Point { x: 10, y: 20 };
do spawn {
println(a.x.to_str());
println!("{}", a.x);
}
}
~~~
Expand All @@ -239,7 +239,7 @@ struct Point {
fn main() {
let a = ~Point { x: 10, y: 20 };
do spawn {
println(a.x.to_str());
println!("{}", a.x);
}
}
~~~
Expand Down Expand Up @@ -270,18 +270,22 @@ struct Point {
fn main() {
let a = ~Point { x: 10, y: 20 };
let b = a;
println(b.x.to_str());
println(a.x.to_str());
println!("{}", b.x);
println!("{}", a.x);
}
~~~

You'll get this error:

~~~ {.notrust}
test.rs:10:12: 10:13 error: use of moved value: `a`
test.rs:10 println(a.x.to_str());
^
test.rs:8:8: 8:9 note: `a` moved here because it has type `~Point`, which is moved by default (use `ref` to override)
test.rs:10:20: 10:21 error: use of moved value: `a`
test.rs:10 println!("{}", a.x);
^
note: in expansion of format_args!
<std-macros>:158:27: 158:81 note: expansion site
<std-macros>:157:5: 159:6 note: in expansion of println!
test.rs:10:5: 10:25 note: expansion site
test.rs:8:9: 8:10 note: `a` moved here because it has type `~Point`, which is moved by default (use `ref` to override)
test.rs:8 let b = a;
^
~~~
Expand All @@ -297,8 +301,8 @@ struct Point {
fn main() {
let a = @Point { x: 10, y: 20 };
let b = a;
println(b.x.to_str());
println(a.x.to_str());
println!("{}", b.x);
println!("{}", a.x);
}
~~~

Expand Down Expand Up @@ -367,7 +371,7 @@ compile?

~~~rust{.xfail-test}
fn main() {
println(x.to_str());
println!("{}", x);
let x = 5;
}
~~~
Expand Down
2 changes: 1 addition & 1 deletion doc/guide-rustpkg.md
Expand Up @@ -143,7 +143,7 @@ Next, let's add a source file:
#[license = "MIT"];
pub fn world() {
println("Hello, world.");
println!("Hello, world.");
}
~~~
Expand Down
6 changes: 3 additions & 3 deletions doc/guide-tasks.md
Expand Up @@ -72,15 +72,15 @@ closure in the new task.
# use std::task::spawn;
// Print something profound in a different task using a named function
fn print_message() { println("I am running in a different task!"); }
fn print_message() { println!("I am running in a different task!"); }
spawn(print_message);
// Print something more profound in a different task using a lambda expression
spawn(proc() println("I am also running in a different task!") );
spawn(proc() println!("I am also running in a different task!") );
// The canonical way to spawn is using `do` notation
do spawn {
println("I too am running in a different task!");
println!("I too am running in a different task!");
}
~~~~

Expand Down
4 changes: 2 additions & 2 deletions doc/rust.md
Expand Up @@ -2668,7 +2668,7 @@ An example:
let mut i = 0;
while i < 10 {
println("hello\n");
println!("hello");
i = i + 1;
}
~~~~
Expand Down Expand Up @@ -3267,7 +3267,7 @@ impl Printable for int {
}
fn print(a: @Printable) {
println(a.to_string());
println!("{}", a.to_string());
}
fn main() {
Expand Down

0 comments on commit a34727f

Please sign in to comment.