Skip to content

feat(manifest): support feature-documentation in manifests - #17447

Open
AudaciousAxiom wants to merge 2 commits into
rust-lang:masterfrom
AudaciousAxiom:feat/rfc-impl-feature-documentation-schema
Open

feat(manifest): support feature-documentation in manifests#17447
AudaciousAxiom wants to merge 2 commits into
rust-lang:masterfrom
AudaciousAxiom:feat/rfc-impl-feature-documentation-schema

Conversation

@AudaciousAxiom

Copy link
Copy Markdown
Contributor

What does this PR try to resolve?

This implements part of RFC feature-documentation, tracked by #17445. This only adds support for the new key in the schema. This doesn't add anything to the index as this was decided against.

This doesn't not introduce a dedicated unstable feature, as mentioned in #17445 (comment), and the new key is simply gated behind the existing feature-metadata unstable feature.

The exact name of the key is still TBD, but it will be easy to rename either in this PR or later.

Open questions

Future work

At least the following is still to be done for this RFC (I may not have time to tackle this):

  • Exposing the new key through cargo metadata.
  • Exposing the documentation to humans through cargo add (and through other tools/services, like docs.rs).

How to test and review this PR?

The tests should be enough to review this.

@rustbot rustbot added the A-manifest Area: Cargo.toml issues label Sep 6, 2026

p.cargo("check")
.masquerade_as_nightly_cargo(&["feature-metadata"])
.run();

@AudaciousAxiom AudaciousAxiom Sep 6, 2026

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.

Should there be a check of the new key being parsed?

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.

I guess this can similarily be split into two (test, fix) commits, so that we don't need a verification but the test diff showing that it was an unused manifest key.

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.

If we had a cargo metadata integration, then we'll have a verification for the consumption side (yeah we should continue the design discussion).

Or we can also add cargo-info integration for feature metadata in a follow-up as part of the verification. @0xPoe any opinion on this? I am not sure whether it should be behind a unstable flag though, given cargo-info is purely for human not programmable.

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 guess this can similarily be split into two (test, fix) commits, so that we don't need a verification but the test diff showing that it was an unused manifest key.

I've split the PR: the feature_has_documentation test case is now introduced in the first commit, triggers the "unused key" warning, which then disappears in the second commit as support for the key is added.

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.

Or we can also add cargo-info integration for feature metadata in a follow-up as part of the verification. @0xPoe any opinion on this? I am not sure whether it should be behind a unstable flag though, given cargo-info is purely for human not programmable.

Sounds interesting. I believe docs may also be helpful for human use. However, the biggest challenge would be the UI design. In the current cargo-info output, it is difficult to display the documents directly within the existing layout.

edition = "2015"

[features]
foo = { enables = [], doc = "Enables foo." }

@AudaciousAxiom AudaciousAxiom Sep 6, 2026

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 think it's still a bit unclear what the style of these should be: should these be capitalized and terminated with a period? I suppose this also depends on whether cargo add (and others) apply any transformation to these.

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.

IMHO it should follow what rustdoc suggesting: https://doc.rust-lang.org/nightly/rustdoc/how-to-write-documentation.html. Strip trailing periods sounds a future problem and also is human-eye-pleasing so we can change whenever needed.

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.

Agreed

Comment thread crates/cargo-util-schemas/src/manifest/mod.rs
@AudaciousAxiom
AudaciousAxiom force-pushed the feat/rfc-impl-feature-documentation-schema branch from e5b1573 to 0baabe5 Compare September 6, 2026 09:59
@AudaciousAxiom

Copy link
Copy Markdown
Contributor Author

The CI failure seems unrelated.

@AudaciousAxiom
AudaciousAxiom marked this pull request as ready for review September 6, 2026 10:14
@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Sep 6, 2026
@rustbot

rustbot commented Sep 6, 2026

Copy link
Copy Markdown
Collaborator

r? @weihanglo

rustbot has assigned @weihanglo.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

Why was this reviewer chosen?

The reviewer was selected based on:

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

@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.

Thanks!

Could you expand https://doc.rust-lang.org/nightly/cargo/reference/unstable.html#feature-metadata a bit? Perhaps with a subsection linking to feature-documentation RFC and tracking issue.
(Also just noticed that we forgot to put feature-metadata RFC link there)

View changes since this review

/// Features that this feature enables.
pub enables: Vec<String>,

/// Unstable feature `feature-documentation`. Documentation for the feature.

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.

Suggested change
/// Unstable feature `feature-documentation`. Documentation for the feature.
/// Documentation for the feature.

I think this should be sufficient?


p.cargo("check")
.masquerade_as_nightly_cargo(&["feature-metadata"])
.run();

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.

I guess this can similarily be split into two (test, fix) commits, so that we don't need a verification but the test diff showing that it was an unused manifest key.


p.cargo("check")
.masquerade_as_nightly_cargo(&["feature-metadata"])
.run();

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.

If we had a cargo metadata integration, then we'll have a verification for the consumption side (yeah we should continue the design discussion).

Or we can also add cargo-info integration for feature metadata in a follow-up as part of the verification. @0xPoe any opinion on this? I am not sure whether it should be behind a unstable flag though, given cargo-info is purely for human not programmable.

edition = "2015"

[features]
foo = { enables = [], doc = "Enables foo." }

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.

IMHO it should follow what rustdoc suggesting: https://doc.rust-lang.org/nightly/rustdoc/how-to-write-documentation.html. Strip trailing periods sounds a future problem and also is human-eye-pleasing so we can change whenever needed.

@AudaciousAxiom
AudaciousAxiom force-pushed the feat/rfc-impl-feature-documentation-schema branch from 0baabe5 to 5d1f882 Compare September 6, 2026 13:22
@rustbot rustbot added the A-documenting-cargo-itself Area: Cargo's documentation label Sep 6, 2026
@AudaciousAxiom
AudaciousAxiom force-pushed the feat/rfc-impl-feature-documentation-schema branch from 5d1f882 to 9199a6e Compare September 6, 2026 13:23
This is equivalent to the array-of-strings syntax.
Support for other keys should be added later.

### feature-documentation

@AudaciousAxiom AudaciousAxiom Sep 6, 2026

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.

Could you expand https://doc.rust-lang.org/nightly/cargo/reference/unstable.html#feature-metadata a bit? Perhaps with a subsection linking to feature-documentation RFC and tracking issue.

I've added a subsection. It's not added to the ToC at the beginning of the page as feature-documentation is not actually an unstable feature.

View changes since the review

```toml
[features.serde]
enables = []
doc = "Enables support for serialization and deserialization via serde."

@AudaciousAxiom AudaciousAxiom Sep 6, 2026

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.

This is mostly the example from the RFC, but I've taken the liberty to make it fit the rustdoc guidelines a bit more.

View changes since the review

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-documenting-cargo-itself Area: Cargo's documentation A-manifest Area: Cargo.toml issues S-waiting-on-review Status: Awaiting review from the assignee but also interested parties.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants