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: Paragraph now superfluous in Rust 2018? #1662

Closed
frankhecker opened this issue Dec 7, 2018 · 4 comments
Closed

Guessing Game: Paragraph now superfluous in Rust 2018? #1662

frankhecker opened this issue Dec 7, 2018 · 4 comments

Comments

@frankhecker
Copy link

In the Rust 2018 edition discussion of the guessing game, there are two paragraphs as follows:

First, we add a line that lets Rust know we’ll be using the rand crate as an external
dependency. This also does the equivalent of calling use rand, so now we can call
anything in the rand crate by placing rand:: before it.

Next, we add another use line: use rand::Rng. ...

I'm guessing that the first paragraph is no longer needed, because Rust 2018 doesn't need the "extern crate" statement (or whatever it is).

@Shanks512
Copy link

The associated code snippet (Listing 2-3) however, does not compile with the latest stable rustc/crate version 1.31.0 because of the missing extern statement ("extern crate rand;").

@frankhecker
Copy link
Author

The code snippet compiles fine for me. But I'm guessing that's because I'm a Rust n00b, installed rustc 1.31.0 as my initial installation of Rust, and have a line 'edition = "2018"' automatically included in my Cargo.toml file when I do "cargo new". If I remove that line or change 2018 to 2015 then I get the same behavior as you, i.e., a compilation error referencing a missing "extern crate rand;" statement.

My assumption is that the current online version of the Rust docs is intended to be for Rust 2018 users. If that's the case, then for those users the code snippet can and arguably should leave out the "extern crate" statement, the paragraph that (indirectly) references that statement should be removed, and the following paragraph rewritten slightly.

@Shanks512
Copy link

Ah, that explains it. I had created the 'guessing_game' project a few months back using an older version of cargo, and hence the 'edition' property was missing from the toml. Encountered this error when revisiting the project to brush up the basics :)

The project compiles fine after adding 'edition = "2018"'. Maybe the doc authors can also update the Filename: Cargo.toml code snippet with the 'edition' property to avoid confusion?

@dralley
Copy link
Contributor

dralley commented Dec 9, 2018

@Shanks512 This should be fixed in the newest version of the docs

#1671

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