Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update rustfmt #87468

Merged
merged 24 commits into from
Aug 2, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
d67f1a4
Update log to 0.4.14
jyn514 May 2, 2021
e243be6
Allow formatting `Anonymous{Struct, Union}` declarations
jedel1043 May 17, 2021
58c63cf
Add support for using qualified paths with structs in expression and …
rylev Dec 10, 2020
1e2258f
Use `AttrVec` for `Arm`, `FieldDef`, and `Variant`
JohnTitor Jun 16, 2021
2608f2c
fix(rustfmt): load nested out-of-line mods correctly
calebcartwright Jun 18, 2021
71f01d1
Delete spaces
Jun 21, 2021
d13020c
Rollup merge of #86274 - alexander-melentyev:spaces, r=bjorn3
JohnTitor Jun 21, 2021
0b8a26f
Rollup merge of #86424 - calebcartwright:rustfmt-mod-resolution, r=Ma…
JohnTitor Jun 21, 2021
33acc96
Document rustfmt on nightly-rustc
jyn514 Jun 30, 2021
abf449f
Rework SESSION_GLOBALS API to prevent overwriting it
GuillaumeGomez May 5, 2021
277feac
Use LocalExpnId where possible.
cjgillot Jun 25, 2021
bfd479d
Merge pull request #4920 from calebcartwright/subtree-sync
calebcartwright Jul 26, 2021
75765f6
Allow `--edition 2021` to be passed to rustfmt
PatchMixolydic May 22, 2021
1ca3798
Improve pasta copyability of `merge_imports` deprecation message
casey May 10, 2021
486e774
Adjusting help message (#4865)
murchu27 Jun 11, 2021
e634a6f
Updating outdated links (#4869)
murchu27 Jun 16, 2021
b305d62
fix: correct arm leading pipe check (#4880)
calebcartwright Jun 24, 2021
19733f1
Change line endings from CRLF to LF
Jun 25, 2021
2cf280e
docs: clarify match_arm_blocks config documentation
calebcartwright Jul 5, 2021
4c2959f
fix a bunch of clippy warnings
matthiaskrgr Jul 18, 2021
d42be80
chore: disable clippy::matches_like_macro lint
calebcartwright Jul 18, 2021
0832137
fix link in Contributing.md
ebobrow Jul 19, 2021
4236289
chore: bump toolchain
calebcartwright Jul 26, 2021
102a06b
Merge commit '4236289b75ee55c78538c749512cdbeea5e1c332' into update-r…
calebcartwright Jul 26, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 15 additions & 9 deletions src/tools/rustfmt/Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "924c76597f0d9ca25d762c25a4d369d51267536465dc5064bdf0eb073ed477ea"
dependencies = [
"backtrace-sys",
"cfg-if",
"cfg-if 0.1.10",
"libc",
"rustc-demangle",
]
Expand Down Expand Up @@ -162,6 +162,12 @@ version = "0.1.10"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4785bdd1c96b2a846b2bd7cc02e86b6b3dbf14e7e53446c4f54c92a361040822"

[[package]]
name = "cfg-if"
version = "1.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"

[[package]]
name = "clap"
version = "2.33.0"
Expand Down Expand Up @@ -207,7 +213,7 @@ version = "0.6.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "04973fa96e96579258a5091af6003abde64af786b860f18622b82e026cca60e6"
dependencies = [
"cfg-if",
"cfg-if 0.1.10",
"lazy_static",
]

Expand All @@ -218,7 +224,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ce446db02cdc3165b94ae73111e570793400d0794e46125cc4056c81cbb039f4"
dependencies = [
"autocfg",
"cfg-if",
"cfg-if 0.1.10",
"lazy_static",
]

Expand All @@ -245,7 +251,7 @@ version = "2.0.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "13aea89a5c93364a98e9b37b2fa237effbb694d5cfe01c5b70941f7eb087d5e3"
dependencies = [
"cfg-if",
"cfg-if 0.1.10",
"dirs-sys",
]

Expand All @@ -255,7 +261,7 @@ version = "0.3.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "afa0b23de8fd801745c471deffa6e12d248f962c9fd4b4c33787b055599bde7b"
dependencies = [
"cfg-if",
"cfg-if 0.1.10",
"libc",
"redox_users",
"winapi",
Expand Down Expand Up @@ -401,11 +407,11 @@ checksum = "f2f96b10ec2560088a8e76961b00d47107b3a625fecb76dedb29ee7ccbf98235"

[[package]]
name = "log"
version = "0.4.8"
version = "0.4.14"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "14b6052be84e6b71ab17edffc2eeabf5c2c3ae1fdb464aae35ac50c67a44e1f7"
checksum = "51b9bbe6c47d51fc3e1a9b945965946b4c44142ab8792c50835a980d362c2710"
dependencies = [
"cfg-if",
"cfg-if 1.0.0",
]

[[package]]
Expand All @@ -426,7 +432,7 @@ version = "0.3.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a85ea9fc0d4ac0deb6fe7911d38786b32fc11119afd9e9d38b84ff691ce64220"
dependencies = [
"cfg-if",
"cfg-if 0.1.10",
]

[[package]]
Expand Down
24 changes: 19 additions & 5 deletions src/tools/rustfmt/Configurations.md
Original file line number Diff line number Diff line change
Expand Up @@ -1475,7 +1475,9 @@ Copyright 2018 The Rust Project Developers.`, etc.:

## `match_arm_blocks`

Wrap the body of arms in blocks when it does not fit on the same line with the pattern of arms
Controls whether arm bodies are wrapped in cases where the first line of the body cannot fit on the same line as the `=>` operator.

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.

- **Default value**: `true`
- **Possible values**: `true`, `false`
Expand All @@ -1486,10 +1488,16 @@ Wrap the body of arms in blocks when it does not fit on the same line with the p
```rust
fn main() {
match lorem {
true => {
ipsum => {
foooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo(x)
}
false => println!("{}", sit),
dolor => println!("{}", sit),
sit => foo(
"foooooooooooooooooooooooo",
"baaaaaaaaaaaaaaaaaaaaaaaarr",
"baaaaaaaaaaaaaaaaaaaazzzzzzzzzzzzz",
"qqqqqqqqquuuuuuuuuuuuuuuuuuuuuuuuuuxxx",
),
}
}
```
Expand All @@ -1499,9 +1507,15 @@ fn main() {
```rust
fn main() {
match lorem {
true =>
lorem =>
foooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo(x),
false => println!("{}", sit),
ipsum => println!("{}", sit),
sit => foo(
"foooooooooooooooooooooooo",
"baaaaaaaaaaaaaaaaaaaaaaaarr",
"baaaaaaaaaaaaaaaaaaaazzzzzzzzzzzzz",
"qqqqqqqqquuuuuuuuuuuuuuuuuuuuuuuuuuxxx",
),
}
}
```
Expand Down
6 changes: 3 additions & 3 deletions src/tools/rustfmt/Contributing.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ and get a better grasp on the execution flow.

## Hack!

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

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

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

Many nodes in the AST (but not all, annoyingly) have a `Span`. A `Span` is a
range in the source code, it can easily be converted to a snippet of source
Expand Down
4 changes: 2 additions & 2 deletions src/tools/rustfmt/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -230,5 +230,5 @@ Apache License (Version 2.0).
See [LICENSE-APACHE](LICENSE-APACHE) and [LICENSE-MIT](LICENSE-MIT) for details.

[rust]: https://github.com/rust-lang/rust
[fmt rfcs]: https://github.com/rust-lang-nursery/fmt-rfcs
[style guide]: https://github.com/rust-lang-nursery/fmt-rfcs/blob/master/guide/guide.md
[fmt rfcs]: https://github.com/rust-dev-tools/fmt-rfcs
[style guide]: https://github.com/rust-dev-tools/fmt-rfcs/blob/master/guide/guide.md
110 changes: 55 additions & 55 deletions src/tools/rustfmt/appveyor.yml
Original file line number Diff line number Diff line change
@@ -1,55 +1,55 @@
# This is based on https://github.com/japaric/rust-everywhere/blob/master/appveyor.yml
# and modified (mainly removal of deployment) to suit rustfmt.
environment:
global:
PROJECT_NAME: rustfmt
matrix:
# Stable channel
# - TARGET: i686-pc-windows-gnu
# CHANNEL: stable
# - TARGET: i686-pc-windows-msvc
# CHANNEL: stable
# - TARGET: x86_64-pc-windows-gnu
# CHANNEL: stable
# - TARGET: x86_64-pc-windows-msvc
# CHANNEL: stable
# Beta channel
# - TARGET: i686-pc-windows-gnu
# CHANNEL: beta
# - TARGET: i686-pc-windows-msvc
# CHANNEL: beta
# - TARGET: x86_64-pc-windows-gnu
# CHANNEL: beta
# - TARGET: x86_64-pc-windows-msvc
# CHANNEL: beta
# Nightly channel
- TARGET: i686-pc-windows-gnu
CHANNEL: nightly
- TARGET: i686-pc-windows-msvc
CHANNEL: nightly
- TARGET: x86_64-pc-windows-gnu
CHANNEL: nightly
- TARGET: x86_64-pc-windows-msvc
CHANNEL: nightly
# Install Rust and Cargo
# (Based on from https://github.com/rust-lang/libc/blob/master/appveyor.yml)
install:
- appveyor-retry appveyor DownloadFile https://win.rustup.rs/ -FileName rustup-init.exe
- if "%TARGET%" == "i686-pc-windows-gnu" set PATH=%PATH%;C:\msys64\mingw32\bin
- if "%TARGET%" == "x86_64-pc-windows-gnu" set PATH=%PATH%;C:\msys64\mingw64\bin
- set PATH=%PATH%;C:\Users\appveyor\.cargo\bin
- rustup-init.exe --default-host %TARGET% --default-toolchain %CHANNEL% -y
- rustc -Vv
- cargo -V
# ???
build: false
test_script:
- set CFG_RELEASE_CHANNEL=nightly
- set CFG_RELEASE=nightly
- cargo build --verbose
- cargo test
- cargo test -- --ignored
# This is based on https://github.com/japaric/rust-everywhere/blob/master/appveyor.yml
# and modified (mainly removal of deployment) to suit rustfmt.

environment:
global:
PROJECT_NAME: rustfmt
matrix:
# Stable channel
# - TARGET: i686-pc-windows-gnu
# CHANNEL: stable
# - TARGET: i686-pc-windows-msvc
# CHANNEL: stable
# - TARGET: x86_64-pc-windows-gnu
# CHANNEL: stable
# - TARGET: x86_64-pc-windows-msvc
# CHANNEL: stable
# Beta channel
# - TARGET: i686-pc-windows-gnu
# CHANNEL: beta
# - TARGET: i686-pc-windows-msvc
# CHANNEL: beta
# - TARGET: x86_64-pc-windows-gnu
# CHANNEL: beta
# - TARGET: x86_64-pc-windows-msvc
# CHANNEL: beta
# Nightly channel
- TARGET: i686-pc-windows-gnu
CHANNEL: nightly
- TARGET: i686-pc-windows-msvc
CHANNEL: nightly
- TARGET: x86_64-pc-windows-gnu
CHANNEL: nightly
- TARGET: x86_64-pc-windows-msvc
CHANNEL: nightly

# Install Rust and Cargo
# (Based on from https://github.com/rust-lang/libc/blob/master/appveyor.yml)
install:
- appveyor-retry appveyor DownloadFile https://win.rustup.rs/ -FileName rustup-init.exe
- if "%TARGET%" == "i686-pc-windows-gnu" set PATH=%PATH%;C:\msys64\mingw32\bin
- if "%TARGET%" == "x86_64-pc-windows-gnu" set PATH=%PATH%;C:\msys64\mingw64\bin
- set PATH=%PATH%;C:\Users\appveyor\.cargo\bin
- rustup-init.exe --default-host %TARGET% --default-toolchain %CHANNEL% -y
- rustc -Vv
- cargo -V

# ???
build: false

test_script:
- set CFG_RELEASE_CHANNEL=nightly
- set CFG_RELEASE=nightly
- cargo build --verbose
- cargo test
- cargo test -- --ignored
2 changes: 1 addition & 1 deletion src/tools/rustfmt/rust-toolchain
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
[toolchain]
channel = "nightly-2021-05-13"
channel = "nightly-2021-07-23"
components = ["rustc-dev"]
2 changes: 1 addition & 1 deletion src/tools/rustfmt/src/attr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ fn format_derive(
} else if let SeparatorTactic::Always = context.config.trailing_comma() {
// Retain the trailing comma.
result.push_str(&item_str);
} else if item_str.ends_with(",") {
} else if item_str.ends_with(',') {
// Remove the trailing comma.
result.push_str(&item_str[..item_str.len() - 1]);
} else {
Expand Down
18 changes: 11 additions & 7 deletions src/tools/rustfmt/src/bin/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -178,12 +178,15 @@ fn make_opts() -> Options {
opts.optflag("v", "verbose", "Print verbose output");
opts.optflag("q", "quiet", "Print less output");
opts.optflag("V", "version", "Show version information");
opts.optflagopt(
"h",
"help",
"Show this message or help about a specific topic: `config` or `file-lines`",
"=TOPIC",
);
let help_topics = if is_nightly {
"`config` or `file-lines`"
} else {
"`config`"
};
let mut help_topic_msg = "Show this message or help about a specific topic: ".to_owned();
help_topic_msg.push_str(help_topics);

opts.optflagopt("h", "help", &help_topic_msg, "=TOPIC");

opts
}
Expand Down Expand Up @@ -437,7 +440,7 @@ fn determine_operation(matches: &Matches) -> Result<Operation, OperationError> {
return Ok(Operation::Help(HelpOp::None));
} else if topic == Some("config".to_owned()) {
return Ok(Operation::Help(HelpOp::Config));
} else if topic == Some("file-lines".to_owned()) {
} else if topic == Some("file-lines".to_owned()) && is_nightly() {
return Ok(Operation::Help(HelpOp::FileLines));
} else {
return Err(OperationError::UnknownHelpTopic(topic.unwrap()));
Expand Down Expand Up @@ -689,6 +692,7 @@ fn edition_from_edition_str(edition_str: &str) -> Result<Edition> {
match edition_str {
"2015" => Ok(Edition::Edition2015),
"2018" => Ok(Edition::Edition2018),
"2021" => Ok(Edition::Edition2021),
_ => Err(format_err!("Invalid value for `--edition`")),
}
}
Expand Down
5 changes: 3 additions & 2 deletions src/tools/rustfmt/src/cargo-fmt/main.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Inspired by Paul Woolcock's cargo-fmt (https://github.com/pwoolcoc/cargo-fmt/).

#![deny(warnings)]
#![allow(clippy::match_like_matches_macro)]

use std::cmp::Ordering;
use std::collections::{BTreeMap, BTreeSet};
Expand Down Expand Up @@ -405,8 +406,8 @@ fn get_targets_recursive(
.packages
.iter()
.find(|p| p.name == dependency.name && p.source.is_none());
let manifest_path = if dependency_package.is_some() {
PathBuf::from(&dependency_package.unwrap().manifest_path)
let manifest_path = if let Some(dep_pkg) = dependency_package {
PathBuf::from(&dep_pkg.manifest_path)
} else {
let mut package_manifest_path = PathBuf::from(&package.manifest_path);
package_manifest_path.pop();
Expand Down
5 changes: 1 addition & 4 deletions src/tools/rustfmt/src/chains.rs
Original file line number Diff line number Diff line change
Expand Up @@ -231,10 +231,7 @@ impl ChainItem {
}

fn is_comment(&self) -> bool {
match self.kind {
ChainItemKind::Comment(..) => true,
_ => false,
}
matches!(self.kind, ChainItemKind::Comment(..))
}

fn rewrite_method_call(
Expand Down
15 changes: 6 additions & 9 deletions src/tools/rustfmt/src/closures.rs
Original file line number Diff line number Diff line change
Expand Up @@ -336,23 +336,23 @@ pub(crate) fn rewrite_last_closure(

// We force to use block for the body of the closure for certain kinds of expressions.
if is_block_closure_forced(context, body) {
return rewrite_closure_with_block(body, &prefix, context, body_shape).and_then(
return rewrite_closure_with_block(body, &prefix, context, body_shape).map(
|body_str| {
match fn_decl.output {
ast::FnRetTy::Default(..) if body_str.lines().count() <= 7 => {
// If the expression can fit in a single line, we need not force block
// closure. However, if the closure has a return type, then we must
// keep the blocks.
match rewrite_closure_expr(body, &prefix, context, shape) {
Some(ref single_line_body_str)
Some(single_line_body_str)
if !single_line_body_str.contains('\n') =>
{
Some(single_line_body_str.clone())
single_line_body_str
}
_ => Some(body_str),
_ => body_str,
}
}
_ => Some(body_str),
_ => body_str,
}
},
);
Expand All @@ -377,10 +377,7 @@ pub(crate) fn rewrite_last_closure(
pub(crate) fn args_have_many_closure(args: &[OverflowableItem<'_>]) -> bool {
args.iter()
.filter_map(OverflowableItem::to_expr)
.filter(|expr| match expr.kind {
ast::ExprKind::Closure(..) => true,
_ => false,
})
.filter(|expr| matches!(expr.kind, ast::ExprKind::Closure(..)))
.count()
> 1
}
Expand Down
Loading