Skip to content

Commit

Permalink
Merge branch 'master' into format-brace-macros
Browse files Browse the repository at this point in the history
  • Loading branch information
trevyn authored Jan 27, 2024
2 parents d11223f + cedb7b5 commit bff2ab8
Show file tree
Hide file tree
Showing 74 changed files with 634 additions and 245 deletions.
14 changes: 7 additions & 7 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
}
```
- Prevent ICE when formatting `vec!{}` [#5735](https://github.com/rust-lang/rustfmt/issues/5735)
- Prevent internal trailing whitespace error when formatting an empty `macro_rules!` defintion e.g. `macro_rules! foo {}` [#5882](https://github.com/rust-lang/rustfmt/issues/5882)
- Prevent internal trailing whitespace error when formatting an empty `macro_rules!` definition e.g. `macro_rules! foo {}` [#5882](https://github.com/rust-lang/rustfmt/issues/5882)
- Formatting doc comment lines that start with `.` or `)` won't be treated as ordered markdown lists because `.` or `)` must be preceded by a number to start an ordered markdown list [#5835](https://github.com/rust-lang/rustfmt/pull/5835)
- Add parenthesis around closures when they're used as method receives, don't have a block body, and end with `.` [#4808](https://github.com/rust-lang/rustfmt/issues/4808)
```rust
Expand Down Expand Up @@ -184,7 +184,7 @@

- Simplify the rustfmt help text by eliding the full path to the rustfmt binary path from the usage string when running `rustfmt --help` [#5214](https://github.com/rust-lang/rustfmt/issues/5214)

- Bumped the version for serveral dependencies. Most notably `dirs` `v2.0.1` -> `v4.0.0`. This changed the global user config directory on macOS from `$HOME/Library/Preferences` to `$HOME/Library/Application Support` [#5237](https://github.com/rust-lang/rustfmt/pull/5237)
- Bumped the version for several dependencies. Most notably `dirs` `v2.0.1` -> `v4.0.0`. This changed the global user config directory on macOS from `$HOME/Library/Preferences` to `$HOME/Library/Application Support` [#5237](https://github.com/rust-lang/rustfmt/pull/5237)

### Fixed

Expand Down Expand Up @@ -942,7 +942,7 @@ from formatting an attribute #3665

### Fixed

- Do not remove path disambiugator inside macro #3142
- Do not remove path disambiguator inside macro #3142
- Improve handling of Windows newlines #3141
- Fix alignment of a struct's fields (`struct_field_align_threshold` option) with the Visual `indent_style` #3165
- Fix a bug in formatting markdown lists within comments #3172
Expand Down Expand Up @@ -1031,7 +1031,7 @@ from formatting an attribute #3665

### Changed

- Replace '--conifig-help' with '--config=help' cb10e06
- Replace '--config-help' with '--config=help' cb10e06
- Improve formatting of slice patterns #2912

### Fixed
Expand Down Expand Up @@ -1075,7 +1075,7 @@ from formatting an attribute #3665
- Add max_width option for all heuristics c2ae39e
- Add config option `format_macro_matchers` to format the metavariable matching patterns in macros 79c5ee8
- Add config option `format_macro_bodies` to format the bodies of macros 79c5ee8
- Format exitential type fc307ff
- Format existential type fc307ff
- Support raw identifiers in struct expressions f121b1a
- Format Async block and async function 0b25f60

Expand Down Expand Up @@ -1131,7 +1131,7 @@ from formatting an attribute #3665

### Changed

- Update rustc-ap-syntax to 128.0.0 and ustc-ap-rustc_target to 128.0.0 195395f
- Update rustc-ap-syntax to 128.0.0 and rustc-ap-rustc_target to 128.0.0 195395f
- Put operands on its own line when each fits in a single line f8439ce
- Improve CLI options 55ac062 1869888 798bffb 4d9de48 eca7796 8396da1 5d9f5aa

Expand Down Expand Up @@ -1195,7 +1195,7 @@ from formatting an attribute #3665
- Do not collapse block around expr with condition on match arm 5b9b7d5
- Use vertical layout for complex attributes c77708f
- Format array using heuristics for function calls 98c6f7b
- Implement stable ordering for impl items with the the following item priority: type, const, macro, then method fa80ddf
- Implement stable ordering for impl items with the following item priority: type, const, macro, then method fa80ddf
- Reorder imports by default 164cf7d
- Group `extern crate` by default 3a138a2
- Make `error_on_line_overflow` false by default f146711
Expand Down
4 changes: 2 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ diff = "0.1"
dirs = "4.0"
getopts = "0.2"
ignore = "0.4"
itertools = "0.10"
itertools = "0.11"
lazy_static = "1.4"
regex = "1.7"
serde = { version = "1.0.160", features = ["derive"] }
Expand Down
26 changes: 22 additions & 4 deletions Configurations.md
Original file line number Diff line number Diff line change
Expand Up @@ -1050,15 +1050,25 @@ Max width for code snippets included in doc comments. Only used if [`format_code

## `format_generated_files`

Format generated files. A file is considered generated
if any of the first five lines contain a `@generated` comment marker.
Format generated files. A file is considered generated if any of the first several lines contain a `@generated` comment marker. The number of lines to check is configured by `generated_marker_line_search_limit`.

By default, generated files are reformatted, i. e. `@generated` marker is ignored.
This option is currently ignored for stdin (`@generated` in stdin is ignored.)

- **Default value**: `true`
- **Possible values**: `true`, `false`
- **Stable**: No (tracking issue: [#5080](https://github.com/rust-lang/rustfmt/issues/5080))

## `generated_marker_line_search_limit`

Number of lines to check for a `@generated` pragma header, starting from the top of the file. Setting this value to `0` will treat all files as non-generated. When`format_generated_files` is `true`, this option has no effect.

- **Default value**: `5`
- **Possible values**: any positive integer
- **Stable**: No (tracking issue: [#5080](https://github.com/rust-lang/rustfmt/issues/5080))

See also [format_generated_files](#format_generated_files) link here.

## `format_macro_matchers`

Format the metavariable matching patterns in macros.
Expand Down Expand Up @@ -1268,12 +1278,20 @@ Control the case of the letters in hexadecimal literal values

## `hide_parse_errors`

Do not show parse errors if the parser failed to parse files.
This option is deprecated and has been renamed to `show_parse_errors` to avoid confusion around the double negative default of `hide_parse_errors=false`.

- **Default value**: `false`
- **Possible values**: `true`, `false`
- **Stable**: No (tracking issue: [#3390](https://github.com/rust-lang/rustfmt/issues/3390))

## `show_parse_errors`

Show parse errors if the parser failed to parse files.

- **Default value**: `true`
- **Possible values**: `true`, `false`
- **Stable**: No (tracking issue: [#5977](https://github.com/rust-lang/rustfmt/issues/5977))

## `ignore`

Skip formatting files and directories that match the specified pattern.
Expand Down Expand Up @@ -1675,7 +1693,7 @@ use core::slice;

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.
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 contains neither multiple statements nor line comments.

- **Default value**: `true`
- **Possible values**: `true`, `false`
Expand Down
2 changes: 1 addition & 1 deletion Processes.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ In this Section, we describe how to stabilise an option of the rustfmt's configu
Open a pull request that closes the tracking issue. The tracking issue is listed beside the option in `Configurations.md`.

- Update the `Config` enum marking the option as stable.
- Update the the `Configuration.md` file marking the option as stable.
- Update the `Configuration.md` file marking the option as stable.
- Update `CHANGELOG.md` marking the option as stable.

## After the stabilisation
Expand Down
4 changes: 2 additions & 2 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,15 @@ fn channel() -> String {

fn commit_hash() -> Option<String> {
Command::new("git")
.args(&["rev-parse", "--short", "HEAD"])
.args(["rev-parse", "--short", "HEAD"])
.output()
.ok()
.and_then(|r| String::from_utf8(r.stdout).ok())
}

fn commit_date() -> Option<String> {
Command::new("git")
.args(&["log", "-1", "--date=short", "--pretty=format:%cd"])
.args(["log", "-1", "--date=short", "--pretty=format:%cd"])
.output()
.ok()
.and_then(|r| String::from_utf8(r.stdout).ok())
Expand Down
12 changes: 6 additions & 6 deletions ci/check_diff.sh
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ function clone_repo() {
GIT_TERMINAL_PROMPT=0 git clone --quiet $1 --depth 1 $2 && cd $2
}

# Initialize Git submoduels for the repo.
# Initialize Git submodules for the repo.
#
# Parameters
# $1: list of directories to initialize
Expand All @@ -43,7 +43,7 @@ function init_submodules() {
# $2: Output file path for the diff
# $3: Any additional configuration options to pass to rustfmt
#
# Globlas:
# Globals:
# $OPTIONAL_RUSTFMT_CONFIGS: Optional configs passed to the script from $4
function create_diff() {
local config;
Expand All @@ -64,7 +64,7 @@ function create_diff() {
# Parameters
# $1: Name of the repository (used for logging)
#
# Globlas:
# Globals:
# $RUSFMT_BIN: Path to the rustfmt master binary. Created when running `compile_rustfmt`
# $FEATURE_BIN: Path to the rustfmt feature binary. Created when running `compile_rustfmt`
# $OPTIONAL_RUSTFMT_CONFIGS: Optional configs passed to the script from $4
Expand Down Expand Up @@ -101,7 +101,7 @@ function check_diff() {
# Parameters:
# $1: Directory where rustfmt will be cloned
#
# Globlas:
# Globals:
# $REMOTE_REPO: Clone URL to the rustfmt fork that we want to test
# $FEATURE_BRANCH: Name of the feature branch
# $OPTIONAL_COMMIT_HASH: Optional commit hash that will be checked out if provided
Expand All @@ -111,8 +111,8 @@ function compile_rustfmt() {
git remote add feature $REMOTE_REPO
git fetch feature $FEATURE_BRANCH

CARGO_VERSON=$(cargo --version)
echo -e "\ncompiling with $CARGO_VERSON\n"
CARGO_VERSION=$(cargo --version)
echo -e "\ncompiling with $CARGO_VERSION\n"

# Because we're building standalone binaries we need to set `LD_LIBRARY_PATH` so each
# binary can find it's runtime dependencies. See https://github.com/rust-lang/rustfmt/issues/5675
Expand Down
2 changes: 1 addition & 1 deletion intellij.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
- Open Rustfmt settings (File → Settings → Languages & Frameworks → Rust → Rustfmt) and enable "Run rustfmt on Save"
![run_rustfmt_on_save](https://user-images.githubusercontent.com/6505554/83944610-3468f380-a81e-11ea-9c34-0cbd18dd4969.png)

- IntellJ uses autosave, so now your files will always be formatted according to rustfmt. Alternatively you can use Ctrl+S to reformat file manually
- IntelliJ uses autosave, so now your files will always be formatted according to rustfmt. Alternatively you can use Ctrl+S to reformat file manually

### Bind shortcut to "Reformat File with Rustfmt" action

Expand Down
2 changes: 1 addition & 1 deletion rust-toolchain
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
[toolchain]
channel = "nightly-2023-10-22"
channel = "nightly-2023-12-28"
components = ["llvm-tools", "rustc-dev"]
17 changes: 6 additions & 11 deletions src/bin/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -387,16 +387,11 @@ fn format_and_emit_report<T: Write>(session: &mut Session<'_, T>, input: Input)
}

fn should_print_with_colors<T: Write>(session: &mut Session<'_, T>) -> bool {
match term::stderr() {
Some(ref t)
if session.config.color().use_colored_tty()
&& t.supports_color()
&& t.supports_attr(term::Attr::Bold) =>
{
true
}
_ => false,
}
term::stderr().is_some_and(|t| {
session.config.color().use_colored_tty()
&& t.supports_color()
&& t.supports_attr(term::Attr::Bold)
})
}

fn print_usage_to_stdout(opts: &Options, reason: &str) {
Expand Down Expand Up @@ -445,7 +440,7 @@ fn print_version() {
fn determine_operation(matches: &Matches) -> Result<Operation, OperationError> {
if matches.opt_present("h") {
let topic = matches.opt_str("h");
if topic == None {
if topic.is_none() {
return Ok(Operation::Help(HelpOp::None));
} else if topic == Some("config".to_owned()) {
return Ok(Operation::Help(HelpOp::Config));
Expand Down
2 changes: 1 addition & 1 deletion src/cargo-fmt/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -507,7 +507,7 @@ fn run_rustfmt(
let mut command = rustfmt_command()
.stdout(stdout)
.args(files)
.args(&["--edition", edition.as_str()])
.args(["--edition", edition.as_str()])
.args(fmt_args)
.spawn()
.map_err(|e| match e.kind() {
Expand Down
22 changes: 11 additions & 11 deletions src/cargo-fmt/test/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ fn default_options() {

#[test]
fn good_options() {
let o = Opts::parse_from(&[
let o = Opts::parse_from([
"test",
"-q",
"-p",
Expand Down Expand Up @@ -48,7 +48,7 @@ fn good_options() {
fn unexpected_option() {
assert!(
Opts::command()
.try_get_matches_from(&["test", "unexpected"])
.try_get_matches_from(["test", "unexpected"])
.is_err()
);
}
Expand All @@ -57,7 +57,7 @@ fn unexpected_option() {
fn unexpected_flag() {
assert!(
Opts::command()
.try_get_matches_from(&["test", "--flag"])
.try_get_matches_from(["test", "--flag"])
.is_err()
);
}
Expand All @@ -66,19 +66,19 @@ fn unexpected_flag() {
fn mandatory_separator() {
assert!(
Opts::command()
.try_get_matches_from(&["test", "--emit"])
.try_get_matches_from(["test", "--emit"])
.is_err()
);
assert!(
Opts::command()
.try_get_matches_from(&["test", "--", "--emit"])
.try_get_matches_from(["test", "--", "--emit"])
.is_ok()
);
}

#[test]
fn multiple_packages_one_by_one() {
let o = Opts::parse_from(&[
let o = Opts::parse_from([
"test",
"-p",
"package1",
Expand All @@ -92,7 +92,7 @@ fn multiple_packages_one_by_one() {

#[test]
fn multiple_packages_grouped() {
let o = Opts::parse_from(&[
let o = Opts::parse_from([
"test",
"--package",
"package1",
Expand All @@ -108,7 +108,7 @@ fn multiple_packages_grouped() {
fn empty_packages_1() {
assert!(
Opts::command()
.try_get_matches_from(&["test", "-p"])
.try_get_matches_from(["test", "-p"])
.is_err()
);
}
Expand All @@ -117,7 +117,7 @@ fn empty_packages_1() {
fn empty_packages_2() {
assert!(
Opts::command()
.try_get_matches_from(&["test", "-p", "--", "--check"])
.try_get_matches_from(["test", "-p", "--", "--check"])
.is_err()
);
}
Expand All @@ -126,7 +126,7 @@ fn empty_packages_2() {
fn empty_packages_3() {
assert!(
Opts::command()
.try_get_matches_from(&["test", "-p", "--verbose"])
.try_get_matches_from(["test", "-p", "--verbose"])
.is_err()
);
}
Expand All @@ -135,7 +135,7 @@ fn empty_packages_3() {
fn empty_packages_4() {
assert!(
Opts::command()
.try_get_matches_from(&["test", "-p", "--check"])
.try_get_matches_from(["test", "-p", "--check"])
.is_err()
);
}
Loading

0 comments on commit bff2ab8

Please sign in to comment.