Skip to content

feat(toml): allow overriding inherited default-features in 2024#17126

Open
0xPoe wants to merge 8 commits into
rust-lang:masterfrom
0xPoe:poe-patch-inherit-default-features
Open

feat(toml): allow overriding inherited default-features in 2024#17126
0xPoe wants to merge 8 commits into
rust-lang:masterfrom
0xPoe:poe-patch-inherit-default-features

Conversation

@0xPoe

@0xPoe 0xPoe commented Jun 21, 2026

Copy link
Copy Markdown
Member

What does this PR try to resolve?

close #16959

Implement RFC 3945, on Edition 2024+ allow workspace members to override the workspace dependency's default-features setting.

Earlier editions are unchanged: setting default-features on an inherited dependency is still ignored with a warning.

Also, this change would allow cargo add X --no-default-features -p Y, but only on Edition 2024+.

How to test and review this PR?

Review and check it commit by commit.

r?@ghost

@rustbot rustbot added A-documenting-cargo-itself Area: Cargo's documentation A-manifest Area: Cargo.toml issues Command-add labels Jun 21, 2026
@0xPoe 0xPoe force-pushed the poe-patch-inherit-default-features branch from c1ee481 to a6548d4 Compare June 23, 2026 21:19
Impl RFC 3945, on Edition 2024+ allow workspace members
to override the workspace dependency's `default-features` setting.

Earlier editions are unchanged: setting `default-features` on an
inherited dependency is still ignored with a warning.

Signed-off-by: 0xPoe <techregister@pm.me>
@0xPoe 0xPoe force-pushed the poe-patch-inherit-default-features branch from a6548d4 to 72f4119 Compare June 23, 2026 21:28
Signed-off-by: 0xPoe <techregister@pm.me>
@0xPoe 0xPoe force-pushed the poe-patch-inherit-default-features branch from 72f4119 to 62db596 Compare June 23, 2026 21:34
@0xPoe 0xPoe marked this pull request as ready for review June 23, 2026 21:34
@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Jun 23, 2026
@0xPoe 0xPoe changed the title NOT READY FOR REVIEW: feat(toml): allow overriding inherited default-features in 2024 feat(toml): allow overriding inherited default-features in 2024 Jun 23, 2026

@0xPoe 0xPoe left a comment

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.

cargo add dep --default-features -p app doesn't work correctly. I will rework this.

View changes since this review

@0xPoe 0xPoe marked this pull request as draft June 23, 2026 22:02
@rustbot rustbot removed the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Jun 23, 2026
@0xPoe 0xPoe changed the title feat(toml): allow overriding inherited default-features in 2024 WIP: feat(toml): allow overriding inherited default-features in 2024 Jun 23, 2026
@epage

epage commented Jun 23, 2026

Copy link
Copy Markdown
Contributor

Comment thread src/cargo/util/toml/mod.rs Outdated
Comment thread src/doc/src/reference/workspaces.md Outdated
0xPoe added 3 commits June 24, 2026 23:51
`cargo add --no-default-features` (or `--default-features`) against a
dependency inherited from `[workspace.dependencies]` is now allowed when
the package is on Edition 2024+, matching the manifest behavior. Earlier
editions still error, pointing the user to the workspace manifest.

Signed-off-by: 0xPoe <techregister@pm.me>
Signed-off-by: 0xPoe <techregister@pm.me>
Signed-off-by: 0xPoe <techregister@pm.me>
@0xPoe 0xPoe force-pushed the poe-patch-inherit-default-features branch 3 times, most recently from f2f677f to 17595ac Compare June 24, 2026 22:04
@0xPoe

0xPoe commented Jun 24, 2026

Copy link
Copy Markdown
Member Author

Will we need to update doc.rust-lang.org/edition-guide/rust-2024/cargo-inherited-default-features.html as part of this?

Yes, I will create a PR for this.

@0xPoe 0xPoe marked this pull request as ready for review June 24, 2026 22:11
@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Jun 24, 2026
@0xPoe 0xPoe changed the title WIP: feat(toml): allow overriding inherited default-features in 2024 feat(toml): allow overriding inherited default-features in 2024 Jun 24, 2026
@0xPoe 0xPoe force-pushed the poe-patch-inherit-default-features branch from 17595ac to 33ca750 Compare June 24, 2026 22:30
Signed-off-by: 0xPoe <techregister@pm.me>
Signed-off-by: 0xPoe <techregister@pm.me>
@0xPoe 0xPoe force-pushed the poe-patch-inherit-default-features branch from 33ca750 to 1b14f50 Compare June 24, 2026 22:32

@0xPoe 0xPoe left a comment

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.

🔢 Self-check (PR reviewed by myself and ready for feedback)

  • Code compiles successfully

  • Unit tests added

  • No AI-generated elegant nonsense in PR.

  • Comments added where necessary

  • PR title and description updated

  • Documentation updated

  • PR size is reasonable

View changes since this review

- [`default-features`][default-features] (Edition 2024 packages, requires Rust 1.98+):
Overrides the value set in `[workspace.dependencies]`.
If neither the package nor the workspace specifies `default-features`, it defaults to `true`.
Before Rust 1.98, or in earlier editions, package-level `default-features = false`

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.

Not sure if this is the perfect word for it, and not sure how detailed we should be here.

@0xPoe 0xPoe requested a review from epage June 25, 2026 13:56
false,
None,
true,
None,

@epage epage Jun 30, 2026

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.

Do we have a test case for

$ cargo init
$ cargo add foo --default-features

ie explicit --default-features with the foo = "1.0" case

View changes since the review

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.

No, we don’t have a case that compiles with cargo init, especially with edition 2024. So I added a new one.

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.

{ws_def_feat} for `workspace.dependencies.{label}`, \
this could become a hard error in the future"
{ws_def_feat} for `workspace.dependencies.{label}`; \
overriding workspace `default-features` to false requires Rust 1.98+ \

@epage epage Jun 30, 2026

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.

Just tracking that we are pretty close to the deadline for this to make sure we update this if we don't make it

View changes since the review

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.

Yes, we have about 10 days to cut a new one if I remember correctly.

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.

Beta branch is on the 3rd and I believe they use our last submodule update, making it earlier.

Signed-off-by: 0xPoe <poe.liu@pm.me>
@0xPoe 0xPoe force-pushed the poe-patch-inherit-default-features branch from e97fffa to 62a3dd8 Compare June 30, 2026 19:24
@0xPoe 0xPoe requested a review from epage July 1, 2026 20:53
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 Command-add 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.

Tracking Issue for inherit-default-features

4 participants