Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Setting workspace = true in patch.crates-io causes panic #11523

Closed
Aphoh opened this issue Dec 29, 2022 · 1 comment · Fixed by #11565
Closed

Setting workspace = true in patch.crates-io causes panic #11523

Aphoh opened this issue Dec 29, 2022 · 1 comment · Fixed by #11565
Labels
A-patch Area: [patch] table override A-workspace-inheritance Area: workspace inheritance RFC 2906 C-bug Category: bug

Comments

@Aphoh
Copy link

Aphoh commented Dec 29, 2022

Problem

I was trying to take some shortcuts in pinning dependency versions for a project by setting workspace.dependencies and then patching each crate to read from the workspace by setting workspace = true. Repro here. Causes this panic on the latest nightly:

thread 'main' panicked at 'internal error: entered unreachable code', src/tools/cargo/src/cargo/util/toml/mod.rs:2509:45
stack backtrace:
   0: _rust_begin_unwind
   1: core::panicking::panic_fmt
   2: core::panicking::panic
   3: <cargo::util::toml::TomlDependency>::to_dependency
   4: <core::iter::adapters::map::Map<alloc::collections::btree::map::Iter<alloc::string::String, cargo::util::toml::TomlDependency>, <cargo::util::toml::TomlManifest>::patch::{closure#2}> as core::iter::traits::iterator::Iterator>::try_fold::<(), <core::iter::adapters::GenericShunt<core::iter::adapters::map::Map<alloc::collections::btree::map::Iter<alloc::string::String, cargo::util::toml::TomlDependency>, <cargo::util::toml::TomlManifest>::patch::{closure#2}>, core::result::Result<core::convert::Infallible, anyhow::Error>> as core::iter::traits::iterator::Iterator>::try_fold<(), core::iter::traits::iterator::Iterator::try_for_each::call<cargo::core::dependency::Dependency, core::ops::control_flow::ControlFlow<cargo::core::dependency::Dependency>, core::ops::control_flow::ControlFlow<cargo::core::dependency::Dependency>::Break>::{closure#0}, core::ops::control_flow::ControlFlow<cargo::core::dependency::Dependency>>::{closure#0}, core::ops::control_flow::ControlFlow<core::ops::control_flow::ControlFlow<cargo::core::dependency::Dependency>>>
   5: <alloc::vec::Vec<cargo::core::dependency::Dependency> as alloc::vec::spec_from_iter::SpecFromIter<cargo::core::dependency::Dependency, core::iter::adapters::GenericShunt<core::iter::adapters::map::Map<alloc::collections::btree::map::Iter<alloc::string::String, cargo::util::toml::TomlDependency>, <cargo::util::toml::TomlManifest>::patch::{closure#2}>, core::result::Result<core::convert::Infallible, anyhow::Error>>>>::from_iter
   6: core::iter::adapters::try_process::<core::iter::adapters::map::Map<alloc::collections::btree::map::Iter<alloc::string::String, cargo::util::toml::TomlDependency>, <cargo::util::toml::TomlManifest>::patch::{closure#2}>, cargo::core::dependency::Dependency, core::result::Result<core::convert::Infallible, anyhow::Error>, <core::result::Result<alloc::vec::Vec<cargo::core::dependency::Dependency>, anyhow::Error> as core::iter::traits::collect::FromIterator<core::result::Result<cargo::core::dependency::Dependency, anyhow::Error>>>::from_iter<core::iter::adapters::map::Map<alloc::collections::btree::map::Iter<alloc::string::String, cargo::util::toml::TomlDependency>, <cargo::util::toml::TomlManifest>::patch::{closure#2}>>::{closure#0}, alloc::vec::Vec<cargo::core::dependency::Dependency>>
   7: <cargo::util::toml::TomlManifest>::patch
   8: cargo::util::toml::read_manifest_from_str
   9: cargo::util::toml::read_manifest
  10: <cargo::core::workspace::Packages>::load
  11: <cargo::core::workspace::Workspace>::find_root
  12: <cargo::core::workspace::Workspace>::new
  13: <clap::parser::matches::arg_matches::ArgMatches as cargo::util::command_prelude::ArgMatchesExt>::workspace
  14: cargo::commands::test::exec
  15: cargo::cli::main
  16: cargo::main

Steps

  1. Take any project and put a.workspace = true in the [patch.crates-io]

Possible Solution(s)

Just throw an error saying this is unsupported? It might be useful if it was supported though.

Notes

No response

Version

cargo 1.68.0-nightly (2381cbdb4 2022-12-23)
release: 1.68.0-nightly
commit-hash: 2381cbdb4e9b07090f552d34a44a529b6e620e44
commit-date: 2022-12-23
host: aarch64-apple-darwin
libgit2: 1.5.0 (sys:0.15.0 vendored)
libcurl: 7.84.0 (sys:0.4.59+curl-7.86.0 system ssl:(SecureTransport) LibreSSL/3.3.6)
os: Mac OS 13.0.1 [64-bit]
@Aphoh Aphoh added the C-bug Category: bug label Dec 29, 2022
@weihanglo weihanglo added A-patch Area: [patch] table override A-workspace-inheritance Area: workspace inheritance RFC 2906 labels Dec 30, 2022
@Muscraft
Copy link
Member

Muscraft commented Jan 3, 2023

Using dependencies from [workspace.dependencies] for [patch] was never supposed to be supported. The problem comes from adding Workspace to TomlDependency. This made it so that anything that had the type TomlDependency could inherit from [workspace.dependencies] i.e. [patch] and [replace].

It was an oversight on my part during implementation. Work on #11409 actually brought this to my attention, and I was hoping no one would run into it before I had time to fix it. I need to get #11409 merged before a fix for this can be implemented. I have a general idea of what needs to happen after #11409, so hopefully, it won't be too long to fix this issue.

All of that being said can you expand on what you are trying to do and what using [workspace.dependencies] and [patch] solves?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-patch Area: [patch] table override A-workspace-inheritance Area: workspace inheritance RFC 2906 C-bug Category: bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants