-
Notifications
You must be signed in to change notification settings - Fork 12.1k
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
Rust book : Guessing game doesn't build #34616
Comments
Trying to build the same with Nightly gives the following errors error: unresolved name `rand::thread_rng` [--explain E0425]
--> <anon>:9:25
|>
9 |> let secret_number = rand::thread_rng().gen_range(1, 101);
|> ^^^^^^^^^^^^^^^^
error: aborting due to previous error |
The playground doesn't have access to crates from crates.io, so normally you'd get an error about the crate not being found. This is know and expected, although it's of course not ideal. Unfortunately, there is a crate internally used by
However, apparently name resolution errors happen before stability is checked, which obscures the real reason why the program won't run on the playground. |
I'm getting the same error when I run cargo build. Does it build for you? |
Did you add
Edit: Yes, with that it does build for me. |
Yes i have. Can you tell me what's wrong with this project? |
rustc --version
rustc 1.9.0 (e4e8b6668 2016-05-18) |
That repo uses |
Thanks. That solves the issue. |
I have the same issue with rustc 1.15.0 (10893a9 2017-01-19) on Win10 x64 I have in Cargo.toml the section
replacing rand::thread_rng with rand::thread_ng removed one build error, but I'm still left with two more:
I also noticed that building with the rand="0.3.0" dependency in Cargo.toml, there was no download of the library nor any addition to Cargo.lock. What am I missing? |
@IngmarBitter are you sure you saved the toml file? That'd be my first guess. |
@steveklabnik thanks for making me double check that it was saved right. |
I have the same problem as mention above. I double checked my Cargo.toml rand = "0.6.0"` cargo does download the crate. I try to import the rand crate in "main.rs", as described in the tutorial, with The error of the compiler is, that it cannot resolve the import. This is the warning: I also tried to import a different crate, but I get the same error. Edit: This should be also updated in the book. |
You need rust 1.31, or to use extern crate.
… On Dec 16, 2018, at 12:45 AM, jon-ryan ***@***.***> wrote:
I have the same problem as mention above.
My rustc version: 1.30.1
cargo versoin: 1.30.0
I double checked my Cargo.toml
This are my dependencies:
`[dependencies]
rand = "0.6.0"`
cargo does download the crate.
I try to import the rand crate in "main.rs", as described in the tutorial, with use rand::Rng;
The error of the compiler is, that it cannot resolve the import. This is the warning:
error[E0432]: unresolved import rand
--> src/main.rs:3:5
|
3 | use rand::Rng;
| ^^^^ Maybe a missing extern crate rand;?
[...]`
I also tried to import a different crate, but I get the same error.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub, or mute the thread.
|
It's 2019; with a stock as-instructed installation on Ubuntu and following "the book", I get this when trying to use the random library: 7 | let secret_number = rand::thread_ng().gen_range(1,101); warning: unused import: error[E0433]: failed to resolve. Use of undeclared type or module warning: unused import: error: aborting due to 2 previous errors error: Could not compile Cargo config: As my first introduction this is not ideal....what is the remedy? Surely the documentation cannot be read with confidence if it fails me on trying to do something this basic? I am using rustc 1.25.0 (84203ca 2018-03-25) which was intalled with: curl https://sh.rustup.rs -sSf | sh as instructed....TIA |
I'm sorry you're running into this issue!
As I said above,
The book covers Rust 1.31+; you're using an older version. This means that you need to modify the code to include the line
at the top. The book covers the newer style of "Rust 2018", which your compiler doesn't support. |
@steveklabnik thanks! Updating only changed submodules error[E0599]: no method named error[E0599]: no method named error[E0599]: no method named error[E0599]: no method named error[E0277]: the size for values of type error[E0277]: the size for values of type error[E0277]: the size for values of type error[E0599]: no method named error[E0277]: the size for values of type error[E0277]: the size for values of type error[E0599]: no method named error[E0599]: no method named error[E0599]: no method named error[E0599]: no method named error[E0599]: no method named error[E0599]: no method named error[E0599]: no method named error[E0599]: no method named error[E0599]: no method named error[E0599]: no method named error[E0599]: no method named error[E0599]: no method named error[E0599]: no method named error[E0599]: no method named error[E0599]: no method named error[E0599]: no method named error[E0599]: no method named error[E0599]: no method named error[E0599]: no method named error[E0599]: no method named error[E0599]: no method named error[E0599]: no method named error[E0599]: no method named error[E0599]: no method named error[E0599]: no method named error[E0599]: no method named error[E0599]: no method named error[E0599]: no method named error[E0599]: no method named error[E0599]: no method named error[E0599]: no method named error[E0599]: no method named error[E0599]: no method named error[E0599]: no method named error[E0599]: no method named error[E0599]: no method named error[E0599]: no method named error[E0599]: no method named error[E0599]: no method named error[E0599]: no method named error[E0599]: no method named error[E0599]: no method named error[E0599]: no method named error[E0599]: no method named error[E0599]: no method named error[E0599]: no method named error[E0599]: no method named error[E0599]: no method named error[E0599]: no method named error[E0599]: no method named error[E0599]: no method named error[E0599]: no method named error[E0599]: no method named error[E0599]: no method named error[E0599]: no method named error[E0599]: no method named error[E0599]: no method named error[E0599]: no method named error[E0599]: no method named error[E0599]: no method named error[E0599]: no method named error[E0599]: no method named error[E0599]: no method named error[E0599]: no method named error[E0599]: no method named error[E0599]: no method named warning: unused import: error: aborting due to 77 previous errors Some errors have detailed explanations: E0277, E0599. To learn more, run the command again with --verbose. |
This build log looks like you're building Rust itself? manually? |
Steve, correct.
Although I subsequently gave up and just installed "rustup" then upgraded
to 1.38.0 and everything is fine. I *like* building stuff from sources
(Smalltalk habit I guess) but I am mor einto learning Rust so I gave in on
this occasion!
Loving it so far...it feels like the thing that "D" should have been, it
feels like Haskell without the maths torture, it feels like C++ without
typing everything twice, it is in short AMAZING and I think apart from Lisp
and Prolog, Rust is now the third weapon in my arsenal for all time.
:)
Nice
…On Sat, 19 Oct 2019 at 02:00, Steve Klabnik ***@***.***> wrote:
This build log looks like you're building Rust itself? manually?
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#34616?email_source=notifications&email_token=AAGHNRN2MLRRQEBPRY2UAZ3QPJL3BA5CNFSM4CIOY5E2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEBWUJUQ#issuecomment-544031954>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAGHNRKCAMX4QEI7C35C6UTQPJL3BANCNFSM4CIOY5EQ>
.
|
It doesn't build for me with the latest version of Rust either (1.56.0):
|
in Cargo.toml: Rebuild project! |
I had that line already. I also tried multiple older versions and still got the same error. I wonder if it's because I'm running macOS Mojave (10.14) and can't upgrade yet for unrelated reasons. Anyway, I seem to be able to compile other rust code, so I guess it's not a blocker for me personally. It says I have current versions though...
|
When i try the program in rust playground it shows the following errors
The text was updated successfully, but these errors were encountered: