diff --git a/src/cargo/util/toml/mod.rs b/src/cargo/util/toml/mod.rs index e2232827885..179f50a053d 100644 --- a/src/cargo/util/toml/mod.rs +++ b/src/cargo/util/toml/mod.rs @@ -1235,25 +1235,36 @@ impl TomlManifest { } fn patch(&self, cx: &mut Context<'_, '_>) -> CargoResult>> { - let mut patch = HashMap::new(); - for (url, deps) in self.patch.iter().flat_map(|x| x) { - let url = match &url[..] { - CRATES_IO_REGISTRY => CRATES_IO_INDEX.parse().unwrap(), - _ => cx - .config - .get_registry_index(url) - .or_else(|_| url.into_url()) - .chain_err(|| { - format!("[patch] entry `{}` should be a URL or registry name", url) - })?, - }; - patch.insert( - url, - deps.iter() - .map(|(name, dep)| dep.to_dependency(name, cx, None)) - .collect::>>()?, - ); + fn process_patch(toml_patch: &Option>>, + cx: &mut Context<'_, '_>, + patch: &mut HashMap>) -> CargoResult<()> { + for (url, deps) in toml_patch.iter().flat_map(|x| x) { + let url = match &url[..] { + CRATES_IO_REGISTRY => CRATES_IO_INDEX.parse().unwrap(), + _ => cx + .config + .get_registry_index(url) + .or_else(|_| url.into_url()) + .chain_err(|| { + format!("[patch] entry `{}` should be a URL or registry name", url) + })?, + }; + patch.insert( + url, + deps.iter() + .map(|(name, dep)| dep.to_dependency(name, cx, None)) + .collect::>>()?, + ); + } + Ok(()) } + + let mut patch = HashMap::new(); + process_patch(&self.patch, cx, &mut patch)?; + + let config_patch: Option>> = cx.config.get("patch")?; + process_patch(&config_patch, cx, &mut patch)?; + Ok(patch) } diff --git a/tests/testsuite/patch.rs b/tests/testsuite/patch.rs index e3d699cc812..0a18a6a0c83 100644 --- a/tests/testsuite/patch.rs +++ b/tests/testsuite/patch.rs @@ -399,6 +399,48 @@ fn add_patch() { p.cargo("build").with_stderr("[FINISHED] [..]").run(); } +#[cargo_test] +fn patch_in_config() { + Package::new("bar", "0.1.0").publish(); + + let p = project() + .file( + "Cargo.toml", + r#" + [package] + name = "foo" + version = "0.0.1" + authors = [] + + [dependencies] + bar = "0.1.0" + "#, + ) + .file( + ".cargo/config", + r#" + [patch.crates-io] + bar = { path = 'bar' } + "# + ) + .file("src/lib.rs", "") + .file("bar/Cargo.toml", &basic_manifest("bar", "0.1.0")) + .file("bar/src/lib.rs", r#""#) + .build(); + + p.cargo("build") + .with_stderr( + "\ +[UPDATING] `[ROOT][..]` index +[COMPILING] bar v0.1.0 ([CWD]/bar) +[COMPILING] foo v0.0.1 ([CWD]) +[FINISHED] dev [unoptimized + debuginfo] target(s) in [..] +", + ) + .run(); + p.cargo("build").with_stderr("[FINISHED] [..]").run(); +} + #[cargo_test] fn add_ignored_patch() { Package::new("bar", "0.1.0").publish();