Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Guessing game example does not give a warning #37307

Closed
vkatsikaros opened this issue Oct 20, 2016 · 4 comments
Closed

Guessing game example does not give a warning #37307

vkatsikaros opened this issue Oct 20, 2016 · 4 comments

Comments

@vkatsikaros
Copy link
Contributor

The Rust book on Guessing Game - Processing a Guess says that after compiling the example we'll get a warning. However, I didn't get one:

~/projects/rust $ cargo new guessing_game_2 --bin
     Created binary (application) `guessing_game_2` project
~/projects/rust $ cd guessing_game_2/
~/projects/rust/guessing_game_2 $ cargo build
   Compiling guessing_game_2 v0.1.0 (file:///home/vag/projects/rust/guessing_game_2)
    Finished debug [unoptimized + debuginfo] target(s) in 0.52 secs
~/projects/rust/guessing_game_2 $ cargo run
    Finished debug [unoptimized + debuginfo] target(s) in 0.0 secs
     Running `target/debug/guessing_game_2`
Hello, world!
~/projects/rust/guessing_game_2 $ cat > src/main.rs 
use std::io;

fn main() {
    println!("Guess the number!");

    println!("Please input your guess.");

    let mut guess = String::new();

    io::stdin().read_line(&mut guess)
        .expect("Failed to read line");

    println!("You guessed: {}", guess);
}

~/projects/rust/guessing_game_2 $ cargo build
   Compiling guessing_game_2 v0.1.0 (file:///home/vag/projects/rust/guessing_game_2)
    Finished debug [unoptimized + debuginfo] target(s) in 0.65 secs

According to the book I expected:

src/main.rs:10:5: 10:39 warning: unused result which must be used,
#[warn(unused_must_use)] on by default
src/main.rs:10     io::stdin().read_line(&mut guess);

I installed rust via https://rustup.rs/ and I got

$ rustc --version && cargo --version
rustc 1.12.0 (3191fbae9 2016-09-23)
cargo 0.13.0-nightly (109cb7c 2016-08-19)

I am on

$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 14.04.5 LTS
Release:    14.04
Codename:   trusty
@vkatsikaros
Copy link
Contributor Author

After playing with it a bit I got the warning with this:

fn main() {
    println!("Guess the number!");
    println!("Please input your guess.");
    let mut guess = String::new();
    io::stdin().read_line(&mut guess);
    //    .expect("Failed to read line");
    //println!("You guessed: {}", guess);
}

So maybe the wording could be a bit more explanatory?

@TimNN
Copy link
Contributor

TimNN commented Oct 20, 2016

The book pretty explicitly states (emphasis mine):

If we leave off calling this method, our program will compile, but we’ll get a warning:

@vkatsikaros
Copy link
Contributor Author

vkatsikaros commented Oct 20, 2016

Indeed, the wording is explicit, but it could be more explanatory in case my confusion was caused by my non-native English skills.

Minor wording changes like these are quite affected by personal style, so I'd understand if you don't find this useful.

GuillaumeGomez added a commit to GuillaumeGomez/rust that referenced this issue Oct 21, 2016
…illaumeGomez

TRPL: guessing game: minor clarification

The original text is correct and exact, but might confuse a non-English speaker (at least I was confused), so I made it a bit more plain (see rust-lang#37307).

I know minor wording changes like these are affected by personal style, so I'd understand if you don't find this useful.

r? @steveklabnik
@GuillaumeGomez
Copy link
Member

I guess it can be closed now. Don't hesitate to tell me if I'm wrong.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants