feat: -Zmin-publish-age (RFC 3923)#17012
Conversation
|
r? @epage rustbot has assigned @epage. Use Why was this reviewer chosen?The reviewer was selected based on:
|
|
Found something wrong. Wait a sec. |
2477e6c to
bc3e9c0
Compare
| } | ||
| } | ||
|
|
||
| fn warn_unused_min_publish_age(gctx: &GlobalContext) -> CargoResult<()> { |
There was a problem hiding this comment.
We warn all unused min-publish-age all at once, regardless of the precedence rule.
1ea1f55 to
ddba374
Compare
There was a problem hiding this comment.
The largest=Day, smallest=Minute rounding produces output like published 2d 8h 23m ago. Suggest simplifying to a single unit based on magnitude: >= 2 days rounds to nearest day (published 3 days ago), < 2 days rounds to nearest hour (published 11 hours ago). The sub-day precision is noise at the day scale and the user cannot act on the minutes component.
For context: we currently enforce this in CI with a bash script that diffs Cargo.lock against the base branch and calls the crates.io API to check publish timestamps on net-new crates. This feature would replace that entirely. The error message is the main user-facing surface, so getting the formatting right matters.
There was a problem hiding this comment.
This revision:
- Addressed lockfile change reporting issue to also "report_too_new".
- Preserve the raw min-publish-age config for later display, and encapsulate it inside a
PublishAgeViolationstruct, so that we don't need to reformat the min-age config/
Also warn when `-Zmin-publish-age` is absent
The juicy part is `PublishAgePolicy::too_new`
Implement the `-Zmin-publish-age` filter at the resolver layer. The resolver filters out versions that are too new, unless pinned by a lock file or a `[patch]` entry.
When resolution fails because every candidate is newer than the configured `min-publish-age`, report "version X is too new (published N ago)" instead of the generic "version X is unavailable". The display format is rounded to a single unit like `published 3 days ago` / `published 11 hours ago` instead of a multi-unit span like `2d 8h 23m ago`, because sub-day precision is noisy
annotate the `(available: vX)` status line with `, published N ago`. This mirrors the existing `, requires Rust X` MSRV note
Only `cargo install --path` is affected
Since policy is now in resolver layer, any query doesn't use resolver should enforce the policy if needed. `cargo add` is one of these places.
50f1812 to
a49ee42
Compare
Update cargo submodule 8 commits in 598ab48ec328e3e4f5e4e373d8df7264bc8e27cd..71e52e6ef695518c3a7d166fdde0dc3650c2fedd 2026-06-17 02:39:50 +0000 to 2026-06-19 16:23:18 +0000 - chore(deps): update msrv to v1.94 (rust-lang/cargo#17121) - test(update): show cross-registry multi-spec precise (rust-lang/cargo#17119) - fix(resolver): hint how to resolve too-new versions (rust-lang/cargo#17118) - fix(add): list too-new versions and how to override (rust-lang/cargo#17117) - feat: `-Zmin-publish-age` (RFC 3923) (rust-lang/cargo#17012) - feat(diag): Support `build.warnings` for cargo lints (rust-lang/cargo#17112) - Remove windows-sys dependencies older than 0.61 (rust-lang/cargo#17115) - fix(install): Run cargo lints like rustc lints (rust-lang/cargo#17107) r? ghost
Update cargo submodule 9 commits in 598ab48ec328e3e4f5e4e373d8df7264bc8e27cd..a595d0da21f228b7fdae64d3d5c0e527ea66bb59 2026-06-17 02:39:50 +0000 to 2026-06-20 13:42:59 +0000 - fix(host-config): dont apply target config to host artifacts (rust-lang/cargo#17123) - chore(deps): update msrv to v1.94 (rust-lang/cargo#17121) - test(update): show cross-registry multi-spec precise (rust-lang/cargo#17119) - fix(resolver): hint how to resolve too-new versions (rust-lang/cargo#17118) - fix(add): list too-new versions and how to override (rust-lang/cargo#17117) - feat: `-Zmin-publish-age` (RFC 3923) (rust-lang/cargo#17012) - feat(diag): Support `build.warnings` for cargo lints (rust-lang/cargo#17112) - Remove windows-sys dependencies older than 0.61 (rust-lang/cargo#17115) - fix(install): Run cargo lints like rustc lints (rust-lang/cargo#17107)
Update cargo submodule 9 commits in 598ab48ec328e3e4f5e4e373d8df7264bc8e27cd..a595d0da21f228b7fdae64d3d5c0e527ea66bb59 2026-06-17 02:39:50 +0000 to 2026-06-20 13:42:59 +0000 - fix(host-config): dont apply target config to host artifacts (rust-lang/cargo#17123) - chore(deps): update msrv to v1.94 (rust-lang/cargo#17121) - test(update): show cross-registry multi-spec precise (rust-lang/cargo#17119) - fix(resolver): hint how to resolve too-new versions (rust-lang/cargo#17118) - fix(add): list too-new versions and how to override (rust-lang/cargo#17117) - feat: `-Zmin-publish-age` (RFC 3923) (rust-lang/cargo#17012) - feat(diag): Support `build.warnings` for cargo lints (rust-lang/cargo#17112) - Remove windows-sys dependencies older than 0.61 (rust-lang/cargo#17115) - fix(install): Run cargo lints like rustc lints (rust-lang/cargo#17107)
View all comments
What does this PR try to resolve?
This implements RFC 3923 min-publish-age (rust-lang/rfcs#3923, #17009).
The policy lives entirely at the resolver layer. A
PublishAgePolicyis built before resolution and applied wherever a version filer needs to be appliedWhere the filter is applied
Because the policy is enforced in the resolver, every code path that selects a version outside the resolver must apply it explicitly. Full audit:
dep_cache::query)cargo add(get_latest_dependency)Cargo.toml)cargo addpath/git (select_package)cargo addfeatures (populate_available_features)cargo install(select_dep_pkg)cargo update --breaking(upgrade_dependency)Cargo.toml)cargo updatereport (report_latest)get_updates)cargo info(query_summaries)How to test and review this PR?
25+ tests in
tests/testsuite/min_publish_age.rscover:"0"disabling[patch]preservation of too-new versionscargo install/cargo addselection pathsOpen questions
registry.min-publish-age/registries.min-publish-ageprecedence rule-Zmin-publish-age(RFC 3923) #17012 (comment)cargo installbehavior (there were some miscommunication in the RFC)-Zmin-publish-age(RFC 3923) #17012 (comment)cargo update --breakingbehavior-Zmin-publish-age(RFC 3923) #17012 (comment)-Zmin-publish-age(RFC 3923) #17012 (comment)-Zmin-publish-age(RFC 3923) #17012 (comment)