Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit 30fb124

Browse files
Merge commit 'ea199bacef07213dbe008841b89c450e3bf0c638' into rustfmt-sync
2 parents 46b8e74 + ea199ba commit 30fb124

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

59 files changed

+670
-372
lines changed
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
name: rustdoc check
2+
on:
3+
push:
4+
branches:
5+
- master
6+
pull_request:
7+
8+
jobs:
9+
rustdoc_check:
10+
runs-on: ubuntu-latest
11+
name: rustdoc check
12+
steps:
13+
- name: checkout
14+
uses: actions/checkout@v2
15+
16+
- name: install rustup
17+
run: |
18+
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs > rustup-init.sh
19+
sh rustup-init.sh -y --default-toolchain none
20+
rustup target add x86_64-unknown-linux-gnu
21+
22+
- name: document rustfmt
23+
env:
24+
RUSTDOCFLAGS: --document-private-items --enable-index-page --show-type-layout --generate-link-to-definition -Zunstable-options -Dwarnings
25+
run: cargo doc -Zskip-rustdoc-fingerprint --no-deps -p rustfmt-nightly -p rustfmt-config_proc_macro

src/tools/rustfmt/Configurations.md

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2062,7 +2062,7 @@ use sit;
20622062
Controls the strategy for how imports are grouped together.
20632063

20642064
- **Default value**: `Preserve`
2065-
- **Possible values**: `Preserve`, `StdExternalCrate`
2065+
- **Possible values**: `Preserve`, `StdExternalCrate`, `One`
20662066
- **Stable**: No
20672067

20682068
#### `Preserve` (default):
@@ -2108,6 +2108,23 @@ use super::update::convert_publish_payload;
21082108
use crate::models::Event;
21092109
```
21102110

2111+
#### `One`:
2112+
2113+
Discard existing import groups, and create a single group for everything
2114+
2115+
```rust
2116+
use super::schema::{Context, Payload};
2117+
use super::update::convert_publish_payload;
2118+
use crate::models::Event;
2119+
use alloc::alloc::Layout;
2120+
use broker::database::PooledConnection;
2121+
use chrono::Utc;
2122+
use core::f32;
2123+
use juniper::{FieldError, FieldResult};
2124+
use std::sync::Arc;
2125+
use uuid::Uuid;
2126+
```
2127+
21112128
## `reorder_modules`
21122129

21132130
Reorder `mod` declarations alphabetically in group.

src/tools/rustfmt/Contributing.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ example, the `issue-1111.rs` test file is configured by the file
5959
## Debugging
6060

6161
Some `rewrite_*` methods use the `debug!` macro for printing useful information.
62-
These messages can be printed by using the environment variable `RUST_LOG=rustfmt=DEBUG`.
62+
These messages can be printed by using the environment variable `RUSTFMT_LOG=rustfmt=DEBUG`.
6363
These traces can be helpful in understanding which part of the code was used
6464
and get a better grasp on the execution flow.
6565

src/tools/rustfmt/README.md

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ cargo +nightly fmt
4747

4848
## Limitations
4949

50-
Rustfmt tries to work on as much Rust code as possible, sometimes, the code
50+
Rustfmt tries to work on as much Rust code as possible. Sometimes, the code
5151
doesn't even need to compile! As we approach a 1.0 release we are also looking
5252
to limit areas of instability; in particular, post-1.0, the formatting of most
5353
code should not change as Rustfmt improves. However, there are some things that
@@ -102,6 +102,25 @@ read data from stdin. Alternatively, you can use `cargo fmt` to format all
102102
binary and library targets of your crate.
103103

104104
You can run `rustfmt --help` for information about available arguments.
105+
The easiest way to run rustfmt against a project is with `cargo fmt`. `cargo fmt` works on both
106+
single-crate projects and [cargo workspaces](https://doc.rust-lang.org/book/ch14-03-cargo-workspaces.html).
107+
Please see `cargo fmt --help` for usage information.
108+
109+
You can specify the path to your own `rustfmt` binary for cargo to use by setting the`RUSTFMT`
110+
environment variable. This was added in v1.4.22, so you must have this version or newer to leverage this feature (`cargo fmt --version`)
111+
112+
### Running `rustfmt` directly
113+
114+
To format individual files or arbitrary codes from stdin, the `rustfmt` binary should be used. Some
115+
examples follow:
116+
117+
- `rustfmt lib.rs main.rs` will format "lib.rs" and "main.rs" in place
118+
- `rustfmt` will read a code from stdin and write formatting to stdout
119+
- `echo "fn main() {}" | rustfmt` would emit "fn main() {}".
120+
121+
For more information, including arguments and emit options, see `rustfmt --help`.
122+
123+
### Verifying code is formatted
105124

106125
When running with `--check`, Rustfmt will exit with `0` if Rustfmt would not
107126
make any formatting changes to the input, and `1` if Rustfmt would make changes.
@@ -129,7 +148,7 @@ rustfmt to exit with an error code if the input is not formatted correctly.
129148
It will also print any found differences. (Older versions of Rustfmt don't
130149
support `--check`, use `--write-mode diff`).
131150

132-
A minimal Travis setup could look like this (requires Rust 1.24.0 or greater):
151+
A minimal Travis setup could look like this (requires Rust 1.31.0 or greater):
133152

134153
```yaml
135154
language: rust

src/tools/rustfmt/appveyor.yml

Lines changed: 0 additions & 8 deletions
This file was deleted.

src/tools/rustfmt/intellij.md

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,28 @@
33
## Installation
44

55
- Install [CLion](https://www.jetbrains.com/clion/), [IntelliJ Ultimate or CE](https://www.jetbrains.com/idea/) through the direct download link or using the [JetBrains Toolbox](https://www.jetbrains.com/toolbox/).
6-
CLion provides a built-in debugger interface but its not free like IntelliJ CE - which does not provide the debugger interface. (IntelliJ seems to lack the toolchain for that, see this discussion [intellij-rust/issues/535](https://github.com/intellij-rust/intellij-rust/issues/535))
7-
8-
- Install the [Rust Plugin](https://intellij-rust.github.io/) by navigating to File -> Settings -> Plugins and press "Install JetBrains Plugin"
9-
![plugins](https://user-images.githubusercontent.com/1133787/47240861-f40af680-d3e9-11e8-9b82-cdd5c8d5f5b8.png)
6+
CLion and IntelliJ Ultimate [provide a built-in debugger interface](https://github.com/intellij-rust/intellij-rust#compatible-ides) but they are not free like IntelliJ CE.
7+
8+
- Install the [Rust Plugin](https://intellij-rust.github.io/) by navigating to File Settings Plugins and searching the plugin in the Marketplace
9+
![plugins](https://user-images.githubusercontent.com/6505554/83944518-6f1e5c00-a81d-11ea-9c35-e16948811ba8.png)
1010

11-
- Press "Install" on the rust plugin
12-
![install rust](https://user-images.githubusercontent.com/1133787/47240803-c0c86780-d3e9-11e8-9265-22f735e4d7ed.png)
11+
- Press "Install" on the Rust plugin
12+
![install rust](https://user-images.githubusercontent.com/6505554/83944533-82c9c280-a81d-11ea-86b3-ee2e31bc7d12.png)
1313

1414
- Restart CLion/IntelliJ
1515

1616
## Configuration
1717

18-
- Open the settings window (File -> Settings) and search for "reformat"
18+
### Run Rustfmt on save
19+
20+
- Open Rustfmt settings (File → Settings → Languages & Frameworks → Rust → Rustfmt) and enable "Run rustfmt on Save"
21+
![run_rustfmt_on_save](https://user-images.githubusercontent.com/6505554/83944610-3468f380-a81e-11ea-9c34-0cbd18dd4969.png)
22+
23+
- IntellJ uses autosave, so now your files will always be formatted according to rustfmt. Alternatively you can use Ctrl+S to reformat file manually
24+
25+
### Bind shortcut to "Reformat File with Rustfmt" action
26+
27+
- Open the settings window (File → Settings) and search for "reformat"
1928
![keymap](https://user-images.githubusercontent.com/1133787/47240922-2ae10c80-d3ea-11e8-9d8f-c798d9749240.png)
2029
- Right-click on "Reformat File with Rustfmt" and assign a keyboard shortcut
2130

src/tools/rustfmt/legacy-rustfmt.toml

Lines changed: 0 additions & 2 deletions
This file was deleted.

src/tools/rustfmt/rust-toolchain

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
[toolchain]
2-
channel = "nightly-2021-10-20"
2+
channel = "nightly-2021-11-08"
33
components = ["rustc-dev"]

src/tools/rustfmt/src/attr.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -451,7 +451,7 @@ impl Rewrite for [ast::Attribute] {
451451
if next.is_doc_comment() {
452452
let snippet = context.snippet(missing_span);
453453
let (_, mlb) = has_newlines_before_after_comment(snippet);
454-
result.push_str(&mlb);
454+
result.push_str(mlb);
455455
}
456456
}
457457
result.push('\n');
@@ -484,7 +484,7 @@ impl Rewrite for [ast::Attribute] {
484484
if next.is_doc_comment() {
485485
let snippet = context.snippet(missing_span);
486486
let (_, mlb) = has_newlines_before_after_comment(snippet);
487-
result.push_str(&mlb);
487+
result.push_str(mlb);
488488
}
489489
}
490490
result.push('\n');

src/tools/rustfmt/src/attr/doc_comment.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ mod tests {
7777
) {
7878
assert_eq!(
7979
expected_comment,
80-
format!("{}", DocCommentFormatter::new(&literal, style))
80+
format!("{}", DocCommentFormatter::new(literal, style))
8181
);
8282
}
8383
}

0 commit comments

Comments
 (0)