Skip to content

Commit 2ce99b0

Browse files
authored
Merge branch 'master' into issue-6470-dont-delete-white-space-on-triple-colon
2 parents 6b3cdb3 + c6c8159 commit 2ce99b0

File tree

6 files changed

+558
-52
lines changed

6 files changed

+558
-52
lines changed

Cargo.lock

Lines changed: 13 additions & 12 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
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

Lines changed: 74 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -537,14 +537,17 @@ Specifies which edition is used by the parser.
537537
- **Possible values**: `"2015"`, `"2018"`, `"2021"`, `"2024"`
538538
- **Stable**: Yes
539539

540-
Rustfmt is able to pick up the edition used by reading the `Cargo.toml` file if executed
541-
through the Cargo's formatting tool `cargo fmt`. Otherwise, the edition needs to be specified
542-
in your config file:
540+
The `edition` option determines the Rust language edition used for parsing the code. This is important for syntax compatibility but does not directly control formatting behavior (see [style_edition](#style_edition)).
541+
542+
When running `cargo fmt`, the `edition` is automatically read from the `Cargo.toml` file. However, when running `rustfmt` directly the `edition` defaults to 2015 if not explicitly configured. For consistent parsing between rustfmt and `cargo fmt` you should configure the `edition`.
543+
For example in your `rustfmt.toml` file:
543544

544545
```toml
545546
edition = "2018"
546547
```
547548

549+
Alternatively, you can use the `--edition` flag when running `rustfmt` directly.
550+
548551
## `empty_item_single_line`
549552

550553
Put empty-body functions and impls on a single line
@@ -2412,9 +2415,62 @@ Require a specific version of rustfmt. If you want to make sure that the
24122415
specific version of rustfmt is used in your CI, use this option.
24132416

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

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

24202476
The width threshold for an array element to be considered "short".
@@ -2750,6 +2806,20 @@ Controls the edition of the [Rust Style Guide] to use for formatting ([RFC 3338]
27502806
- **Possible values**: `"2015"`, `"2018"`, `"2021"`, `"2024"` (unstable variant)
27512807
- **Stable**: No
27522808

2809+
This option is inferred from the [`edition`](#edition) if not specified.
2810+
2811+
See [Rust Style Editions] for details on formatting differences between style editions.
2812+
rustfmt has a default style edition of `2015` while `cargo fmt` infers the style edition from the `edition` set in `Cargo.toml`. This can lead to inconsistencies between `rustfmt` and `cargo fmt` if the style edition is not explicitly configured.
2813+
2814+
To ensure consistent formatting, it is recommended to specify the `style_edition` in a `rustfmt.toml` configuration file. For example:
2815+
2816+
```toml
2817+
style_edition = "2024"
2818+
```
2819+
2820+
Alternatively, you can use the `--style-edition` flag when running `rustfmt` directly.
2821+
2822+
[Rust Style Editions]: https://doc.rust-lang.org/nightly/style-guide/editions.html?highlight=editions#rust-style-editions
27532823
[Rust Style Guide]: https://doc.rust-lang.org/nightly/style-guide/
27542824
[RFC 3338]: https://rust-lang.github.io/rfcs/3338-style-evolution.html
27552825

README.md

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -170,12 +170,36 @@ See [GitHub page](https://rust-lang.github.io/rustfmt/) for details.
170170

171171
### Rust's Editions
172172

173-
Rustfmt is able to pick up the edition used by reading the `Cargo.toml` file if
174-
executed through the Cargo's formatting tool `cargo fmt`. Otherwise, the edition
175-
needs to be specified in `rustfmt.toml`, e.g., with `edition = "2018"`.
173+
The `edition` option determines the Rust language edition used for parsing the code. This is important for syntax compatibility but does not directly control formatting behavior (see [Style Editions](#style-editions)).
174+
175+
When running `cargo fmt`, the `edition` is automatically read from the `Cargo.toml` file. However, when running `rustfmt` directly the `edition` defaults to 2015 if not explicitly configured. For consistent parsing between rustfmt and `cargo fmt` you should configure the `edition`.
176+
For example in your `rustfmt.toml` file:
177+
178+
```toml
179+
edition = "2018"
180+
```
181+
182+
### Style Editions
183+
184+
This option is inferred from the [`edition`](#rusts-editions) if not specified.
185+
186+
See [Rust Style Editions] for details on formatting differences between style editions.
187+
rustfmt has a default style edition of `2015` while `cargo fmt` infers the style edition from the `edition` set in `Cargo.toml`. This can lead to inconsistencies between `rustfmt` and `cargo fmt` if the style edition is not explicitly configured.
188+
189+
To ensure consistent formatting, it is recommended to specify the `style_edition` in a `rustfmt.toml` configuration file. For example:
190+
191+
```toml
192+
style_edition = "2024"
193+
```
194+
[Rust Style Editions]: https://doc.rust-lang.org/nightly/style-guide/editions.html?highlight=editions#rust-style-editions
195+
[Rust Style Guide]: https://doc.rust-lang.org/nightly/style-guide/
196+
[RFC 3338]: https://rust-lang.github.io/rfcs/3338-style-evolution.html
176197

177198
## Tips
178199

200+
* To ensure consistent parsing between `cargo fmt` and `rustfmt`, you should configure the [`edition`](#rusts-editions) in your `rustfmt.toml` file.
201+
* To ensure consistent formatting between `cargo fmt` and `rustfmt`, you should configure the [`style_edition`](#style-editions) in your `rustfmt.toml` file.
202+
179203
* For things you do not want rustfmt to mangle, use `#[rustfmt::skip]`
180204
* To prevent rustfmt from formatting a macro or an attribute,
181205
use `#[rustfmt::skip::macros(target_macro_name)]` or

docs/index.html

Lines changed: 19 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,6 @@
108108
</div>
109109
<script>
110110
const RustfmtTagsUrl = 'https://api.github.com/repos/rust-lang/rustfmt/tags';
111-
const RustfmtLatestUrl = 'https://api.github.com/repos/rust-lang/rustfmt/releases/latest';
112111
const UrlHash = window.location.hash.replace(/^#/, '');
113112
const queryParams = new URLSearchParams(window.location.search);
114113
const searchParam = queryParams.get('search');
@@ -134,18 +133,25 @@
134133
scrolledOnce: false,
135134
},
136135
asyncComputed: {
137-
async updateVersion() {
138-
let latest;
139-
try {
140-
latest = (await axios.get(RustfmtLatestUrl)).data;
141-
} catch(err) {
142-
console.log(err);
143-
return;
144-
}
145-
if (versionParam == null) {
146-
this.viewVersion = latest.name;
147-
}
148-
},
136+
async pullTags() {
137+
let tags;
138+
try {
139+
tags = (await axios.get(RustfmtTagsUrl)).data;
140+
} catch(e) {
141+
this.handleReqFailure(e);
142+
return;
143+
}
144+
145+
const excludedTagVersions = new Set(['v0.7', 'v0.8.1']);
146+
147+
const tagOptions = tags
148+
.map(tag => tag.name)
149+
.filter(tag => tag.startsWith('v') && !excludedTagVersions.has(tag));
150+
151+
const latestRelease = tagOptions.find(tag => !tag.includes('rc'));
152+
this.viewVersion = latestRelease;
153+
this.versionOptions = this.versionOptions.concat(tagOptions);
154+
},
149155
async outputHtml() {
150156
if (this.viewVersion !== this.oldViewVersion) {
151157
const ConfigurationMdUrl =
@@ -207,22 +213,6 @@
207213
});
208214
}
209215
},
210-
created: async function() {
211-
let tags;
212-
try {
213-
tags = (await axios.get(RustfmtTagsUrl)).data;
214-
} catch(e) {
215-
this.handleReqFailure(e);
216-
return;
217-
}
218-
219-
const excludedTagVersions = new Set(['v0.7', 'v0.8.1']);
220-
221-
const tagOptions = tags
222-
.map(tag => tag.name)
223-
.filter(tag => tag.startsWith('v') && !excludedTagVersions.has(tag));
224-
this.versionOptions = this.versionOptions.concat(tagOptions);
225-
},
226216
updated() {
227217
if (UrlHash === '') return;
228218
this.$nextTick(() => {

0 commit comments

Comments
 (0)