/errors/cargo/believes-its-in-a-workspace
Cargo: error: current package believes it's in a workspace when it's not
verified onenvironmentlocal · windows 10.0.26200 arm64 · GNU bash 5.3.15 (Git Bash) · cargo 1.98.1 (797e8a9bc 2026-08-05)updated
- tool
- Cargo
- exit code
- 101
- versions
- Rust 1.x
- os
- any
error: current package believes it's in a workspace when it's not means Cargo found a Cargo.toml with a [workspace] section in a parent folder, but the current package is not one of its members. Cargo then does not know which workspace (and which Cargo.lock and target/) to use. Cargo prints both manifest paths and suggests the fix: add the package to workspace.members, add it to workspace.exclude, or give the package its own empty [workspace] table.
Reproduce it
cat > Cargo.toml <<'EOF'
[workspace]
members = []
EOF
mkdir -p tool/src
cat > tool/Cargo.toml <<'EOF'
[package]
name = "tool"
version = "0.1.0"
edition = "2021"
EOF
echo 'fn main() { println!("hi"); }' > tool/src/main.rs
cd tool
cargo buildOutput · exit 101
error: current package believes it's in a workspace when it's not: current: /tmp/work/tool/Cargo.toml workspace: /tmp/work/Cargo.toml this may be fixable by adding `tool` to the `workspace.members` array of the manifest located at: /tmp/work/Cargo.toml Alternatively, to keep it out of the workspace, add the package to the `workspace.exclude` array, or add an empty `[workspace]` table to the package's manifest.
Fix
Add the package to the workspace members (or use a glob such as "crates/*"):
cat > Cargo.toml <<'EOF'
[workspace]
members = ["tool"]
resolver = "2"
EOF
mkdir -p tool/src
cat > tool/Cargo.toml <<'EOF'
[package]
name = "tool"
version = "0.1.0"
edition = "2021"
EOF
echo 'fn main() { println!("hi"); }' > tool/src/main.rs
cd tool
cargo run -qOutput
hi
| Goal | Change |
|---|---|
| The crate is part of the workspace | members = ["tool"] in the parent [workspace] |
| The crate is unrelated to the parent project | exclude = ["tool"] in the parent [workspace] |
| Keep the parent unchanged | Add an empty [workspace] table to tool/Cargo.toml |
Inside a workspace, all members share one Cargo.lock and one target/ folder at the workspace root.
Sources
Related pages
errors · cargoerror: could not find `Cargo.toml` in `...` or any parent directorycargo reports could not find Cargo.toml when run outside a Rust package. cd into the project, pass --manifest-path, or create a package with cargo new.errors · cargoerror: a bin target must be available for `cargo run`cargo run fails with a bin target must be available when the package is a library with no src/main.rs. Add a binary, run an example, or use cargo test instead.commands · cargocargo add serde --features derive: add a dependency with featurescargo add NAME --features F adds a crate to Cargo.toml with chosen features (Cargo 1.62+). Pin versions, dev and build deps, default features, and cargo remove.