MS VS Code : "can't find crate" error

Hi, All!

I,m trying to run this simple program from MS VS Code (OS: Windows 10):

extern crate num;
use num::Complex;

fn main() {
    let z = Complex { re: 0.0, im: 0.0 };
    println!("Complex = {}", z);
}

Cargo.toml

[package]
name = "mandelbrot"
version = "0.1.0"
authors = ["U_M0TE7"]
edition = "2018"

[dependencies]
num = "0.2.1"

But... see this error:

error[E0463]: can't find crate for `num`
 --> main.rs:1:1
  |
1 | extern crate num;
  | ^^^^^^^^^^^^^^^^^ can't find crate

error: aborting due to previous error
For more information about this error, try `rustc --explain E0463`.

If I run it using console command "cargo run" from the project's folder, all works correct, without any errors.
How to solve it?
Thanks

  1. extern crate num; is not needed in the 2018 edition you are using. It doesn't hurt though.
  2. Try restarting rls or rust-analyzer. (whichever you are using) They both currently don't handle changes to Cargo.toml.

Thank you for your answer.
I restarted all several times...
Unfortunately it happens with all "extern crate xxx" which I was trying to compile in the Code.
If I use console command - all is ok!
May be there is a common problem related to MS VS Code configuration?

Hi all!

I've fond out that something wrong with Code Runner extension. It can't run rust code correctly. But the problem still not solved...
If i try to run the program using "cargo run" from VS Code's Terminal - all works correctly

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.