Skip to content

feat(hints): support minimum optimization levels - #17368

Open
0xPoe wants to merge 4 commits into
rust-lang:masterfrom
0xPoe:hint-min-opt-level
Open

0xPoe wants to merge 4 commits into
rust-lang:masterfrom
0xPoe:hint-min-opt-level

Conversation

@0xPoe

@0xPoe 0xPoe commented Aug 16, 2026 •

Copy link
Copy Markdown
Member

View all comments

What does this PR try to resolve?

ref #17334

This PR would allow Rust library to provide a simple hint about the minimum opt-level to build them with via the hint.min-opt-level setting in the manifest.

How to test and review this PR?

Check the unit tests and review it commit by commit.

r?@ghost

@0xPoe 0xPoe changed the title feat(hints): support minimum optimization levels WIP: feat(hints): support minimum optimization levels Aug 16, 2026
@0xPoe 0xPoe changed the title WIP: feat(hints): support minimum optimization levels WIP(Not Ready For Review): feat(hints): support minimum optimization levels Aug 16, 2026
@rustbot rustbot added A-build-execution Area: anything dealing with executing the compiler A-cargo-targets Area: selection and definition of targets (lib, bins, examples, tests, benches) A-documenting-cargo-itself Area: Cargo's documentation A-manifest Area: Cargo.toml issues A-profiles Area: profiles A-unstable Area: nightly unstable support labels Aug 18, 2026
@0xPoe
0xPoe force-pushed the hint-min-opt-level branch 7 times, most recently from b532a3f to 2b19c48 Compare August 21, 2026 07:18

@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

r?@joshtriplett

View changes since this review

Comment thread crates/cargo-util-schemas/Cargo.toml Outdated
Comment thread crates/cargo-util-schemas/manifest.schema.json
Comment thread src/workspace/profiles.rs Outdated
@0xPoe 0xPoe changed the title WIP(Not Ready For Review): feat(hints): support minimum optimization levels feat(hints): support minimum optimization levels Aug 21, 2026
@0xPoe
0xPoe marked this pull request as ready for review August 21, 2026 07:20
@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Aug 21, 2026
Comment thread doc/book/src/reference/unstable.md
Comment thread doc/book/src/reference/unstable.md Outdated
Comment thread src/compiler/mod.rs Outdated
Comment thread src/workspace/profiles.rs
Comment thread tests/testsuite/hints.rs
Comment thread tests/testsuite/hints.rs
Comment thread tests/testsuite/hints.rs
@rustbot

This comment has been minimized.

@0xPoe
0xPoe force-pushed the hint-min-opt-level branch 2 times, most recently from 14ab0ce to 415812c Compare August 26, 2026 07:53
@rustbot

This comment has been minimized.

Comment thread src/workspace/profiles.rs
Comment thread src/workspace/profiles.rs Outdated
Comment thread src/diagnostics/rules/min_opt_level_hint.rs Outdated
Comment thread src/diagnostics/rules/min_opt_level_hint.rs Outdated
pull Bot pushed a commit to Mu-L/cargo that referenced this pull request Sep 20, 2026
### What does this PR try to resolve?

Try to use `annotate-snippets` to report mostly unused warnings.
Inspired by
rust-lang#17368 (comment).

Some behaviour changes after we move it to phase pass.

| # | Case | Before | After |
|---|---|---|---|
| 1 | `hint-mostly-unused = true` in a profile table the build doesn't
apply: unselected profile (`[profile.release]` on `cargo check`, config
`profile.bench`), `build-override` with no build scripts,
`package.<spec>` for a package that isn't built | Silent | Warns |
| 2 | `hints.mostly-unused = true` while a profile sets
`hint-mostly-unused = false` for that package | Silent, as the flag
wouldn't change this build | Warns, as the key is still ignored without
the flag (the profile override isn't considered) |
| 3 | `hints.mostly-unused = true` while a profile also sets
`hint-mostly-unused = true` for that package | Only the profile warning
| Both warnings |
| 4 | `[hints]` in a workspace member this invocation doesn't compile,
e.g. `cargo check -p a` when `b` has the hint | Silent | Warns about `b`
|
| 5 | `cargo doc -p b` where `b` has `[hints]`| Silent | Warns |
| 6 | `cargo clean` with `hint-mostly-unused = true` in a config/env
profile | Silent | Warns, as `cargo clean` loads profiles |
| 7 | `[hints]` in a path dependency that isn't a workspace member |
Warns | Silent |
| 8 | `[hints]` in a registry/git dependency | Warns under `-vv` when it
is compiled | Silent |
| 9 | `cargo install <registry crate>` whose own manifest has
`[profile.release] hint-mostly-unused = true` | Warns | Silent |

### How to test and review this PR?

Check the unit tests and review each commit individually.

r?@ghost

LLM disclosure: AI generated the unit tests and helped me move mostly
unused diagnostics to the parse pass.
@0xPoe
0xPoe force-pushed the hint-min-opt-level branch from 961bec9 to bf6bede Compare September 21, 2026 07:17
@rustbot

This comment has been minimized.

@0xPoe
0xPoe force-pushed the hint-min-opt-level branch 4 times, most recently from 2314321 to 8ad3d1f Compare September 21, 2026 07:59
@0xPoe
0xPoe marked this pull request as draft September 21, 2026 08:00
@rustbot rustbot removed the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Sep 21, 2026
@0xPoe 0xPoe changed the title feat(hints): support minimum optimization levels WIP: feat(hints): support minimum optimization levels Sep 21, 2026
@0xPoe
0xPoe force-pushed the hint-min-opt-level branch from 8ad3d1f to e720ead Compare September 22, 2026 08:26
@0xPoe 0xPoe changed the title WIP: feat(hints): support minimum optimization levels feat(hints): support minimum optimization levels Sep 22, 2026
@0xPoe
0xPoe requested a review from epage September 22, 2026 08:27
@0xPoe
0xPoe marked this pull request as ready for review September 22, 2026 08:27
@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Sep 22, 2026
@rustbot

This comment has been minimized.

@0xPoe
0xPoe force-pushed the hint-min-opt-level branch from e720ead to d490827 Compare October 4, 2026 19:21
0xPoe added 4 commits October 4, 2026 21:23
Record the current ignored-hint behavior across
the RFC precedence, scope, validation, and boundary cases.

Signed-off-by: 0xPoe <poe.liu@pm.me>
Validating `hints.min-opt-level` only needs the manifest, so run it as a
package rule in the parse pass instead of walking the pre-build unit
graph. Non-member path dependencies stop being diagnosed, matching how
unused manifest keys and unknown hints are already reported.

Signed-off-by: 0xPoe <poe.liu@pm.me>
Signed-off-by: 0xPoe <poe.liu@pm.me>
@0xPoe
0xPoe force-pushed the hint-min-opt-level branch from d490827 to 1da3c9b Compare October 4, 2026 19:26
@rustbot

rustbot commented Oct 4, 2026

Copy link
Copy Markdown
Collaborator

This PR was rebased onto a different master commit. Here's a range-diff highlighting what actually changed.

Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers.

This branch has not been deployed

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

Labels

A-build-execution Area: anything dealing with executing the compiler A-cargo-targets Area: selection and definition of targets (lib, bins, examples, tests, benches) A-documenting-cargo-itself Area: Cargo's documentation A-manifest Area: Cargo.toml issues A-profiles Area: profiles A-unstable Area: nightly unstable support S-waiting-on-author Status: The marked PR is awaiting some action (such as code changes) from the PR author. 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