Skip to content

After saving a binary target related file, rust-analyzer reports 0 errors even though some errors remain #20651

@Riateche

Description

@Riateche

When I save a file that belongs to a binary target, e.g. main.rs or a module included from main.rs, the compiler errors for other targets disappear. Apparently in this case rust-analyzer runs cargo check and cargo clippy with -p ... --bin ... arguments, so the output is limited to the binary target that was modified. Any other compiler errors reported by a previous cargo check call are forgotten by rust-analyzer.

In contrast, when a file belonging to a library target is saved, rust-analyzer executes cargo check and cargo clippy with --workspace argument and without -p and --bin arguments, so the output contains errors from all targets.

I think the simplest fix for the issue would be to always run cargo check and cargo clippy with --workspace when the project is a workspace.

rust-analyzer version: 0.3.2593-standalone (6b2e677 2025-08-25) [.../.vscode/extensions/rust-lang.rust-analyzer-0.3.2593-darwin-arm64/server/rust-analyzer]

rustc version: 1.88.0

editor or extension: VSCode, rust-lang.rust-analyzer 0.3.2593

code snippet to reproduce:

new file mode 100644
index 0000000..c7d3639
--- /dev/null
+++ b/Cargo.toml
@@ -0,0 +1,3 @@
+[workspace]
+resolver = "2"
+members = ["lib1", "lib2", "bin3"]
diff --git a/bin3/Cargo.toml b/bin3/Cargo.toml
new file mode 100644
index 0000000..fcb7f21
--- /dev/null
+++ b/bin3/Cargo.toml
@@ -0,0 +1,7 @@
+[package]
+name = "lib3"
+version = "0.1.0"
+edition = "2024"
+
+[dependencies]
+lib1 = { path = "../lib1" }
diff --git a/bin3/src/main.rs b/bin3/src/main.rs
new file mode 100644
index 0000000..76343d1
--- /dev/null
+++ b/bin3/src/main.rs
@@ -0,0 +1,3 @@
+pub fn main() {
+    lib1::add(1, 1);
+}
diff --git a/lib1/Cargo.toml b/lib1/Cargo.toml
new file mode 100644
index 0000000..431002f
--- /dev/null
+++ b/lib1/Cargo.toml
@@ -0,0 +1,6 @@
+[package]
+name = "lib1"
+version = "0.1.0"
+edition = "2024"
+
+[dependencies]
diff --git a/lib1/src/lib.rs b/lib1/src/lib.rs
new file mode 100644
index 0000000..e118611
--- /dev/null
+++ b/lib1/src/lib.rs
@@ -0,0 +1,3 @@
+pub fn add(left: u64, right: u64) -> u64 {
+    left + right
+}
diff --git a/lib2/Cargo.toml b/lib2/Cargo.toml
new file mode 100644
index 0000000..4260b24
--- /dev/null
+++ b/lib2/Cargo.toml
@@ -0,0 +1,7 @@
+[package]
+name = "lib2"
+version = "0.1.0"
+edition = "2024"
+
+[dependencies]
+lib1 = { path = "../lib1" }
diff --git a/lib2/src/lib.rs b/lib2/src/lib.rs
new file mode 100644
index 0000000..b10983a
--- /dev/null
+++ b/lib2/src/lib.rs
@@ -0,0 +1,3 @@
+pub fn f2() -> u64 {
+    lib1::add(1, 1)
+}
diff --git a/src/main.rs b/src/main.rs
new file mode 100644
index 0000000..e7a11a9
--- /dev/null
+++ b/src/main.rs
@@ -0,0 +1,3 @@
+fn main() {
+    println!("Hello, world!");
+}

Steps to reproduce:

  1. mkdir dir; cd dir; patch --strip=1 < /tmp/1.patch
  2. Open directory as VSCode project.
  3. Change add to add1 in lib1/src/lib.rs. Rust-analyzer will show 2 errors: one in lib2/src/lib.rs and one in bin3/src/main.rs.
  4. Fix the error in the binary target by changing add to add1 in bin3/src/main.rs.

Expected behavior: 1 compiler error remains in lib2/src/lib.rs.

Actual behavior: rust-analyzer shows 0 compile errors. The error will only show after either lib1/src/lib.rs or lib2/src/lib.rs is edited and saved again, or after executing "Reload workspace" action in VSCode.

Metadata

Metadata

Assignees

Labels

A-diagnosticsdiagnostics / error reportingA-flycheckissues with flycheck a.k.a. "check on save"C-bugCategory: bug

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions