Skip to content

RFC: Cargo feature descriptions - #3485

Merged
weihanglo merged 16 commits into
rust-lang:masterfrom
tgross35:feature-documentation
Sep 6, 2026
Merged

RFC: Cargo feature descriptions#3485
weihanglo merged 16 commits into
rust-lang:masterfrom
tgross35:feature-documentation

Conversation

@tgross35

@tgross35 tgross35 commented Sep 9, 2023

Copy link
Copy Markdown
Member

View all comments

Rendered

RFC for feature-documentation
RFC goals: add a way to write feature descriptions in Cargo.toml

This was split from #3416

[features]
# current configuration
foo = []
# Add a description to the feature
bar = { enables = ["foo"], doc = "simple docstring here"}

# Features can also be full tables if descriptions are longer
[features.qux]
enables = ["bar", "baz"]
doc = """
# qux

This could be a longer description of this feature
"""

This would resolve rust-lang/cargo#4956

FCP

@tgross35

tgross35 commented Sep 9, 2023

Copy link
Copy Markdown
Member Author

@rustbot label +t-cargo

@rustbot

rustbot commented Sep 9, 2023

Copy link
Copy Markdown
Collaborator

Error: Label t-cargo can only be set by Rust team members

Please file an issue on GitHub at triagebot if there's a problem with this bot, or reach out on #t-infra on Zulip.

@compiler-errors compiler-errors added the T-cargo Relevant to the Cargo team, which will review and decide on the RFC. label Sep 9, 2023
I directly applied my more minor feedback that did not change the
characteristic of the RFC.
@epage

epage commented Sep 10, 2023

Copy link
Copy Markdown
Contributor

@tgross35 thanks for the access. Definitely makes it handy for the more trivial feedback.

Comment thread text/3485-feature-documentation.md Outdated
Comment on lines +159 to +160
- Rather than being consistent with `rustdoc` and accepting markdown, should the
`doc` key be consistent with `package.description` and only support plain

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Wanted to highlight this for discussion. My main interest is in being able to show summaries in cargo add. Might be good to reach out to @kornelski for what they have seen of how features are documented through the ecosystem as that might help show potential requirements.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Package descriptions tend to use markdown `code` and *emphasis*. Rust devs really like using ` everywhere. Even rustc uses ` in terminal error messages.

Markdown's goal is to look fine even when displayed as plain text.

You could define it as the first line being for CLI help, and the rest for docs. Analogous to how rustdoc handles doc comments.

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.

@kornelski 👍 for using markdown. And I think it makes sense to treat the first logical line (anything before the first double-newline) as a "short description", cutting off subsequent paragraphs in places where full documentation doesn't fit.

Comment thread text/3485-feature-documentation.md Outdated
Comment thread text/3485-feature-documentation.md Outdated

This RFC describes a new key to under `features` in `Cargo.toml` for
documentation. This will allow Cargo to display this information to the user and
provide a way for `rustdoc` to eventually render this data (how this is rendered

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.

One of the issues is how rustdoc consumes the data. rust doc generally knows nothing about Cargo.toml. I would suggest taking #3123 as a reference to start a discussion on cargo-rustdoc integration of this. It doesn't need to be perfect but at least two teams should have some consensus.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I did bring it up when I initially proposed this feature, https://rust-lang.zulipchat.com/#narrow/stream/266220-rustdoc/topic/Descriptions.20for.20feature.20flags and then opened a draft RFC suggesting that rustdoc accept JSON configuration, which Cargo could pass it #3421. That didn't get too much traction, though. I will start that discussion back up

eopb added a commit to eopb/rfcs that referenced this pull request Sep 20, 2023
Comment thread text/3485-feature-documentation.md
Comment thread text/3485-feature-documentation.md Outdated
@joshtriplett

Copy link
Copy Markdown
Member

Since RFC 3416 is in FCP, that unblocks this feature.

I'm going to go ahead and propose FCP here, and see how close we are to consensus.

Personally, I do think we should use markdown here. Markdown already looks reasonable in plain text, by design, and it gives crates.io and docs.rs and rustdoc something nicer to work with.

@joshtriplett

Copy link
Copy Markdown
Member

@rfcbot merge

@rfcbot

rfcbot commented Jun 21, 2024

Copy link
Copy Markdown

@joshtriplett has proposed to merge this. The next step is review by the rest of the tagged team members:

Concerns:

Once a majority of reviewers approve (and at most 2 approvals are outstanding), this will enter its final comment period. If you spot a major issue that hasn't been raised at any point in this process, please speak up!

See this document for info about what commands tagged team members can give me.

@rfcbot rfcbot added proposed-final-comment-period Currently awaiting signoff of all team members in order to enter the final comment period. disposition-merge This RFC is in PFCP or FCP with a disposition to merge it. labels Jun 21, 2024
Comment thread text/3485-feature-documentation.md Outdated
@weihanglo

weihanglo commented Jun 22, 2024

Copy link
Copy Markdown
Member

@rfcbot reviewed

Though I still want to call out that intra-doc links are important #3416 (review). CC @GuillaumeGomez if they have any opinion on this.

@GuillaumeGomez

Copy link
Copy Markdown
Member

This is a very good point. Thanks for the ping!

# Tables are preferred for longer descriptions
[features.corge]
enables = ["bar", "baz"]
doc = """

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.

Another good question raised was "should we also support intra-doc links in this documentation?". I personally think we should and make the context the same as the crate top-level. What do you think?

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.

Ah I see you mentioned it below, my bad.

@weihanglo weihanglo Jun 22, 2024

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 for the response!

The follow-up question from me would be: Is there any compatibility issues if we hadn't implemented this RFC and rustdoc change all together? If not then this RFC can safely go first.

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'm not sure. From cargo perspective, whether there are intra-doc links or not in this documentation doesn't matter. But it'll definitely need to be mentioned when support will be discussed in rustdoc.

For the current case, I think cargo should mention that intra-doc links may be supported when rustdoc support this option and that's it. What do you think?

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.

Sounds good to me.

@tgross35 could you add something like this? (or whichever way you'd like to rephase this)

- Rustdoc can build on this to show feature documentation.
+ Rustdoc can build on this to show feature documentation.
+ If this RFC gets stabilized before any corresponding change in rustdoc,
+ its documentation should highlight that rustdoc may parse the description and support intra-doc links in the feature.
+ Users need to be aware of this potential incompatibility.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Added, thank you!

Comment thread text/3485-feature-documentation.md Outdated
Comment thread text/3485-feature-documentation.md Outdated
Comment thread text/3485-feature-documentation.md Outdated
@epage

epage commented Sep 8, 2025

Copy link
Copy Markdown
Contributor

@weihanglo and @kornelski I moved your conversation into a thread in the hopes that it will make it easier to follow

@epage epage removed the T-rustdoc Relevant to rustdoc team, which will review and decide on the RFC. label Sep 17, 2025
@epage

epage commented Sep 17, 2025

Copy link
Copy Markdown
Contributor

FYI I removed T-rustdoc from this RFC because this is the Cargo portion split out of #3421 which is now just T-rustdoc's side. T-rustdoc's input in this RFC is still important for how viable this is for allowing #3421 but I expect we'll have other clients of this as well, including ourselves. I was just thinking the other day how having the feature descriptions would be nice for cargo's new completions.

@oli-obk oli-obk removed the T-crates-io Relevant to the crates.io team, which will review and decide on the RFC. label Sep 17, 2025
@GuillaumeGomez

Copy link
Copy Markdown
Member

Sounds good to me at least, thanks!

@tgross35

Copy link
Copy Markdown
Member Author

Unfortunately I've let this slip for two years, but I opened #4002 with a metadata proposal that can then be extended to this RFC pretty easily.


See [`feature-metadata`] for information about `enables`.

# Reference-level explanation

@tgross35 tgross35 Aug 20, 2026

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

If #4002 or similar merges, we will need to figure out how this shows up in metadata. With that proposal, this would be:

"features_v2": {
    "feat": { "doc": "simple docstring for bar" }
}

One question is what the key name should be. doc being consistent with the Cargo.toml makes sense, but this could also be a full name like documentation or description.

View changes since the review

@epage

epage commented Aug 25, 2026

Copy link
Copy Markdown
Contributor

We talked about the active concerns in the RFC

Neither of those requires the community-wide input and are likely best figured out while we work through implementation and stabilization.

@tgross35 if you could record those as Unresolved Questions, we'll remove the blocking concerns, allowing FCP to commence on this RFC.

@tgross35

Copy link
Copy Markdown
Member Author

Thanks for discussing, I have added those items as unresolved questions.

@epage

epage commented Aug 26, 2026

Copy link
Copy Markdown
Contributor

@rfcbot resolve cargo-metadata
@rfcbot resolve naming

@rust-rfcbot rust-rfcbot added final-comment-period Will be merged/postponed/closed in ~10 calendar days unless new substational objections are raised. and removed proposed-final-comment-period Currently awaiting signoff of all team members in order to enter the final comment period. labels Aug 26, 2026
@rust-rfcbot

Copy link
Copy Markdown
Collaborator

🔔 This is now entering its final comment period, as per the review above. 🔔

Comment thread text/3485-feature-documentation.md Outdated
Co-authored-by: Kevin Reid <kpreid@switchb.org>
@rust-rfcbot rust-rfcbot added finished-final-comment-period The final comment period is finished for this RFC. S-waiting-on-review Status: This is awaiting some action from the reviewer. to-announce and removed final-comment-period Will be merged/postponed/closed in ~10 calendar days unless new substational objections are raised. labels Sep 5, 2026
@rust-rfcbot

Copy link
Copy Markdown
Collaborator

The final comment period, with a disposition to merge, as per the review above, is now complete.

As the automated representative of the governance process, I would like to thank the author for their work and everyone else who contributed.

@weihanglo

Copy link
Copy Markdown
Member

Thanks people! This has passed FCP. Merging (finally 🎉🎉🎉).

Further discussion would happen in rust-lang/cargo#17445. Subscribe to track the progress.

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

Labels

disposition-merge This RFC is in PFCP or FCP with a disposition to merge it. finished-final-comment-period The final comment period is finished for this RFC. S-waiting-on-review Status: This is awaiting some action from the reviewer. T-cargo Relevant to the Cargo team, which will review and decide on the RFC. to-announce

Projects

Archived in project
Status: Unreviewed

Development

Successfully merging this pull request may close these issues.

Allow adding a description for features