Skip to content

Commit e6992d4

Browse files
committed
-- renamed deduplicate_workspace to inheritable_workspace_fields
-- removed `[]` from error messages in favor of back-ticks
1 parent c4cd152 commit e6992d4

File tree

4 files changed

+42
-33
lines changed

4 files changed

+42
-33
lines changed

src/cargo/core/workspace.rs

+17-17
Original file line numberDiff line numberDiff line change
@@ -1714,18 +1714,18 @@ impl InheritableFields {
17141714

17151715
pub fn dependencies(&self) -> CargoResult<BTreeMap<String, TomlDependency>> {
17161716
self.dependencies.clone().map_or(
1717-
Err(anyhow!("[workspace.dependencies] was not defined")),
1717+
Err(anyhow!("`workspace.dependencies` was not defined")),
17181718
|d| Ok(d),
17191719
)
17201720
}
17211721

17221722
pub fn get_dependency(&self, name: &str) -> CargoResult<TomlDependency> {
17231723
self.dependencies.clone().map_or(
1724-
Err(anyhow!("[workspace.dependencies] was not defined")),
1724+
Err(anyhow!("`workspace.dependencies` was not defined")),
17251725
|deps| {
17261726
deps.get(name).map_or(
17271727
Err(anyhow!(
1728-
"dependency {} was not found in [workspace.dependencies]",
1728+
"`dependency.{}` was not found in `workspace.dependencies`",
17291729
name
17301730
)),
17311731
|dep| Ok(dep.clone()),
@@ -1737,106 +1737,106 @@ impl InheritableFields {
17371737
pub fn version(&self) -> CargoResult<semver::Version> {
17381738
self.version
17391739
.clone()
1740-
.map_or(Err(anyhow!("[workspace.version] was not defined")), |d| {
1740+
.map_or(Err(anyhow!("`workspace.version` was not defined")), |d| {
17411741
Ok(d)
17421742
})
17431743
}
17441744

17451745
pub fn authors(&self) -> CargoResult<Vec<String>> {
17461746
self.authors
17471747
.clone()
1748-
.map_or(Err(anyhow!("[workspace.authors] was not defined")), |d| {
1748+
.map_or(Err(anyhow!("`workspace.authors` was not defined")), |d| {
17491749
Ok(d)
17501750
})
17511751
}
17521752

17531753
pub fn description(&self) -> CargoResult<String> {
17541754
self.description.clone().map_or(
1755-
Err(anyhow!("[workspace.description] was not defined")),
1755+
Err(anyhow!("`workspace.description` was not defined")),
17561756
|d| Ok(d),
17571757
)
17581758
}
17591759

17601760
pub fn homepage(&self) -> CargoResult<String> {
17611761
self.homepage
17621762
.clone()
1763-
.map_or(Err(anyhow!("[workspace.homepage] was not defined")), |d| {
1763+
.map_or(Err(anyhow!("`workspace.homepage` was not defined")), |d| {
17641764
Ok(d)
17651765
})
17661766
}
17671767

17681768
pub fn documentation(&self) -> CargoResult<String> {
17691769
self.documentation.clone().map_or(
1770-
Err(anyhow!("[workspace.documentation] was not defined")),
1770+
Err(anyhow!("`workspace.documentation` was not defined")),
17711771
|d| Ok(d),
17721772
)
17731773
}
17741774

17751775
pub fn readme(&self) -> CargoResult<StringOrBool> {
17761776
self.readme
17771777
.clone()
1778-
.map_or(Err(anyhow!("[workspace.readme] was not defined")), |d| {
1778+
.map_or(Err(anyhow!("`workspace.readme` was not defined")), |d| {
17791779
Ok(d)
17801780
})
17811781
}
17821782

17831783
pub fn keywords(&self) -> CargoResult<Vec<String>> {
17841784
self.keywords
17851785
.clone()
1786-
.map_or(Err(anyhow!("[workspace.keywords] was not defined")), |d| {
1786+
.map_or(Err(anyhow!("`workspace.keywords` was not defined")), |d| {
17871787
Ok(d)
17881788
})
17891789
}
17901790

17911791
pub fn categories(&self) -> CargoResult<Vec<String>> {
17921792
self.categories.clone().map_or(
1793-
Err(anyhow!("[workspace.categories] was not defined")),
1793+
Err(anyhow!("`workspace.categories` was not defined")),
17941794
|d| Ok(d),
17951795
)
17961796
}
17971797

17981798
pub fn license(&self) -> CargoResult<String> {
17991799
self.license
18001800
.clone()
1801-
.map_or(Err(anyhow!("[workspace.license] was not defined")), |d| {
1801+
.map_or(Err(anyhow!("`workspace.license` was not defined")), |d| {
18021802
Ok(d)
18031803
})
18041804
}
18051805

18061806
pub fn license_file(&self) -> CargoResult<String> {
18071807
self.license_file.clone().map_or(
1808-
Err(anyhow!("[workspace.license_file] was not defined")),
1808+
Err(anyhow!("`workspace.license_file` was not defined")),
18091809
|d| Ok(d),
18101810
)
18111811
}
18121812

18131813
pub fn repository(&self) -> CargoResult<String> {
18141814
self.repository.clone().map_or(
1815-
Err(anyhow!("[workspace.repository] was not defined")),
1815+
Err(anyhow!("`workspace.repository` was not defined")),
18161816
|d| Ok(d),
18171817
)
18181818
}
18191819

18201820
pub fn publish(&self) -> CargoResult<VecStringOrBool> {
18211821
self.publish
18221822
.clone()
1823-
.map_or(Err(anyhow!("[workspace.publish] was not defined")), |d| {
1823+
.map_or(Err(anyhow!("`workspace.publish` was not defined")), |d| {
18241824
Ok(d)
18251825
})
18261826
}
18271827

18281828
pub fn edition(&self) -> CargoResult<String> {
18291829
self.edition
18301830
.clone()
1831-
.map_or(Err(anyhow!("[workspace.edition] was not defined")), |d| {
1831+
.map_or(Err(anyhow!("`workspace.edition` was not defined")), |d| {
18321832
Ok(d)
18331833
})
18341834
}
18351835

18361836
pub fn badges(&self) -> CargoResult<BTreeMap<String, BTreeMap<String, String>>> {
18371837
self.badges
18381838
.clone()
1839-
.map_or(Err(anyhow!("[workspace.badges] was not defined")), |d| {
1839+
.map_or(Err(anyhow!("`workspace.badges` was not defined")), |d| {
18401840
Ok(d)
18411841
})
18421842
}

src/cargo/util/toml/mod.rs

+16-8
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,8 @@ pub fn read_manifest_from_str(
129129
}
130130
if let TomlDependency::Workspace(_) = dep {
131131
bail!(
132-
"`dependencies.{}` specified `{{ workspace = true}}`, but workspace dependencies cannot do this",
132+
"`workspace.dependencies.{}` specified `{{ workspace = true }}`, but \
133+
workspace dependencies cannot do this",
133134
name
134135
);
135136
}
@@ -1010,12 +1011,13 @@ impl<T> MaybeWorkspace<T> {
10101011
MaybeWorkspace::Workspace(TomlWorkspaceField { workspace: true }) => {
10111012
cargo_features.require(Feature::workspace_inheritance())?;
10121013
get_ws_field().context(format!(
1013-
"error reading `{}` from workspace root manifest's `[workspace.{}]`",
1014+
"error inheriting `{}` from workspace root manifest's `workspace.{}`",
10141015
label, label
10151016
))
10161017
}
10171018
MaybeWorkspace::Workspace(TomlWorkspaceField { workspace: false }) => Err(anyhow!(
1018-
"workspace cannot be false for key `package.{label}`",
1019+
"`workspace=false` is unsupported for `package.{}`",
1020+
label,
10191021
)),
10201022
}
10211023
}
@@ -2190,7 +2192,7 @@ impl<P: ResolveToPath + Clone> TomlDependency<P> {
21902192
}) => {
21912193
cargo_features.require(Feature::workspace_inheritance())?;
21922194
get_ws_dependency().context(format!(
2193-
"error reading `dependencies.{}` from workspace root manifest's `[workspace.dependencies.{}]`",
2195+
"error reading `dependencies.{}` from workspace root manifest's `workspace.dependencies.{}`",
21942196
label, label
21952197
)).map(|dep| {
21962198
match dep {
@@ -2200,16 +2202,22 @@ impl<P: ResolveToPath + Clone> TomlDependency<P> {
22002202
dep.add_features(features);
22012203
dep.update_optional(optional);
22022204
TomlDependency::Detailed(dep)
2203-
}
2204-
// We check for this when we parse a toml file
2205-
TomlDependency::Workspace(_) => unreachable!(),
2205+
},
2206+
TomlDependency::Workspace(_) => {
2207+
unreachable!(
2208+
"We check that no workspace defines dependencies with \
2209+
`{{ workspace = true }}` when we read a manifest from a string. \
2210+
this should not happen but did on {}",
2211+
label
2212+
)
2213+
},
22062214
}
22072215
})
22082216
}
22092217
TomlDependency::Workspace(TomlWorkspaceDependency {
22102218
workspace: false, ..
22112219
}) => Err(anyhow!(
2212-
"workspace cannot be false for key `dependencies.{}`",
2220+
"`workspace=false` is unsupported for `package.dependencies.{}`",
22132221
label,
22142222
)),
22152223
}

tests/testsuite/deduplicate_workspace.rs tests/testsuite/inheritable_workspace_fields.rs

+8-7
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//! Tests for deduplicating Cargo.toml fields with { workspace = true }
1+
//! Tests for inheriting Cargo.toml fields with { workspace = true }
22
use cargo_test_support::registry::{Dependency, Package};
33
use cargo_test_support::{basic_lib_manifest, git, paths, project, publish, registry};
44

@@ -495,10 +495,10 @@ fn inherit_from_own_undefined_field() {
495495
[ERROR] failed to parse manifest at `[CWD]/Cargo.toml`
496496
497497
Caused by:
498-
error reading `description` from workspace root manifest's `[workspace.description]`
498+
error inheriting `description` from workspace root manifest's `workspace.description`
499499
500500
Caused by:
501-
[workspace.description] was not defined
501+
`workspace.description` was not defined
502502
",
503503
)
504504
.run();
@@ -604,7 +604,7 @@ fn error_on_unimplemented_inheritance_fields() {
604604
[ERROR] failed to parse manifest at `[CWD]/Cargo.toml`
605605
606606
Caused by:
607-
error reading `version` from workspace root manifest's `[workspace.version]`
607+
error inheriting `version` from workspace root manifest's `workspace.version`
608608
609609
Caused by:
610610
inheriting from a parent workspace is not implemented yet
@@ -677,7 +677,7 @@ Caused by:
677677
failed to parse manifest at `[CWD]/bar/Cargo.toml`
678678
679679
Caused by:
680-
error reading `dependencies.detailed` from workspace root manifest's `[workspace.dependencies.detailed]`
680+
error reading `dependencies.detailed` from workspace root manifest's `workspace.dependencies.detailed`
681681
682682
Caused by:
683683
inheriting from a parent workspace is not implemented yet
@@ -724,7 +724,7 @@ fn error_workspace_false() {
724724
[ERROR] failed to parse manifest at `[CWD]/Cargo.toml`
725725
726726
Caused by:
727-
workspace cannot be false for key `package.description`
727+
`workspace=false` is unsupported for `package.description`
728728
",
729729
)
730730
.run();
@@ -768,7 +768,8 @@ fn error_workspace_dependency_looked_for_workspace_itself() {
768768
[ERROR] failed to parse manifest at `[CWD]/Cargo.toml`
769769
770770
Caused by:
771-
`dependencies.dep` specified `{ workspace = true}`, but workspace dependencies cannot do this
771+
`workspace.dependencies.dep` specified `{ workspace = true }`, but workspace dependencies \
772+
cannot do this
772773
",
773774
)
774775
.run();

tests/testsuite/main.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ mod cross_compile;
3939
mod cross_publish;
4040
mod custom_target;
4141
mod death;
42-
mod deduplicate_workspace;
4342
mod dep_info;
4443
mod directory;
4544
mod doc;
@@ -58,6 +57,7 @@ mod git_auth;
5857
mod git_gc;
5958
mod glob_targets;
6059
mod help;
60+
mod inheritable_workspace_fields;
6161
mod init;
6262
mod install;
6363
mod install_upgrade;

0 commit comments

Comments
 (0)