rust-lang / rust-lang/rustfmt

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

Open
#6,729 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

C-feature-request
Dominant language
Rust
Stars
7k
Forks
1.1k
Avg merge
2d 13h
Merged PRs (30d)
24

Description

So, for context, we had only a text comparison for required_version param. Then, on #6066 I introduced semver library so we didn't had to fix this ourselves nor maintain this complexity on this codebase.

One thing tho, is that the only values available for required_version at the time, were exact versions, which would generate an exact match. Which means we were not semver-compliant.

At the time, as this made sense for me to not break change the implementation, we should use == as the default behavior, instead of ^ when there is no operator on it. Because of that, I even opened dtolnay/semver#311 asking semver maintainer to include the option to use other default operator.

The thing is, a few days ago the issue was closed, with this justification:

This diverges from how version requirements with no comparison operator are treated by Cargo.
source: https://github.com/dtolnay/semver/issues/311#issuecomment-3564029577

After digging a bit on that, according to The Cargo Book:

Caret requirements are the default version requirement strategy. This version strategy allows SemVer compatible updates. They are specified as version requirements with a leading caret (^).
source: https://doc.rust-lang.org/cargo/reference/specifying-dependencies.html#caret-requirements

With this information, it makes sense to make this semver-compliant and follow the default Cargo behavior.

TL;DR: We should do the same as cargo does and use ^ as the default comparator instead of == which was used to kept the behavior from before we introduced semver-compliant behavior with semver library.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

The issue names no files, tests, or entry points. Start by locating the handling of the required_version parameter and review the semver and Cargo caret-requirement references linked in the issue. Done means an omitted comparator follows Cargo's caret behavior instead of exact == matching, with existing behavior covered by tests.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.