Skip to content

feat: -Zmin-publish-age (RFC 3923)#17012

Merged
epage merged 17 commits into
rust-lang:masterfrom
weihanglo:min-publish-age
Jun 18, 2026
Merged

feat: -Zmin-publish-age (RFC 3923)#17012
epage merged 17 commits into
rust-lang:masterfrom
weihanglo:min-publish-age

Conversation

@weihanglo

@weihanglo weihanglo commented May 19, 2026

Copy link
Copy Markdown
Member

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 PublishAgePolicy is built before resolution and applied wherever a version filer needs to be applied

Where 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:

Site Kind Filtered?
resolver (dep_cache::query) selects (resolution) yes
cargo add (get_latest_dependency) selects (writes Cargo.toml) yes
cargo add path/git (select_package) non-registry source no
cargo add features (populate_available_features) enumerates features only no
cargo install (select_dep_pkg) selects (install target) no
cargo update --breaking (upgrade_dependency) selects (writes Cargo.toml) no
cargo update report (report_latest) displays "available: vX" no
future-incompat (get_updates) displays "newer versions" no
cargo info (query_summaries) displays no

How to test and review this PR?

25+ tests in tests/testsuite/min_publish_age.rs cover:

  • feature gate + ignored-config warnings
  • deny/allow logic and "0" disabling
  • per-registry config precedence
  • lockfile and [patch] preservation of too-new versions
  • cargo install / cargo add selection paths

Open questions

@rustbot

rustbot commented May 19, 2026

Copy link
Copy Markdown
Collaborator

r? @epage

rustbot has assigned @epage.
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: @ehuss, @epage, @weihanglo
  • @ehuss, @epage, @weihanglo expanded to ehuss, epage, weihanglo
  • Random selection from ehuss, epage

@rustbot rustbot added A-cli Area: Command-line interface, option parsing, etc. A-configuration Area: cargo config files and env vars A-dependency-resolution Area: dependency resolution and the resolver A-directory-source Area: directory sources (vendoring) A-documenting-cargo-itself Area: Cargo's documentation A-future-incompat Area: future incompatible reporting A-git Area: anything dealing with git A-interacts-with-crates.io Area: interaction with registries A-overrides Area: general issues with overriding dependencies (patch, replace, paths) A-registries Area: registries A-source-replacement Area: [source] replacement A-unstable Area: nightly unstable support A-workspaces Area: workspaces Command-clean Command-install Command-publish Command-vendor S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels May 19, 2026
@weihanglo
weihanglo marked this pull request as draft May 19, 2026 14:58
@rustbot rustbot removed the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label May 19, 2026
@weihanglo

Copy link
Copy Markdown
Member Author

Found something wrong. Wait a sec.

@weihanglo
weihanglo force-pushed the min-publish-age branch 2 times, most recently from 2477e6c to bc3e9c0 Compare May 19, 2026 15:24
Comment thread src/cargo/core/resolver/errors.rs Outdated
}
}

fn warn_unused_min_publish_age(gctx: &GlobalContext) -> CargoResult<()> {

@weihanglo weihanglo May 19, 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.

We warn all unused min-publish-age all at once, regardless of the precedence rule.

View changes since the review

Comment thread tests/testsuite/min_publish_age.rs
@weihanglo
weihanglo force-pushed the min-publish-age branch 2 times, most recently from 1ea1f55 to ddba374 Compare May 19, 2026 15:43

@clouatre clouatre left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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.

View changes since this review

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

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 PublishAgeViolation struct, so that we don't need to reformat the min-age config/

View changes since this review

Comment thread src/cargo/ops/cargo_update.rs
@weihanglo
weihanglo marked this pull request as ready for review June 18, 2026 04:06
@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Jun 18, 2026
weihanglo added 11 commits June 18, 2026 00:42
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.

@epage epage left a comment

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.

Thanks!

I'm assuming you will transfer the Open/Deferred to the tracking issue.

View changes since this review

@epage
epage added this pull request to the merge queue Jun 18, 2026
Merged via the queue into rust-lang:master with commit b5a4cd4 Jun 18, 2026
29 checks passed
@rustbot rustbot removed the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Jun 18, 2026
@weihanglo
weihanglo deleted the min-publish-age branch June 19, 2026 17:15
rust-bors Bot pushed a commit to rust-lang/rust that referenced this pull request Jun 20, 2026
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
rust-bors Bot pushed a commit to rust-lang/rust that referenced this pull request Jun 20, 2026
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)
@rustbot rustbot added this to the 1.98.0 milestone Jun 20, 2026
pull Bot pushed a commit to xtqqczze/rust-lang-miri that referenced this pull request Jun 21, 2026
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)
@weihanglo weihanglo linked an issue Jun 25, 2026 that may be closed by this pull request
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-cli Area: Command-line interface, option parsing, etc. A-configuration Area: cargo config files and env vars A-dependency-resolution Area: dependency resolution and the resolver A-directory-source Area: directory sources (vendoring) A-documenting-cargo-itself Area: Cargo's documentation A-future-incompat Area: future incompatible reporting A-git Area: anything dealing with git A-interacts-with-crates.io Area: interaction with registries A-overrides Area: general issues with overriding dependencies (patch, replace, paths) A-registries Area: registries A-registry-authentication Area: registry authentication and authorization (authn authz) A-source-replacement Area: [source] replacement A-timings Area: timings A-unstable Area: nightly unstable support A-workspaces Area: workspaces Command-add Command-clean Command-install Command-publish Command-update Command-vendor S-waiting-on-author Status: The marked PR is awaiting some action (such as code changes) from the PR author.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Minimum age for dependencies

4 participants