Skip to content

Commit 328f453

Browse files
feat: use semver to match required version (#6066)
implement `semver` checks for rustfmt's `required_version` config
1 parent 2ad782c commit 328f453

File tree

4 files changed

+492
-17
lines changed

4 files changed

+492
-17
lines changed

Cargo.lock

+13-12
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ unicode-width = "0.1"
5757
unicode-properties = { version = "0.1", default-features = false, features = ["general-category"] }
5858

5959
rustfmt-config_proc_macro = { version = "0.3", path = "config_proc_macro" }
60+
semver = "1.0.21"
6061

6162
# Rustc dependencies are loaded from the sysroot, Cargo doesn't know about them.
6263

Configurations.md

+54-1
Original file line numberDiff line numberDiff line change
@@ -2412,9 +2412,62 @@ Require a specific version of rustfmt. If you want to make sure that the
24122412
specific version of rustfmt is used in your CI, use this option.
24132413

24142414
- **Default value**: `CARGO_PKG_VERSION`
2415-
- **Possible values**: any published version (e.g. `"0.3.8"`)
2415+
- **Possible values**: `semver` compliant values, such as defined on [semver.org](https://semver.org/).
24162416
- **Stable**: No (tracking issue: [#3386](https://github.com/rust-lang/rustfmt/issues/3386))
24172417

2418+
#### Match on exact version:
2419+
2420+
```toml
2421+
required_version="1.0.0"
2422+
```
2423+
2424+
#### Higher or equal to:
2425+
2426+
```toml
2427+
required_version=">=1.0.0"
2428+
```
2429+
2430+
#### Lower or equal to:
2431+
2432+
```toml
2433+
required_version="<=1.0.0"
2434+
```
2435+
2436+
#### New minor or patch versions:
2437+
2438+
```toml
2439+
required_version="^1.0.0"
2440+
```
2441+
2442+
#### New patch versions:
2443+
2444+
```toml
2445+
required_version="~1.0.0"
2446+
```
2447+
2448+
#### Wildcard:
2449+
2450+
```toml
2451+
required_version="*" # matches any version.
2452+
required_version="1.*" # matches any version with the same major version
2453+
required_version="1.0.*" # matches any version with the same major and minor version
2454+
```
2455+
2456+
#### Multiple versions to match:
2457+
2458+
A comma separated list of version requirements.
2459+
The match succeeds when the current rustfmt version matches all version requirements.
2460+
2461+
The one notable exception is that a wildcard matching any version cannot be used in the list.
2462+
For example, `*, <1.0.0` will always fail.
2463+
2464+
Additionally, the version match will always fail if any of the version requirements contradict themselves.
2465+
Some examples of contradictory requirements are `1.*, >2.0.0`, `1.0.*, >2.0.0` and `<1.5.0, >1.10.*`.
2466+
2467+
```toml
2468+
required_version=">=1.0.0, <2.0.0"
2469+
```
2470+
24182471
## `short_array_element_width_threshold`
24192472

24202473
The width threshold for an array element to be considered "short".

0 commit comments

Comments
 (0)