Skip to content

Use caret (^) as the default required_version comparator - #7048

Open
wesleymatosdev wants to merge 2 commits into
rust-lang:mainfrom
wesleymatosdev:fix/6729-caret-default
Open

Use caret (^) as the default required_version comparator#7048
wesleymatosdev wants to merge 2 commits into
rust-lang:mainfrom
wesleymatosdev:fix/6729-caret-default

Conversation

@wesleymatosdev

Copy link
Copy Markdown
Contributor

Closes #6729

Summary

required_version currently treats a bare version (no comparator prefix) as
an exact match, overriding the semver crate's own default of a caret
requirement. As discussed in #6729, this diverges from how Cargo treats
dependency version requirements with no operator, where a bare version like
"1.2.3" is equivalent to "^1.2.3".

This removes the override in check_semver_version so a bare version behaves
like ^version, matching Cargo's convention. The old exact-match behavior is
still available by opting in explicitly with =, e.g.
required_version = "=1.2.3".

  • src/config/mod.rs: remove the per-comparator override that forced a bare
    (no-prefix) comparator from semver's own default (Op::Caret) back to
    Op::Exact.
  • Configurations.md: documents the new default, adds an explicit "Match on
    exact version" example using =, and notes the caret-default in the
    Possible values bullet.
  • CHANGELOG.md: adds a Changed entry under [Unreleased] referencing
    Use caret (^) comparison instead of == for required_version #6729.

Test plan

  • cargo test --lib required_version — all 19 existing tests pass unchanged;
    none of them depended on the old exact-only default (they all either use
    the current version as its own requirement, an explicit operator, or a
    requirement whose major/minor already differs enough that caret vs. exact
    makes no difference).
  • cargo test --lib check_semver_version — 27 tests pass, including two new
    ones: test_default_caret_match (renamed from test_exact_version_match,
    with the two assertions that change under the new default flipped) and
    test_explicit_exact_match (covers the opt-in = exact-match path).
  • cargo test --lib (full suite, binary built first): 235 passed; 0 failed.

required_version currently treats a bare version (no comparator prefix)
as an exact match, overriding the semver crate's own default of a caret
requirement. This diverges from how Cargo treats dependency version
requirements with no operator.

Remove the override so a bare version behaves like `^version`, matching
Cargo's convention. The old exact-match behavior is still available by
opting in explicitly with `=`.

Closes rust-lang#6729
Copilot AI lite review requested due to automatic review settings August 22, 2026 20:06
@rustbot rustbot added the S-waiting-on-review Status: awaiting review from the assignee but also interested parties. label Aug 22, 2026

Copilot AI 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.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

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

functionally looks good, I had some thoughts on some of the comments.

View changes since this review

Comment thread src/config/mod.rs Outdated
Comment thread src/config/mod.rs Outdated
Comment thread Configurations.md Outdated
Drop the now-unnecessary old-behavior explanations from the
check_semver_version comment and the test_explicit_exact_match
test, and combine the Configurations.md caret-default note with
an equivalent bare-version example.
@wesleymatosdev

Copy link
Copy Markdown
Contributor Author

suggestions applied. Thank you for reviewing it @matthewhughes934

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

Labels

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.

Use caret (^) comparison instead of == for required_version

4 participants