Skip to content

First program example in the rust book "Learn" chapter in nightlies has a bug! #25147

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

Closed
banks opened this issue May 6, 2015 · 1 comment
Closed

Comments

@banks
Copy link
Contributor

banks commented May 6, 2015

Just found the Learn chapter has appeared in nightlies.

While working through it the very first bit of code it gets me to run has a bug!

It is

use std::io;

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

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

    let mut guess = String::new();

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

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

note the last line we are printing input which is there return value of read_line (appears to be number of bytes read) and not the actual string guess which is what the chapter text implies.

Trivial fix...

Took me a while to find, but I figured out where the book source is and will submit PR despite it being one word change so far ;).

@banks
Copy link
Contributor Author

banks commented May 6, 2015

I guess I made my pull request from that commit badly, but it's #25148 I guess this should be closed if that is accepted.

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

1 participant