Skip to content

fix(package): preserve feature metadata in normalized manifests - #17509

Merged
rustbot merged 2 commits into
rust-lang:masterfrom
darkraider01:codex/preserve-feature-metadata
Sep 25, 2026
Merged

rustbot merged 2 commits into
rust-lang:masterfrom
darkraider01:codex/preserve-feature-metadata

Conversation

@darkraider01

Copy link
Copy Markdown
Contributor

Summary

Preserve feature metadata when generating the normalized Cargo.toml for cargo package and cargo publish.

Packaging still removes feature references to dependencies that are excluded from the published package, but now filters the existing enables list in place instead of converting every feature definition to the legacy array syntax.

Motivation

Feature definitions using the feature-metadata table syntax were previously rewritten as arrays during packaging. This discarded metadata such as doc, preventing registry consumers like cargo info and cargo metadata from accessing it.

Preserving the metadata table also ensures future feature metadata fields are not lost during packaging.

Fixes #17472.

Testing

Updated the packaging regression test to cover:

  • Preserving documented feature metadata
  • Preserving metadata with an empty enables list
  • Keeping legacy array definitions unchanged
  • Removing references to unpublished dev-dependencies without discarding metadata

Also verified the existing dev-dependency stripping test.

@rustbot rustbot added A-manifest Area: Cargo.toml issues S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Sep 24, 2026
@rustbot

rustbot commented Sep 24, 2026

Copy link
Copy Markdown
Collaborator

Thanks for the pull request, and welcome! The Rust Project has assigned @Muscraft (or someone else) to review your changes, you should hear from them (or someone else) within the next two weeks.

Please see the contribution instructions and our LLM policy for more information.

Why was this reviewer chosen?

The reviewer was selected based on:

  • Owners of files modified in this PR: @Muscraft, @epage, @weihanglo
  • @Muscraft, @epage, @weihanglo expanded to Muscraft, epage, weihanglo
  • Random selection from Muscraft, epage, weihanglo

@weihanglo weihanglo Sep 24, 2026 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

Would you mind follow the C-TEST commit structure there? The first commit adds/changes tests, and subsequent fix commit will change the test snapshot, whose diff can make the behavior change more obvious.

View changes since the review

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@darkraider01
One important point of C-TEST is that tests should passes in both commits. This ensure commits are bisectable, and snapshot diff clearly reflects behavior change.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks! I updated the test commit so it passes with the existing behavior, then the fix commit changes the snapshot along with the packaging code

b = []
c = { enables = ["a", "b"] }
c = { enables = ["a", "dev-only/feature", "b"], doc = "Enables a and b." }
empty = { enables = [], doc = "Enables nothing." }

@weihanglo weihanglo Sep 24, 2026 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you add one more feature only with enables without any other metadata fields?

View changes since the review

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done!

Comment on lines 2684 to 2685
a = []
b = []

@weihanglo weihanglo Sep 24, 2026 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some design questions I am uncertain:

  • In a package that has a mix of array and table syntax, how should we serialize features that still use array syntax?
  • If a feature with table syntax only has the enables field, should it be serialized with table or keep the array syntax?

cc @Muscraft, any opinions?

View changes since the review

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I went with preserving the syntax used for each feature. So if a manifest mixes arrays and tables, they stay arrays and tables in the packaged manifest. An enables-only table also stays a table.
That felt like the simplest rule, and I added a test for the enables-only case. If there’s a compatibility reason to turn those back into arrays, I’m happy to adjust it.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, that is indeed simpler. Also another supporiting argument: tools consuming Cargo.toml would anyway need to handle both syntax. Normalizing to new syntax doesn't really move the needle in terms of compatibility .

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks. I kept the syntax for each feature as written in the original manifest, including enables-only tables, and added a test for that case

@weihanglo weihanglo Sep 25, 2026 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Muscraft pointed out that cargo publish also normalize [dependencies] like

from

[dependencies]
syn = "1"

to

[dependencies.syn]
version = "1"

We might want to do normalized for [features] table as well when this feature is stabilized, to be consistent. (though the normalization may be conditioned on MSRV if it doesn't use new syntax at all)

The downside is that it may make git diff a bit more larger for cargo vendor users that check in vendored crates, even those new crates don't user feature metadata at all.

Let's move on and track this in the tracking issue.

@darkraider01
darkraider01 force-pushed the codex/preserve-feature-metadata branch from 56d0bb5 to 3045296 Compare September 24, 2026 14:57
@weihanglo weihanglo added the Z-feature-metadata Nightly: feature-metadata label Sep 24, 2026
@darkraider01
darkraider01 force-pushed the codex/preserve-feature-metadata branch from 3045296 to 90cd92b Compare September 24, 2026 15:32

@weihanglo weihanglo left a comment •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment on lines 2684 to 2685
a = []
b = []

@weihanglo weihanglo Sep 25, 2026 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Muscraft pointed out that cargo publish also normalize [dependencies] like

from

[dependencies]
syn = "1"

to

[dependencies.syn]
version = "1"

We might want to do normalized for [features] table as well when this feature is stabilized, to be consistent. (though the normalization may be conditioned on MSRV if it doesn't use new syntax at all)

The downside is that it may make git diff a bit more larger for cargo vendor users that check in vendored crates, even those new crates don't user feature metadata at all.

Let's move on and track this in the tracking issue.

@rustbot
rustbot added this pull request to the merge queue Sep 25, 2026
Merged via the queue into rust-lang:master with commit 3d7cf6e Sep 25, 2026
29 checks passed
@rustbot rustbot removed the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Sep 25, 2026
rust-bors Bot pushed a commit to rust-lang/rust that referenced this pull request Sep 25, 2026
Update cargo submodule

5 commits in 98a09e7e7d62850f14e5b6132101fc1edd19a16f..3d7cf6e937d6127d0f49881bf689c560b36d35c4
2026-09-21 19:03:16 +0000 to 2026-09-25 01:47:29 +0000
- fix(package): preserve feature metadata in normalized manifests (rust-lang/cargo#17509)
- fix(diag): Don't report unused normal deps when static libs are skipped  (rust-lang/cargo#17515)
- test(builtin-deps): Additional manifest regression tests (rust-lang/cargo#17500)
- fix(builtin-deps): Builtin dependencies manifest validation (rust-lang/cargo#17499)
- feat(builtin-deps): Add builtin dependencies manifest syntax (rust-lang/cargo#17498)

r? ghost
@rustbot rustbot added this to the 1.100.0 milestone Sep 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-manifest Area: Cargo.toml issues Z-feature-metadata Nightly: feature-metadata

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Preserve feature metadata in packaged Cargo.toml

4 participants