Skip to content

Instantly share code, notes, and snippets.

@deepak
Last active April 13, 2016 12:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save deepak/9cc8e0ac7c8a833a9231b7e53a9b6b05 to your computer and use it in GitHub Desktop.
Save deepak/9cc8e0ac7c8a833a9231b7e53a9b6b05 to your computer and use it in GitHub Desktop.
error in using rust's rand crate
[root]
name = "hello_world"
version = "0.0.1"
dependencies = [
"rand 0.3.14 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "libc"
version = "0.2.10"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "rand"
version = "0.3.14"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"libc 0.2.10 (registry+https://github.com/rust-lang/crates.io-index)",
]
[package]
name = "hello_world"
version = "0.0.1"
authors = [ "Deepak Kannan <kannan.deepak@gmail.com>" ]
[dependencies]
rand = "0.3.14"
extern crate rand;
use std::io;
use rand::Rng;
fn main() {
println!("Guess the number!");
let secret_number = rand::thread_rng().gen_range(1, 101);
println!("The secret number is: {}", secret_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);
}
# why does `rustc` throw a error
# but cargo build and run works
# using `rust-mode` in emacs and it flags the same error as `rustc`
$ rustc src/main.rs
src/main.rs:9:25: 9:41 error: unresolved name `rand::thread_rng` [E0425]
src/main.rs:9 let secret_number = rand::thread_rng().gen_range(1, 101);
^~~~~~~~~~~~~~~~
src/main.rs:9:25: 9:41 help: run `rustc --explain E0425` to see a detailed explanation
error: aborting due to previous error
$ cargo build
Compiling hello_world v0.0.1 (file:///Users/deepak/Code/ScratchPad/hello-rust)
$ cargo run
Running `target/debug/hello_world`
Guess the number!
The secret number is: 2
Please input your guess.
1
You guessed: 1
$ rustc --explain E0425
An unresolved name was used. Example of erroneous codes:
```
something_that_doesnt_exist::foo;
// error: unresolved name `something_that_doesnt_exist::foo`
// or:
trait Foo {
fn bar() {
Self; // error: unresolved name `Self`
}
}
// or:
let x = unknown_variable; // error: unresolved name `unknown_variable`
```
Please verify that the name wasn't misspelled and ensure that the
identifier being referred to is valid for the given situation. Example:
```
enum something_that_does_exist {
foo
}
// or:
mod something_that_does_exist {
pub static foo : i32 = 0i32;
}
something_that_does_exist::foo; // ok!
// or:
let unknown_variable = 12u32;
let x = unknown_variable; // ok!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment