Use caret (^) as the default required_version comparator - #7048
Open
wesleymatosdev wants to merge 2 commits into
Open
Use caret (^) as the default required_version comparator#7048wesleymatosdev wants to merge 2 commits into
wesleymatosdev wants to merge 2 commits into
Conversation
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
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.
Contributor
Author
|
suggestions applied. Thank you for reviewing it @matthewhughes934 |
matthewhughes934
approved these changes
Aug 23, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #6729
Summary
required_versioncurrently treats a bare version (no comparator prefix) asan exact match, overriding the
semvercrate's own default of a caretrequirement. 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_versionso a bare version behaveslike
^version, matching Cargo's convention. The old exact-match behavior isstill 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 toOp::Exact.Configurations.md: documents the new default, adds an explicit "Match onexact version" example using
=, and notes the caret-default in thePossible values bullet.
CHANGELOG.md: adds aChangedentry under[Unreleased]referencingUse caret (
^) comparison instead of==forrequired_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 newones:
test_default_caret_match(renamed fromtest_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.