From ea92a5e90a4a88d10dcdd5647dfb906aaecadd21 Mon Sep 17 00:00:00 2001 From: Eduardo Bautista Date: Fri, 1 Aug 2014 14:30:52 -0500 Subject: [PATCH 1/2] Use hello_world instead of the guessing_game --- src/doc/guide.md | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/src/doc/guide.md b/src/doc/guide.md index 2216d829e4be8..2bcac24c0a2c9 100644 --- a/src/doc/guide.md +++ b/src/doc/guide.md @@ -449,8 +449,8 @@ let x; ...we'll get an error: ```{ignore} -src/guessing_game.rs:2:9: 2:10 error: cannot determine a type for this local variable: unconstrained type -src/guessing_game.rs:2 let x; +src/hello_world.rs:2:9: 2:10 error: cannot determine a type for this local variable: unconstrained type +src/hello_world.rs:2 let x; ^ ``` @@ -460,7 +460,7 @@ Giving it a type will compile, though: let x: int; ``` -Let's try it out. Change your `src/guessing_game.rs` file to look like this: +Let's try it out. Change your `src/hello_world.rs` file to look like this: ```{rust} fn main() { @@ -474,9 +474,9 @@ You can use `cargo build` on the command line to build it. You'll get a warning, but it will still print "Hello, world!": ```{ignore,notrust} - Compiling guessing_game v0.1.0 (file:/home/you/projects/guessing_game) -src/guessing_game.rs:2:9: 2:10 warning: unused variable: `x`, #[warn(unused_variable)] on by default -src/guessing_game.rs:2 let x: int; + Compiling hello_world v0.1.0 (file:/home/you/projects/hello_world) +src/hello_world.rs:2:9: 2:10 warning: unused variable: `x`, #[warn(unused_variable)] on by default +src/hello_world.rs:2 let x: int; ^ ``` @@ -496,16 +496,16 @@ And try to build it. You'll get an error: ```{bash} $ cargo build - Compiling guessing_game v0.1.0 (file:/home/you/projects/guessing_game) -src/guessing_game.rs:4:39: 4:40 error: use of possibly uninitialized variable: `x` -src/guessing_game.rs:4 println!("The value of x is: {}", x); + Compiling hello_world v0.1.0 (file:/home/you/projects/hello_world) +src/hello_world.rs:4:39: 4:40 error: use of possibly uninitialized variable: `x` +src/hello_world.rs:4 println!("The value of x is: {}", x); ^ note: in expansion of format_args! :2:23: 2:77 note: expansion site :1:1: 3:2 note: in expansion of println! -src/guessing_game.rs:4:5: 4:42 note: expansion site +src/hello_world.rs:4:5: 4:42 note: expansion site error: aborting due to previous error -Could not execute process `rustc src/guessing_game.rs --crate-type bin --out-dir /home/you/projects/guessing_game/target -L /home/you/projects/guessing_game/target -L /home/you/projects/guessing_game/target/deps` (status=101) +Could not execute process `rustc src/hello_world.rs --crate-type bin --out-dir /home/you/projects/hello_world/target -L /home/you/projects/hello_world/target -L /home/you/projects/hello_world/target/deps` (status=101) ``` Rust will not let us use a value that has not been initialized. So why let us From 69267b1e1d42c4c00ce2c478be8d8088f7a75283 Mon Sep 17 00:00:00 2001 From: Eduardo Bautista Date: Fri, 1 Aug 2014 14:34:18 -0500 Subject: [PATCH 2/2] Move caret under the 'x' variabe --- src/doc/guide.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/doc/guide.md b/src/doc/guide.md index 2bcac24c0a2c9..0a8520436ff61 100644 --- a/src/doc/guide.md +++ b/src/doc/guide.md @@ -451,7 +451,7 @@ let x; ```{ignore} src/hello_world.rs:2:9: 2:10 error: cannot determine a type for this local variable: unconstrained type src/hello_world.rs:2 let x; - ^ + ^ ``` Giving it a type will compile, though: @@ -477,7 +477,7 @@ but it will still print "Hello, world!": Compiling hello_world v0.1.0 (file:/home/you/projects/hello_world) src/hello_world.rs:2:9: 2:10 warning: unused variable: `x`, #[warn(unused_variable)] on by default src/hello_world.rs:2 let x: int; - ^ + ^ ``` Rust warns us that we never use the variable binding, but since we never use it, @@ -499,7 +499,7 @@ $ cargo build Compiling hello_world v0.1.0 (file:/home/you/projects/hello_world) src/hello_world.rs:4:39: 4:40 error: use of possibly uninitialized variable: `x` src/hello_world.rs:4 println!("The value of x is: {}", x); - ^ + ^ note: in expansion of format_args! :2:23: 2:77 note: expansion site :1:1: 3:2 note: in expansion of println!