Skip to content

ch2: unused result warning differs #1006

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
wants to merge 1 commit into from
Closed

ch2: unused result warning differs #1006

wants to merge 1 commit into from

Conversation

nathany
Copy link

@nathany nathany commented Nov 18, 2017

When running cargo build with rust 1.21.0 (rustc 1.18.0), the warning appears as:

warning: unused result which must be used

rather than

unused `std::result::Result` which must be used

@nathany
Copy link
Author

nathany commented Nov 18, 2017

I'm seeing other differences in compiler errors later on. Not sure if I'm using an old rustc release compared to the book or if the book is out-of-date.

variables/main.rs

re-assignment of immutable variable `x`

rather than

cannot assign twice to immutable variable `x`

@steveklabnik
Copy link
Member

The book is out of date; for your second example, that error actually changed due to the book!

I believe @carols10cents and I were going to go over all of the error messages at the very end and make sure they're up to date, but I also don't see the harm in merging this right now. Carol, whatcha think?

@carols10cents
Copy link
Member

rust 1.21.0 (rustc 1.18.0)

I'm confused about this part? What do you mean by this? The version of Rust that you're using should be exactly what rustc --version prints out....

@carols10cents
Copy link
Member

Aside from that, the book's error messages are out of date and I'm slowly updating them to be the ones generated by rustc 1.21.0. I thought I did chapter 2 recently, checking...

@carols10cents
Copy link
Member

Ok yeah I updated this recently with rustc 1.21.0.

When I run this code:

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);

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

I get this output:

$ cargo run
   Compiling guessing_game v0.1.0 (file:///Users/carolnichols/rust/guessing_game)
warning: unused `std::result::Result` which must be used
  --> src/main.rs:10:5
   |
10 |     io::stdin().read_line(&mut guess);
   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   |
   = note: #[warn(unused_must_use)] on by default

    Finished dev [unoptimized + debuginfo] target(s) in 0.36 secs
     Running `target/debug/guessing_game`
Guess the number!
Please input your guess.

and that's what we're going for in the book.

We're going to have a notice in Chapter 1 (we're revising that chapter last) that we've used Rust 1.21.0 for all the examples in the book and that the exact output you see might be slightly different, but everything that compiles in the book should continue to compile with future versions (and since we've been working on this book for a while, with past versions even though that's not a guarantee of Rust's per se).

Please let us know if you need any help getting the right Rust version, I'm still confused about what you mean by "rust 1.21.0 (rustc 1.18.0)" but if there's an upgrading problem we can help fix we'd be happy to help!

@nathany
Copy link
Author

nathany commented Nov 21, 2017

thanks @carols10cents and @steveklabnik

I'm confused by the version mismatch too. If it's not an expected situation, then there's probably something wrong with the setup on my Mac.

❯ brew list | grep rust 
rust

❯ brew info rust
rust: stable 1.21.0 (bottled), HEAD

❯ which rustc
/Users/nathany/.cargo/bin/rustc
                                                                                
❯ rustc --version
rustc 1.18.0 (03fc9d622 2017-06-06)

Maybe I should try uninstalling Rust entirely and reinstalling from scratch.

@nathany nathany deleted the unused-result branch November 21, 2017 15:55
@carols10cents
Copy link
Member

Yeah I highly recommend using rustup rather than homebrew for managing Rust versions. I know, I know, it's another tool, but rustup Just Works for me and manages a lot of other aspects of your Rust dev setup.

@steveklabnik
Copy link
Member

It sounds to me like you have both brew and rustup trying to manage a rust, and they're getting crossed.

@nathany
Copy link
Author

nathany commented Nov 21, 2017

@steveklabnik Yup, that appears to be the case, with rustup taking precedence over Homebrew, so I was using an older version than I thought.

@carols10cents Thanks for pointing out the issue and encouraging me to switch to just rustup. Appreciate it! Also thanks for caring about the small details, like the error messages shown in the book.

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

Successfully merging this pull request may close these issues.

3 participants