rust-lang / rust-analyzer

A Rust compiler front-end for IDEs
https://rust-analyzer.github.io/
Apache License 2.0
14.02k stars 1.55k forks source link

Unresolved import error for crate after adding lib.rs #11604

Open swanandx opened 2 years ago

swanandx commented 2 years ago

I have a lib.rs file, which has the pub async fn run() function, but when I try to import it, rust-analyzer shows unresolved import error. But it doesn't show any errors in cargo check / clippy , and it also builds successfully!

image

Here is my Cargo.toml file:

[package]
name = "zero2prod"
version = "0.1.0"
..

[lib]
path = "src/lib.rs"

[[bin]]
path = "src/main.rs"
name = "zero2prod"

[dependencies]
..

rust-analyzer version: 4e72700e3 2022-02-28 stable

rustc version: rustc 1.59.0 (9d1b2106e 2022-02-23)

swanandx commented 2 years ago

Complete restart of VSCode solved the unresolved import error, but it should have worked without needing to restart/reload it as soon as I added the [lib] in Cargo.toml right?

kherldhussein commented 1 year ago

Hi @swanandx,

I've been experiencing a similar "Unresolved import" error after adding lib.rs to my project. I came across an interesting Stack Overflow article that provided some insights on how to resolve this issue.