Skip to content

Commit 4621915

Browse files
Merge remote-tracking branch 'upstream/master' into rustup-2021-11-s1
2 parents bf3c52f + e4472d3 commit 4621915

Some content is hidden

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

58 files changed

+669
-371
lines changed

Diff for: .github/workflows/rustdoc_check.yml

+25
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

Diff for: Configurations.md

+18-1
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.

Diff for: Contributing.md

+1-1
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

Diff for: README.md

+21-2
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

Diff for: appveyor.yml

-8
This file was deleted.

Diff for: intellij.md

+16-7
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

Diff for: legacy-rustfmt.toml

-2
This file was deleted.

Diff for: src/attr.rs

+2-2
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');

Diff for: src/attr/doc_comment.rs

+1-1
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
}

Diff for: src/bin/main.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ use crate::rustfmt::{
2020
};
2121

2222
fn main() {
23-
env_logger::init();
23+
env_logger::Builder::from_env("RUSTFMT_LOG").init();
2424
let opts = make_opts();
2525

2626
let exit_code = match execute(&opts) {

Diff for: src/cargo-fmt/main.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -401,12 +401,12 @@ fn get_targets_root_only(
401401

402402
fn get_targets_recursive(
403403
manifest_path: Option<&Path>,
404-
mut targets: &mut BTreeSet<Target>,
404+
targets: &mut BTreeSet<Target>,
405405
visited: &mut BTreeSet<String>,
406406
) -> Result<(), io::Error> {
407407
let metadata = get_cargo_metadata(manifest_path)?;
408408
for package in &metadata.packages {
409-
add_targets(&package.targets, &mut targets);
409+
add_targets(&package.targets, targets);
410410

411411
// Look for local dependencies using information available since cargo v1.51
412412
// It's theoretically possible someone could use a newer version of rustfmt with
@@ -427,7 +427,7 @@ fn get_targets_recursive(
427427
.any(|p| p.manifest_path.eq(&manifest_path))
428428
{
429429
visited.insert(dependency.name.to_owned());
430-
get_targets_recursive(Some(&manifest_path), &mut targets, visited)?;
430+
get_targets_recursive(Some(&manifest_path), targets, visited)?;
431431
}
432432
}
433433
}

Diff for: src/chains.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -568,7 +568,7 @@ impl<'a> ChainFormatterShared<'a> {
568568
} else {
569569
self.rewrites
570570
.iter()
571-
.map(|rw| utils::unicode_str_width(&rw))
571+
.map(|rw| utils::unicode_str_width(rw))
572572
.sum()
573573
} + last.tries;
574574
let one_line_budget = if self.child_count == 1 {
@@ -673,7 +673,7 @@ impl<'a> ChainFormatterShared<'a> {
673673
ChainItemKind::Comment(_, CommentPosition::Top) => result.push_str(&connector),
674674
_ => result.push_str(&connector),
675675
}
676-
result.push_str(&rewrite);
676+
result.push_str(rewrite);
677677
}
678678

679679
Some(result)

Diff for: src/comment.rs

+9-9
Original file line numberDiff line numberDiff line change
@@ -405,7 +405,7 @@ impl CodeBlockAttribute {
405405
/// attributes are valid rust attributes
406406
/// See <https://doc.rust-lang.org/rustdoc/print.html#attributes>
407407
fn new(attributes: &str) -> CodeBlockAttribute {
408-
for attribute in attributes.split(",") {
408+
for attribute in attributes.split(',') {
409409
match attribute.trim() {
410410
"" | "rust" | "should_panic" | "no_run" | "edition2015" | "edition2018"
411411
| "edition2021" => (),
@@ -563,7 +563,7 @@ impl<'a> CommentRewrite<'a> {
563563
result.push_str(line);
564564
result.push_str(match iter.peek() {
565565
Some(next_line) if next_line.is_empty() => sep.trim_end(),
566-
Some(..) => &sep,
566+
Some(..) => sep,
567567
None => "",
568568
});
569569
}
@@ -622,7 +622,7 @@ impl<'a> CommentRewrite<'a> {
622622
let is_last = i == count_newlines(orig);
623623

624624
if let Some(ref mut ib) = self.item_block {
625-
if ib.add_line(&line) {
625+
if ib.add_line(line) {
626626
return false;
627627
}
628628
self.is_prev_line_multi_line = false;
@@ -684,8 +684,8 @@ impl<'a> CommentRewrite<'a> {
684684
self.item_block = None;
685685
if let Some(stripped) = line.strip_prefix("```") {
686686
self.code_block_attr = Some(CodeBlockAttribute::new(stripped))
687-
} else if self.fmt.config.wrap_comments() && ItemizedBlock::is_itemized_line(&line) {
688-
let ib = ItemizedBlock::new(&line);
687+
} else if self.fmt.config.wrap_comments() && ItemizedBlock::is_itemized_line(line) {
688+
let ib = ItemizedBlock::new(line);
689689
self.item_block = Some(ib);
690690
return false;
691691
}
@@ -941,7 +941,7 @@ fn left_trim_comment_line<'a>(line: &'a str, style: &CommentStyle<'_>) -> (&'a s
941941
{
942942
(&line[4..], true)
943943
} else if let CommentStyle::Custom(opener) = *style {
944-
if let Some(ref stripped) = line.strip_prefix(opener) {
944+
if let Some(stripped) = line.strip_prefix(opener) {
945945
(stripped, true)
946946
} else {
947947
(&line[opener.trim_end().len()..], false)
@@ -1384,7 +1384,7 @@ impl<'a> Iterator for LineClasses<'a> {
13841384
None => unreachable!(),
13851385
};
13861386

1387-
while let Some((kind, c)) = self.base.next() {
1387+
for (kind, c) in self.base.by_ref() {
13881388
// needed to set the kind of the ending character on the last line
13891389
self.kind = kind;
13901390
if c == '\n' {
@@ -1570,7 +1570,7 @@ pub(crate) fn recover_comment_removed(
15701570
context.parse_sess.span_to_filename(span),
15711571
vec![FormattingError::from_span(
15721572
span,
1573-
&context.parse_sess,
1573+
context.parse_sess,
15741574
ErrorKind::LostComment,
15751575
)],
15761576
);
@@ -1675,7 +1675,7 @@ impl<'a> Iterator for CommentReducer<'a> {
16751675
fn remove_comment_header(comment: &str) -> &str {
16761676
if comment.starts_with("///") || comment.starts_with("//!") {
16771677
&comment[3..]
1678-
} else if let Some(ref stripped) = comment.strip_prefix("//") {
1678+
} else if let Some(stripped) = comment.strip_prefix("//") {
16791679
stripped
16801680
} else if (comment.starts_with("/**") && !comment.starts_with("/**/"))
16811681
|| comment.starts_with("/*!")

Diff for: src/config/options.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ pub enum NewlineStyle {
2020
Windows,
2121
/// Force CR (`\n).
2222
Unix,
23-
/// `\r\n` in Windows, `\n`` on other platforms.
23+
/// `\r\n` in Windows, `\n` on other platforms.
2424
Native,
2525
}
2626

@@ -112,6 +112,8 @@ pub enum GroupImportsTactic {
112112
/// 2. other imports
113113
/// 3. `self` / `crate` / `super` imports
114114
StdExternalCrate,
115+
/// Discard existing groups, and create a single group for everything
116+
One,
115117
}
116118

117119
#[config_type]

Diff for: src/emitter/checkstyle.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -121,15 +121,15 @@ mod tests {
121121
format!(r#"<file name="{}">"#, bin_file),
122122
format!(
123123
r#"<error line="2" severity="warning" message="Should be `{}`" />"#,
124-
XmlEscaped(&r#" println!("Hello, world!");"#),
124+
XmlEscaped(r#" println!("Hello, world!");"#),
125125
),
126126
String::from("</file>"),
127127
];
128128
let exp_lib_xml = vec![
129129
format!(r#"<file name="{}">"#, lib_file),
130130
format!(
131131
r#"<error line="2" severity="warning" message="Should be `{}`" />"#,
132-
XmlEscaped(&r#" println!("Greetings!");"#),
132+
XmlEscaped(r#" println!("Greetings!");"#),
133133
),
134134
String::from("</file>"),
135135
];

Diff for: src/emitter/diff.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ impl Emitter for DiffEmitter {
2323
}: FormattedFile<'_>,
2424
) -> Result<EmitterResult, io::Error> {
2525
const CONTEXT_SIZE: usize = 3;
26-
let mismatch = make_diff(&original_text, formatted_text, CONTEXT_SIZE);
26+
let mismatch = make_diff(original_text, formatted_text, CONTEXT_SIZE);
2727
let has_diff = !mismatch.is_empty();
2828

2929
if has_diff {

0 commit comments

Comments
 (0)