Skip to content

Commit cc20b55

Browse files
committed
Auto merge of #13788 - epage:badges, r=weihanglo
fix(toml)!: Remove support for inheriting badges ### What does this PR try to resolve? We allowed `[badges]` to inherit from `[workspace.package.badges]` which was a bug: - This was not specified in the RFC - We did not document this - Even if someone were to try to guess to use this, it is inconsistent with how inheritance works because this should inherit from `workspace.badges` instead of `workspace.package.badges` While keeping in mind that `[badges]` is effectively deprecated. In that context, I think its safe to break support for this without a transition period. Fixes #13643 ### How should we test and review this PR? ### Additional information
2 parents e31c27d + bdd4bda commit cc20b55

File tree

6 files changed

+8
-50
lines changed

6 files changed

+8
-50
lines changed

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ cargo-platform = { path = "crates/cargo-platform", version = "0.1.5" }
3333
cargo-test-macro = { version = "0.2.0", path = "crates/cargo-test-macro" }
3434
cargo-test-support = { version = "0.2.0", path = "crates/cargo-test-support" }
3535
cargo-util = { version = "0.2.9", path = "crates/cargo-util" }
36-
cargo-util-schemas = { version = "0.3.0", path = "crates/cargo-util-schemas" }
36+
cargo-util-schemas = { version = "0.4.0", path = "crates/cargo-util-schemas" }
3737
cargo_metadata = "0.18.1"
3838
clap = "4.5.4"
3939
color-print = "0.3.5"

crates/cargo-util-schemas/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "cargo-util-schemas"
3-
version = "0.3.1"
3+
version = "0.4.0"
44
rust-version = "1.77" # MSRV:1
55
edition.workspace = true
66
license.workspace = true

crates/cargo-util-schemas/src/manifest/mod.rs

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ pub struct TomlManifest {
5151
pub replace: Option<BTreeMap<String, TomlDependency>>,
5252
pub patch: Option<BTreeMap<String, BTreeMap<PackageName, TomlDependency>>>,
5353
pub workspace: Option<TomlWorkspace>,
54-
pub badges: Option<InheritableBtreeMap>,
54+
pub badges: Option<BTreeMap<String, BTreeMap<String, String>>>,
5555
pub lints: Option<InheritableLints>,
5656

5757
/// Report unused keys (see also nested `_unused_keys`)
@@ -106,12 +106,6 @@ impl TomlManifest {
106106
self.features.as_ref()
107107
}
108108

109-
pub fn resolved_badges(
110-
&self,
111-
) -> Result<Option<&BTreeMap<String, BTreeMap<String, String>>>, UnresolvedError> {
112-
self.badges.as_ref().map(|l| l.resolved()).transpose()
113-
}
114-
115109
pub fn resolved_lints(&self) -> Result<Option<&TomlLints>, UnresolvedError> {
116110
self.lints.as_ref().map(|l| l.resolved()).transpose()
117111
}

src/cargo/util/toml/mod.rs

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -451,12 +451,7 @@ fn resolve_toml(
451451

452452
resolved_toml.lints = original_toml.lints.clone();
453453

454-
let resolved_badges = original_toml
455-
.badges
456-
.clone()
457-
.map(|mw| field_inherit_with(mw, "badges", || inherit()?.badges()))
458-
.transpose()?;
459-
resolved_toml.badges = resolved_badges.map(manifest::InheritableField::Value);
454+
resolved_toml.badges = original_toml.badges.clone();
460455
} else {
461456
for field in original_toml.requires_package() {
462457
bail!("this virtual manifest specifies a `{field}` section, which is not allowed");
@@ -799,7 +794,6 @@ impl InheritableFields {
799794
package_field_getter! {
800795
// Please keep this list lexicographically ordered.
801796
("authors", authors -> Vec<String>),
802-
("badges", badges -> BTreeMap<String, BTreeMap<String, String>>),
803797
("categories", categories -> Vec<String>),
804798
("description", description -> String),
805799
("documentation", documentation -> String),
@@ -1340,11 +1334,7 @@ fn to_real_manifest(
13401334
.expect("previously resolved")
13411335
.cloned()
13421336
.unwrap_or_default(),
1343-
badges: resolved_toml
1344-
.resolved_badges()
1345-
.expect("previously resolved")
1346-
.cloned()
1347-
.unwrap_or_default(),
1337+
badges: resolved_toml.badges.clone().unwrap_or_default(),
13481338
links: resolved_package.links.clone(),
13491339
rust_version: rust_version.clone(),
13501340
};

tests/testsuite/inheritable_workspace_fields.rs

Lines changed: 2 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,6 @@ fn permit_additional_workspace_fields() {
3030
exclude = ["foo.txt"]
3131
include = ["bar.txt", "**/*.rs", "Cargo.toml", "LICENSE", "README.md"]
3232
33-
[workspace.package.badges]
34-
gitlab = { repository = "https://gitlab.com/rust-lang/rust", branch = "master" }
35-
3633
[workspace.dependencies]
3734
dep = "0.1"
3835
"#,
@@ -117,8 +114,6 @@ fn inherit_own_workspace_fields() {
117114
.file(
118115
"Cargo.toml",
119116
r#"
120-
badges.workspace = true
121-
122117
[package]
123118
name = "foo"
124119
version.workspace = true
@@ -153,8 +148,6 @@ fn inherit_own_workspace_fields() {
153148
rust-version = "1.60"
154149
exclude = ["foo.txt"]
155150
include = ["bar.txt", "**/*.rs", "Cargo.toml"]
156-
[workspace.package.badges]
157-
gitlab = { repository = "https://gitlab.com/rust-lang/rust", branch = "master" }
158151
"#,
159152
)
160153
.file("src/main.rs", "fn main() {}")
@@ -186,9 +179,7 @@ You may press ctrl-c to skip waiting; the crate should be available shortly.
186179
r#"
187180
{
188181
"authors": ["Rustaceans"],
189-
"badges": {
190-
"gitlab": { "branch": "master", "repository": "https://gitlab.com/rust-lang/rust" }
191-
},
182+
"badges": {},
192183
"categories": ["development-tools"],
193184
"deps": [],
194185
"description": "This is a crate",
@@ -240,10 +231,6 @@ keywords = ["cli"]
240231
categories = ["development-tools"]
241232
license = "MIT"
242233
repository = "https://github.com/example/example"
243-
244-
[badges.gitlab]
245-
branch = "master"
246-
repository = "https://gitlab.com/rust-lang/rust"
247234
"#,
248235
cargo::core::manifest::MANIFEST_PREAMBLE
249236
),
@@ -665,15 +652,12 @@ fn inherit_workspace_fields() {
665652
rust-version = "1.60"
666653
exclude = ["foo.txt"]
667654
include = ["bar.txt", "**/*.rs", "Cargo.toml", "LICENSE", "README.md"]
668-
[workspace.package.badges]
669-
gitlab = { repository = "https://gitlab.com/rust-lang/rust", branch = "master" }
670655
"#,
671656
)
672657
.file("src/main.rs", "fn main() {}")
673658
.file(
674659
"bar/Cargo.toml",
675660
r#"
676-
badges.workspace = true
677661
[package]
678662
name = "bar"
679663
workspace = ".."
@@ -731,9 +715,7 @@ You may press ctrl-c to skip waiting; the crate should be available shortly.
731715
r#"
732716
{
733717
"authors": ["Rustaceans"],
734-
"badges": {
735-
"gitlab": { "branch": "master", "repository": "https://gitlab.com/rust-lang/rust" }
736-
},
718+
"badges": {},
737719
"categories": ["development-tools"],
738720
"deps": [],
739721
"description": "This is a crate",
@@ -791,10 +773,6 @@ categories = ["development-tools"]
791773
license = "MIT"
792774
license-file = "LICENSE"
793775
repository = "https://github.com/example/example"
794-
795-
[badges.gitlab]
796-
branch = "master"
797-
repository = "https://gitlab.com/rust-lang/rust"
798776
"#,
799777
cargo::core::manifest::MANIFEST_PREAMBLE
800778
),
@@ -1715,8 +1693,6 @@ fn warn_inherit_unused_manifest_key_package() {
17151693
.file(
17161694
"Cargo.toml",
17171695
r#"
1718-
badges = { workspace = true, xyz = "abc"}
1719-
17201696
[workspace]
17211697
members = []
17221698
[workspace.package]
@@ -1734,8 +1710,6 @@ fn warn_inherit_unused_manifest_key_package() {
17341710
rust-version = "1.60"
17351711
exclude = ["foo.txt"]
17361712
include = ["bar.txt", "**/*.rs", "Cargo.toml"]
1737-
[workspace.package.badges]
1738-
gitlab = { repository = "https://gitlab.com/rust-lang/rust", branch = "master" }
17391713
17401714
[package]
17411715
name = "bar"

0 commit comments

Comments
 (0)