Skip to content

Commit fdcc73f

Browse files
committed
Auto merge of #7452 - pyrrho:bug7346/transitive_patches, r=Eh2406
Bug7346/transitive patches Fixes #7346. A cursory comparison between current stable and nightly shows that projects with this topology resolve similarly. If there are other behaviors I should test, I'd be happy to expand that section. This is a pretty focused change, though, so I'm not sure what else there is to break. Sorry about the delay in putting this PR together. Good news is I know more than I did last week.
2 parents d096a86 + f7bfd9d commit fdcc73f

File tree

2 files changed

+75
-13
lines changed

2 files changed

+75
-13
lines changed

src/cargo/core/resolver/context.rs

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,16 @@ use std::collections::HashMap;
22
use std::num::NonZeroU64;
33
use std::rc::Rc;
44

5-
// "ensure" seems to require "bail" be in scope (macro hygiene issue?).
6-
#[allow(unused_imports)]
7-
use failure::{bail, ensure};
5+
use failure::format_err;
86
use log::debug;
97

108
use crate::core::interning::InternedString;
119
use crate::core::{Dependency, PackageId, SourceId, Summary};
12-
use crate::util::CargoResult;
1310
use crate::util::Graph;
1411

1512
use super::dep_cache::RegistryQueryer;
16-
use super::types::{ConflictMap, FeaturesSet, ResolveOpts};
13+
use super::errors::ActivateResult;
14+
use super::types::{ConflictMap, ConflictReason, FeaturesSet, ResolveOpts};
1715

1816
pub use super::encode::Metadata;
1917
pub use super::encode::{EncodableDependency, EncodablePackageId, EncodableResolve};
@@ -109,7 +107,7 @@ impl Context {
109107
summary: &Summary,
110108
opts: &ResolveOpts,
111109
parent: Option<(&Summary, &Dependency)>,
112-
) -> CargoResult<bool> {
110+
) -> ActivateResult<bool> {
113111
let id = summary.package_id();
114112
let age: ContextAge = self.age();
115113
match self.activations.entry(id.as_activations_key()) {
@@ -122,12 +120,15 @@ impl Context {
122120
}
123121
im_rc::hashmap::Entry::Vacant(v) => {
124122
if let Some(link) = summary.links() {
125-
ensure!(
126-
self.links.insert(link, id).is_none(),
127-
"Attempting to resolve a dependency with more then one crate with the \
128-
links={}.\nThis will not build as is. Consider rebuilding the .lock file.",
129-
&*link
130-
);
123+
if self.links.insert(link, id).is_some() {
124+
return Err(format_err!(
125+
"Attempting to resolve a dependency with more then \
126+
one crate with links={}.\nThis will not build as \
127+
is. Consider rebuilding the .lock file.",
128+
&*link
129+
)
130+
.into());
131+
}
131132
}
132133
v.insert((summary.clone(), age));
133134

@@ -150,7 +151,11 @@ impl Context {
150151
if dep.source_id() != id.source_id() {
151152
let key = (id.name(), dep.source_id(), id.version().into());
152153
let prev = self.activations.insert(key, (summary.clone(), age));
153-
assert!(prev.is_none());
154+
if let Some((previous_summary, _)) = prev {
155+
return Err(
156+
(previous_summary.package_id(), ConflictReason::Semver).into()
157+
);
158+
}
154159
}
155160
}
156161

tests/testsuite/patch.rs

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -735,6 +735,63 @@ fn transitive_new_major() {
735735
.run();
736736
}
737737

738+
#[cargo_test]
739+
fn shared_by_transitive() {
740+
Package::new("baz", "0.1.1").publish();
741+
742+
let baz = git::repo(&paths::root().join("override"))
743+
.file("Cargo.toml", &basic_manifest("baz", "0.1.2"))
744+
.file("src/lib.rs", "")
745+
.build();
746+
747+
let p = project()
748+
.file(
749+
"Cargo.toml",
750+
&format!(
751+
r#"
752+
[package]
753+
name = "foo"
754+
version = " 0.1.0"
755+
756+
[dependencies]
757+
bar = {{ path = "bar" }}
758+
baz = "0.1"
759+
760+
[patch.crates-io]
761+
baz = {{ git = "{}", version = "0.1" }}
762+
"#,
763+
baz.url(),
764+
),
765+
)
766+
.file("src/lib.rs", "")
767+
.file(
768+
"bar/Cargo.toml",
769+
r#"
770+
[package]
771+
name = "bar"
772+
version = "0.1.0"
773+
774+
[dependencies]
775+
baz = "0.1.1"
776+
"#,
777+
)
778+
.file("bar/src/lib.rs", "")
779+
.build();
780+
781+
p.cargo("build")
782+
.with_stderr(
783+
"\
784+
[UPDATING] git repository `file://[..]`
785+
[UPDATING] `[ROOT][..]` index
786+
[COMPILING] baz v0.1.2 [..]
787+
[COMPILING] bar v0.1.0 [..]
788+
[COMPILING] foo v0.1.0 ([CWD])
789+
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
790+
",
791+
)
792+
.run();
793+
}
794+
738795
#[cargo_test]
739796
fn remove_patch() {
740797
Package::new("foo", "0.1.0").publish();

0 commit comments

Comments
 (0)