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

Listing 12-14: use minigrep; instead of extern crate minigrep; results in error #1676

Closed
jvivian opened this issue Dec 9, 2018 · 7 comments

Comments

@jvivian
Copy link

jvivian commented Dec 9, 2018

I'm following the current live version of the Rust book (master on Github) and encountered the following issue:

Listing 12-14 states to use use minigrep; "... to bring the library crate into the binary crate". Yet when I do that I get the following compile errors when calling cargo run:

error[E0432]: unresolved import `minigrep`                                                                                                                                
 --> src/main.rs:2:5                                                                                                                                                      
  |                                                                                                                                                                       
2 | use minigrep;                                                                                                                                                         
  |     ^^^^^^^^ no `minigrep` in the root                                                                                                                                
                                                                                                                                                                          
error[E0433]: failed to resolve. Use of undeclared type or module `Config`                                                                                                
  --> src/main.rs:11:18                                                                                                                                                   
   |                                                                                                                                                                      
11 |     let config = Config::new(&args).unwrap_or_else(|err| {                                                                                                           
   |                  ^^^^^^ Use of undeclared type or module `Config`    

If I change use minigrep; to extern crate minigrep; the problem goes away.

I'd be happy to open a pull request if this is a legitimate bug.

@anuj1102
Copy link

I'm running into the same issue as well, and the fix above worked for me.

@carols10cents
Copy link
Member

@jvivian and @anuj1102 Do you have edition="2018" in your Cargo.toml and are you using Rust 1.31.0? The current version of the book assumes 2018 Edition Rust.

@jvivian
Copy link
Author

jvivian commented Dec 10, 2018

Hi @carols10cents,

Thank you for the reply — I see now that the book is in lockstep with the latest release of Rust and the version I installed last week (1.30.1) doesn't include the edition="2018" in Cargo.toml. I updated via rustup update and added edition = "2018" which resolved my issue. Thank you very much! I'll go ahead and close this.

@jvivian jvivian closed this as completed Dec 10, 2018
@carols10cents
Copy link
Member

carols10cents commented Dec 10, 2018 via email

@taiprogramer
Copy link

I try to re-create project with --lib (cargo new minigrep --lib), react new main.rs file and copy everything. Now, It's work.
Hope this useful to other!

@TylerBrock
Copy link

In case anyone else stumbles upon this in the future the correct answer is actually to run cargo clean. I found that I had edition = "2018" but the incremental build process gets confused when you move the code from main.rs to lib.rs so you need to clear them out.

@gitgitcode
Copy link

in my case version is
cargo 1.60.0 (d1fd9fe2c 2022-03-01)
rustc 1.60.0 (7737e0b5c 2022-04-04)
i just edit once to edition = "2018" it's solved.
then turn back to edition = "2021" it's ok.
at last i also run cargo clean

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

6 participants