Skip to content

Commit 102a06b

Browse files
Merge commit '4236289b75ee55c78538c749512cdbeea5e1c332' into update-rustfmt
2 parents 0ded6ad + 4236289 commit 102a06b

39 files changed

+276
-291
lines changed

Diff for: src/tools/rustfmt/Cargo.lock

+15-9
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
7373
checksum = "924c76597f0d9ca25d762c25a4d369d51267536465dc5064bdf0eb073ed477ea"
7474
dependencies = [
7575
"backtrace-sys",
76-
"cfg-if",
76+
"cfg-if 0.1.10",
7777
"libc",
7878
"rustc-demangle",
7979
]
@@ -162,6 +162,12 @@ version = "0.1.10"
162162
source = "registry+https://github.com/rust-lang/crates.io-index"
163163
checksum = "4785bdd1c96b2a846b2bd7cc02e86b6b3dbf14e7e53446c4f54c92a361040822"
164164

165+
[[package]]
166+
name = "cfg-if"
167+
version = "1.0.0"
168+
source = "registry+https://github.com/rust-lang/crates.io-index"
169+
checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
170+
165171
[[package]]
166172
name = "clap"
167173
version = "2.33.0"
@@ -207,7 +213,7 @@ version = "0.6.6"
207213
source = "registry+https://github.com/rust-lang/crates.io-index"
208214
checksum = "04973fa96e96579258a5091af6003abde64af786b860f18622b82e026cca60e6"
209215
dependencies = [
210-
"cfg-if",
216+
"cfg-if 0.1.10",
211217
"lazy_static",
212218
]
213219

@@ -218,7 +224,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
218224
checksum = "ce446db02cdc3165b94ae73111e570793400d0794e46125cc4056c81cbb039f4"
219225
dependencies = [
220226
"autocfg",
221-
"cfg-if",
227+
"cfg-if 0.1.10",
222228
"lazy_static",
223229
]
224230

@@ -245,7 +251,7 @@ version = "2.0.2"
245251
source = "registry+https://github.com/rust-lang/crates.io-index"
246252
checksum = "13aea89a5c93364a98e9b37b2fa237effbb694d5cfe01c5b70941f7eb087d5e3"
247253
dependencies = [
248-
"cfg-if",
254+
"cfg-if 0.1.10",
249255
"dirs-sys",
250256
]
251257

@@ -255,7 +261,7 @@ version = "0.3.4"
255261
source = "registry+https://github.com/rust-lang/crates.io-index"
256262
checksum = "afa0b23de8fd801745c471deffa6e12d248f962c9fd4b4c33787b055599bde7b"
257263
dependencies = [
258-
"cfg-if",
264+
"cfg-if 0.1.10",
259265
"libc",
260266
"redox_users",
261267
"winapi",
@@ -401,11 +407,11 @@ checksum = "f2f96b10ec2560088a8e76961b00d47107b3a625fecb76dedb29ee7ccbf98235"
401407

402408
[[package]]
403409
name = "log"
404-
version = "0.4.8"
410+
version = "0.4.14"
405411
source = "registry+https://github.com/rust-lang/crates.io-index"
406-
checksum = "14b6052be84e6b71ab17edffc2eeabf5c2c3ae1fdb464aae35ac50c67a44e1f7"
412+
checksum = "51b9bbe6c47d51fc3e1a9b945965946b4c44142ab8792c50835a980d362c2710"
407413
dependencies = [
408-
"cfg-if",
414+
"cfg-if 1.0.0",
409415
]
410416

411417
[[package]]
@@ -426,7 +432,7 @@ version = "0.3.3"
426432
source = "registry+https://github.com/rust-lang/crates.io-index"
427433
checksum = "a85ea9fc0d4ac0deb6fe7911d38786b32fc11119afd9e9d38b84ff691ce64220"
428434
dependencies = [
429-
"cfg-if",
435+
"cfg-if 0.1.10",
430436
]
431437

432438
[[package]]

Diff for: src/tools/rustfmt/Configurations.md

+19-5
Original file line numberDiff line numberDiff line change
@@ -1475,7 +1475,9 @@ Copyright 2018 The Rust Project Developers.`, etc.:
14751475

14761476
## `match_arm_blocks`
14771477

1478-
Wrap the body of arms in blocks when it does not fit on the same line with the pattern of arms
1478+
Controls whether arm bodies are wrapped in cases where the first line of the body cannot fit on the same line as the `=>` operator.
1479+
1480+
The Style Guide requires that bodies are block wrapped by default if a line break is required after the `=>`, but this option can be used to disable that behavior to prevent wrapping arm bodies in that event, so long as the body does not contain multiple statements nor line comments.
14791481

14801482
- **Default value**: `true`
14811483
- **Possible values**: `true`, `false`
@@ -1486,10 +1488,16 @@ Wrap the body of arms in blocks when it does not fit on the same line with the p
14861488
```rust
14871489
fn main() {
14881490
match lorem {
1489-
true => {
1491+
ipsum => {
14901492
foooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo(x)
14911493
}
1492-
false => println!("{}", sit),
1494+
dolor => println!("{}", sit),
1495+
sit => foo(
1496+
"foooooooooooooooooooooooo",
1497+
"baaaaaaaaaaaaaaaaaaaaaaaarr",
1498+
"baaaaaaaaaaaaaaaaaaaazzzzzzzzzzzzz",
1499+
"qqqqqqqqquuuuuuuuuuuuuuuuuuuuuuuuuuxxx",
1500+
),
14931501
}
14941502
}
14951503
```
@@ -1499,9 +1507,15 @@ fn main() {
14991507
```rust
15001508
fn main() {
15011509
match lorem {
1502-
true =>
1510+
lorem =>
15031511
foooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo(x),
1504-
false => println!("{}", sit),
1512+
ipsum => println!("{}", sit),
1513+
sit => foo(
1514+
"foooooooooooooooooooooooo",
1515+
"baaaaaaaaaaaaaaaaaaaaaaaarr",
1516+
"baaaaaaaaaaaaaaaaaaaazzzzzzzzzzzzz",
1517+
"qqqqqqqqquuuuuuuuuuuuuuuuuuuuuuuuuuxxx",
1518+
),
15051519
}
15061520
}
15071521
```

Diff for: src/tools/rustfmt/Contributing.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ and get a better grasp on the execution flow.
6565

6666
## Hack!
6767

68-
Here are some [good starting issues](https://github.com/rust-lang/rustfmt/issues?q=is%3Aopen+is%3Aissue+label%3Agood-first-issue).
68+
Here are some [good starting issues](https://github.com/rust-lang/rustfmt/issues?q=is%3Aopen+is%3Aissue+label%3A%22good+first+issue%22).
6969

7070
If you've found areas which need polish and don't have issues, please submit a
7171
PR, don't feel there needs to be an issue.
@@ -138,8 +138,8 @@ format.
138138

139139
There are different nodes for every kind of item and expression in Rust. For
140140
more details see the source code in the compiler -
141-
[ast.rs](https://dxr.mozilla.org/rust/source/src/libsyntax/ast.rs) - and/or the
142-
[docs](https://doc.rust-lang.org/nightly/nightly-rustc/syntax/ast/index.html).
141+
[ast.rs](https://github.com/rust-lang/rust/blob/master/compiler/rustc_ast/src/ast.rs) - and/or the
142+
[docs](https://doc.rust-lang.org/nightly/nightly-rustc/rustc_ast/ast/index.html).
143143

144144
Many nodes in the AST (but not all, annoyingly) have a `Span`. A `Span` is a
145145
range in the source code, it can easily be converted to a snippet of source

Diff for: src/tools/rustfmt/README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -230,5 +230,5 @@ Apache License (Version 2.0).
230230
See [LICENSE-APACHE](LICENSE-APACHE) and [LICENSE-MIT](LICENSE-MIT) for details.
231231

232232
[rust]: https://github.com/rust-lang/rust
233-
[fmt rfcs]: https://github.com/rust-lang-nursery/fmt-rfcs
234-
[style guide]: https://github.com/rust-lang-nursery/fmt-rfcs/blob/master/guide/guide.md
233+
[fmt rfcs]: https://github.com/rust-dev-tools/fmt-rfcs
234+
[style guide]: https://github.com/rust-dev-tools/fmt-rfcs/blob/master/guide/guide.md

Diff for: src/tools/rustfmt/appveyor.yml

+55-55
Original file line numberDiff line numberDiff line change
@@ -1,55 +1,55 @@
1-
# This is based on https://github.com/japaric/rust-everywhere/blob/master/appveyor.yml
2-
# and modified (mainly removal of deployment) to suit rustfmt.
3-
4-
environment:
5-
global:
6-
PROJECT_NAME: rustfmt
7-
matrix:
8-
# Stable channel
9-
# - TARGET: i686-pc-windows-gnu
10-
# CHANNEL: stable
11-
# - TARGET: i686-pc-windows-msvc
12-
# CHANNEL: stable
13-
# - TARGET: x86_64-pc-windows-gnu
14-
# CHANNEL: stable
15-
# - TARGET: x86_64-pc-windows-msvc
16-
# CHANNEL: stable
17-
# Beta channel
18-
# - TARGET: i686-pc-windows-gnu
19-
# CHANNEL: beta
20-
# - TARGET: i686-pc-windows-msvc
21-
# CHANNEL: beta
22-
# - TARGET: x86_64-pc-windows-gnu
23-
# CHANNEL: beta
24-
# - TARGET: x86_64-pc-windows-msvc
25-
# CHANNEL: beta
26-
# Nightly channel
27-
- TARGET: i686-pc-windows-gnu
28-
CHANNEL: nightly
29-
- TARGET: i686-pc-windows-msvc
30-
CHANNEL: nightly
31-
- TARGET: x86_64-pc-windows-gnu
32-
CHANNEL: nightly
33-
- TARGET: x86_64-pc-windows-msvc
34-
CHANNEL: nightly
35-
36-
# Install Rust and Cargo
37-
# (Based on from https://github.com/rust-lang/libc/blob/master/appveyor.yml)
38-
install:
39-
- appveyor-retry appveyor DownloadFile https://win.rustup.rs/ -FileName rustup-init.exe
40-
- if "%TARGET%" == "i686-pc-windows-gnu" set PATH=%PATH%;C:\msys64\mingw32\bin
41-
- if "%TARGET%" == "x86_64-pc-windows-gnu" set PATH=%PATH%;C:\msys64\mingw64\bin
42-
- set PATH=%PATH%;C:\Users\appveyor\.cargo\bin
43-
- rustup-init.exe --default-host %TARGET% --default-toolchain %CHANNEL% -y
44-
- rustc -Vv
45-
- cargo -V
46-
47-
# ???
48-
build: false
49-
50-
test_script:
51-
- set CFG_RELEASE_CHANNEL=nightly
52-
- set CFG_RELEASE=nightly
53-
- cargo build --verbose
54-
- cargo test
55-
- cargo test -- --ignored
1+
# This is based on https://github.com/japaric/rust-everywhere/blob/master/appveyor.yml
2+
# and modified (mainly removal of deployment) to suit rustfmt.
3+
4+
environment:
5+
global:
6+
PROJECT_NAME: rustfmt
7+
matrix:
8+
# Stable channel
9+
# - TARGET: i686-pc-windows-gnu
10+
# CHANNEL: stable
11+
# - TARGET: i686-pc-windows-msvc
12+
# CHANNEL: stable
13+
# - TARGET: x86_64-pc-windows-gnu
14+
# CHANNEL: stable
15+
# - TARGET: x86_64-pc-windows-msvc
16+
# CHANNEL: stable
17+
# Beta channel
18+
# - TARGET: i686-pc-windows-gnu
19+
# CHANNEL: beta
20+
# - TARGET: i686-pc-windows-msvc
21+
# CHANNEL: beta
22+
# - TARGET: x86_64-pc-windows-gnu
23+
# CHANNEL: beta
24+
# - TARGET: x86_64-pc-windows-msvc
25+
# CHANNEL: beta
26+
# Nightly channel
27+
- TARGET: i686-pc-windows-gnu
28+
CHANNEL: nightly
29+
- TARGET: i686-pc-windows-msvc
30+
CHANNEL: nightly
31+
- TARGET: x86_64-pc-windows-gnu
32+
CHANNEL: nightly
33+
- TARGET: x86_64-pc-windows-msvc
34+
CHANNEL: nightly
35+
36+
# Install Rust and Cargo
37+
# (Based on from https://github.com/rust-lang/libc/blob/master/appveyor.yml)
38+
install:
39+
- appveyor-retry appveyor DownloadFile https://win.rustup.rs/ -FileName rustup-init.exe
40+
- if "%TARGET%" == "i686-pc-windows-gnu" set PATH=%PATH%;C:\msys64\mingw32\bin
41+
- if "%TARGET%" == "x86_64-pc-windows-gnu" set PATH=%PATH%;C:\msys64\mingw64\bin
42+
- set PATH=%PATH%;C:\Users\appveyor\.cargo\bin
43+
- rustup-init.exe --default-host %TARGET% --default-toolchain %CHANNEL% -y
44+
- rustc -Vv
45+
- cargo -V
46+
47+
# ???
48+
build: false
49+
50+
test_script:
51+
- set CFG_RELEASE_CHANNEL=nightly
52+
- set CFG_RELEASE=nightly
53+
- cargo build --verbose
54+
- cargo test
55+
- cargo test -- --ignored

Diff for: src/tools/rustfmt/rust-toolchain

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
[toolchain]
2-
channel = "nightly-2021-05-13"
2+
channel = "nightly-2021-07-23"
33
components = ["rustc-dev"]

Diff for: src/tools/rustfmt/src/attr.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ fn format_derive(
183183
} else if let SeparatorTactic::Always = context.config.trailing_comma() {
184184
// Retain the trailing comma.
185185
result.push_str(&item_str);
186-
} else if item_str.ends_with(",") {
186+
} else if item_str.ends_with(',') {
187187
// Remove the trailing comma.
188188
result.push_str(&item_str[..item_str.len() - 1]);
189189
} else {

Diff for: src/tools/rustfmt/src/bin/main.rs

+11-7
Original file line numberDiff line numberDiff line change
@@ -178,12 +178,15 @@ fn make_opts() -> Options {
178178
opts.optflag("v", "verbose", "Print verbose output");
179179
opts.optflag("q", "quiet", "Print less output");
180180
opts.optflag("V", "version", "Show version information");
181-
opts.optflagopt(
182-
"h",
183-
"help",
184-
"Show this message or help about a specific topic: `config` or `file-lines`",
185-
"=TOPIC",
186-
);
181+
let help_topics = if is_nightly {
182+
"`config` or `file-lines`"
183+
} else {
184+
"`config`"
185+
};
186+
let mut help_topic_msg = "Show this message or help about a specific topic: ".to_owned();
187+
help_topic_msg.push_str(help_topics);
188+
189+
opts.optflagopt("h", "help", &help_topic_msg, "=TOPIC");
187190

188191
opts
189192
}
@@ -437,7 +440,7 @@ fn determine_operation(matches: &Matches) -> Result<Operation, OperationError> {
437440
return Ok(Operation::Help(HelpOp::None));
438441
} else if topic == Some("config".to_owned()) {
439442
return Ok(Operation::Help(HelpOp::Config));
440-
} else if topic == Some("file-lines".to_owned()) {
443+
} else if topic == Some("file-lines".to_owned()) && is_nightly() {
441444
return Ok(Operation::Help(HelpOp::FileLines));
442445
} else {
443446
return Err(OperationError::UnknownHelpTopic(topic.unwrap()));
@@ -689,6 +692,7 @@ fn edition_from_edition_str(edition_str: &str) -> Result<Edition> {
689692
match edition_str {
690693
"2015" => Ok(Edition::Edition2015),
691694
"2018" => Ok(Edition::Edition2018),
695+
"2021" => Ok(Edition::Edition2021),
692696
_ => Err(format_err!("Invalid value for `--edition`")),
693697
}
694698
}

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

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// Inspired by Paul Woolcock's cargo-fmt (https://github.com/pwoolcoc/cargo-fmt/).
22

33
#![deny(warnings)]
4+
#![allow(clippy::match_like_matches_macro)]
45

56
use std::cmp::Ordering;
67
use std::collections::{BTreeMap, BTreeSet};
@@ -405,8 +406,8 @@ fn get_targets_recursive(
405406
.packages
406407
.iter()
407408
.find(|p| p.name == dependency.name && p.source.is_none());
408-
let manifest_path = if dependency_package.is_some() {
409-
PathBuf::from(&dependency_package.unwrap().manifest_path)
409+
let manifest_path = if let Some(dep_pkg) = dependency_package {
410+
PathBuf::from(&dep_pkg.manifest_path)
410411
} else {
411412
let mut package_manifest_path = PathBuf::from(&package.manifest_path);
412413
package_manifest_path.pop();

Diff for: src/tools/rustfmt/src/chains.rs

+1-4
Original file line numberDiff line numberDiff line change
@@ -231,10 +231,7 @@ impl ChainItem {
231231
}
232232

233233
fn is_comment(&self) -> bool {
234-
match self.kind {
235-
ChainItemKind::Comment(..) => true,
236-
_ => false,
237-
}
234+
matches!(self.kind, ChainItemKind::Comment(..))
238235
}
239236

240237
fn rewrite_method_call(

Diff for: src/tools/rustfmt/src/closures.rs

+6-9
Original file line numberDiff line numberDiff line change
@@ -336,23 +336,23 @@ pub(crate) fn rewrite_last_closure(
336336

337337
// We force to use block for the body of the closure for certain kinds of expressions.
338338
if is_block_closure_forced(context, body) {
339-
return rewrite_closure_with_block(body, &prefix, context, body_shape).and_then(
339+
return rewrite_closure_with_block(body, &prefix, context, body_shape).map(
340340
|body_str| {
341341
match fn_decl.output {
342342
ast::FnRetTy::Default(..) if body_str.lines().count() <= 7 => {
343343
// If the expression can fit in a single line, we need not force block
344344
// closure. However, if the closure has a return type, then we must
345345
// keep the blocks.
346346
match rewrite_closure_expr(body, &prefix, context, shape) {
347-
Some(ref single_line_body_str)
347+
Some(single_line_body_str)
348348
if !single_line_body_str.contains('\n') =>
349349
{
350-
Some(single_line_body_str.clone())
350+
single_line_body_str
351351
}
352-
_ => Some(body_str),
352+
_ => body_str,
353353
}
354354
}
355-
_ => Some(body_str),
355+
_ => body_str,
356356
}
357357
},
358358
);
@@ -377,10 +377,7 @@ pub(crate) fn rewrite_last_closure(
377377
pub(crate) fn args_have_many_closure(args: &[OverflowableItem<'_>]) -> bool {
378378
args.iter()
379379
.filter_map(OverflowableItem::to_expr)
380-
.filter(|expr| match expr.kind {
381-
ast::ExprKind::Closure(..) => true,
382-
_ => false,
383-
})
380+
.filter(|expr| matches!(expr.kind, ast::ExprKind::Closure(..)))
384381
.count()
385382
> 1
386383
}

0 commit comments

Comments
 (0)