I've started learning Rust and am following this guide: docs, but encountered this error at this step:
Before I added this code to my Cargo.toml, everything was fine:
[dependencies]
rand = "0.8.5"
But after adding this line, I encountered an error:
~/g/rust-by-example/02/guessing_game main ❯ cargo build
warning: `/Users/smallyu/.cargo/config` is deprecated in favor of `config.toml`
note: if you need to support cargo 1.38 or earlier, you can symlink `config` to `config.toml`
warning: `/Users/smallyu/.cargo/config` is deprecated in favor of `config.toml`
note: if you need to support cargo 1.38 or earlier, you can symlink `config` to `config.toml`
Compiling proc-macro2 v1.0.86
error[E0433]: failed to resolve: use of undeclared crate or module `average_block_sizeproc_macro`
--> /Users/smallyu/.cargo/registry/src/index.crates.io-6f17d22bba15001f/proc-macro2-1.0.86/src/wrapper.rs:871:21
|
871 | average_block_sizeproc_macro::Literal::byte_character(byte)
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ use of undeclared crate or module `average_block_sizeproc_macro`
|
help: consider importing one of these structs
|
1 + use crate::Literal;
|
1 + use crate::fallback::Literal;
|
1 + use proc_macro::Literal;
|
help: if you import `Literal`, refer to it directly
|
871 - average_block_sizeproc_macro::Literal::byte_character(byte)
871 + Literal::byte_character(byte)
|
For more information about this error, try `rustc --explain E0433`.
error: could not compile `proc-macro2` (lib) due to 1 previous error
I'm on macOS, and the Rust version is:
~/g/rust-by-example/02/guessing_game main ❯ cargo --version smallyunet
warning: `/Users/smallyu/.cargo/config` is deprecated in favor of `config.toml`
note: if you need to support cargo 1.38 or earlier, you can symlink `config` to `config.toml`
warning: `/Users/smallyu/.cargo/config` is deprecated in favor of `config.toml`
note: if you need to support cargo 1.38 or earlier, you can symlink `config` to `config.toml`
cargo 1.82.0-nightly (0d8d22f83 2024-08-08)
~/g/rust-by-example/02/guessing_game main ❯ rustc --version smallyunet
rustc 1.82.0-nightly (91376f416 2024-08-12)
My full 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)
.expect("Failed to read line");
println!("You guessed: {}", guess);
}
[package]
name = "guessing_game"
version = "0.1.0"
edition = "2021"
[dependencies]
rand = "0.8.5"