Skip to content

cargo-script: error when dependent library uses package.*.workspace inheritance #16995

@kleinesfilmroellchen

Description

@kleinesfilmroellchen

Problem

If a cargo-script has a dependency on a local package that is located within a workspace, and that package inherits some package keys using the *.workspace = true mechanism, Cargo will not detect that the package is in its workspace correctly, and will claim that “workspace.* was not defined”.

Steps

Roughly minimal reproducer:

Top-level Cargo.toml:

[workspace]
members = ["dependency-lib"]

[workspace.package]
# could be any key(s) that are allowed here
edition = "2024"

dependency-lib/Cargo.toml:

[package]
name = "dependency-lib"
version = "0.1.0"
# !!!!!
edition.workspace = true

touch dependency-lib/src/lib.rs so that it’s a valid library.

Now create a script somewhere in the dependency tree (tested at top-level as well as in dependency-lib, which will need changes to the path):

#!/usr/bin/env -S cargo +nightly -Zscript
---
[dependencies]
# in this case the script is located within the "dependency-lib" directory
dependency-lib = { path = "." }
---
fn main() {}

Possible Solution(s)

For now, I’m using a separate bin package, which defeats some of the purpose of cargo-script.

Notes

Full output when running the script:

warning: `package.edition` is unspecified, defaulting to the latest edition (currently `2024`)
help: to pin the edition, run `cargo fix --manifest-path […]/script.rs`
error: failed to get `dependency-lib` as a dependency of package `script v0.0.0 ([…]/script.rs)`

Caused by:
  failed to load source for dependency `dependency-lib`

Caused by:
  unable to update […]/dependency-lib

Caused by:
  failed to parse manifest at `[…]/dependency-lib/Cargo.toml`

Caused by:
  error inheriting `edition` from workspace root manifest's `workspace.package.edition`

Caused by:
  `workspace.package.edition` was not defined

Version

cargo 1.97.0-nightly (a343accce 2026-05-08)
release: 1.97.0-nightly
commit-hash: a343accce8526b128adc517d33348573d22920a3
commit-date: 2026-05-08
host: x86_64-unknown-linux-gnu
libgit2: 1.9.2 (sys:0.20.4 vendored)
libcurl: 8.20.0-DEV (sys:0.4.88+curl-8.20.0 vendored ssl:OpenSSL/3.6.2)
ssl: OpenSSL 3.6.2 7 Apr 2026
os: Arch Linux Rolling Release [64-bit]

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-workspace-inheritanceArea: workspace inheritance RFC 2906C-bugCategory: bugS-triageStatus: This issue is waiting on initial triage.Z-scriptNightly: cargo script

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions