Skip to content

Cargo add reaches unreachable code when workspace root contains cratename.workspace = true #16061

@Chiffario

Description

@Chiffario

Problem

When accidentally specifying a workspace-level dependency as cratename.workspace = true and then trying to add it to a workspace-crate via cargo add cratename, instead of producing a proper error message cargo add panics

Steps

  1. Create a workspace
  2. In workspace's root, add a [workspace.dependencies] block
  3. Add apply.workspace = true to that block (or any other crate)
  4. Create a workspace crate (for example, cargo new testing)
  5. Change directory to the crate's root (cd ./testing)
  6. Use cargo add apply (or a different previously specified crate) from crate's root

On step 6, cargo add panics with the following

thread 'main' panicked at src/tools/cargo/src/cargo/ops/cargo_add/mod.rs:519:21:
internal error: entered unreachable code: This should have been caught when parsing a workspace root
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

Possible Solution(s)

Adding a proper error message could be nice, as this is a type of error one can make while copypasting Cargo.toml when moving stuff around/creating a workspace

Notes

No response

Version

cargo 1.90.0 (840b83a10 2025-07-30)
release: 1.90.0
commit-hash: 840b83a10fb0e039a83f4d70ad032892c287570a
commit-date: 2025-07-30
host: x86_64-unknown-linux-gnu
libgit2: 1.9.1 (sys:0.20.2 vendored)
libcurl: 8.14.1-DEV (sys:0.4.82+curl-8.14.1 vendored ssl:OpenSSL/3.5.0)
ssl: OpenSSL 3.5.0 8 Apr 2025
os: Arch Linux Rolling Release [64-bit]

Metadata

Metadata

Assignees

Labels

C-bugCategory: bugCommand-addS-acceptedStatus: Issue or feature is accepted, and has a team member available to help mentor or review

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions