Skip to content

Commit 151cf04

Browse files
committed
Merge remote-tracking branch 'upstream/master' into fix-inline_attribute_width
2 parents 5a2729b + b5dcc6f commit 151cf04

File tree

12 files changed

+197
-20
lines changed

12 files changed

+197
-20
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
## [Unreleased]
44

5+
- Updating `dirs 4.0.0 -> 5.0.1` and `cargo_metadata 0.15.4 -> 0.18.0` [#6033] (https://github.com/rust-lang/rustfmt/issues/6033)
56

67
## [1.7.0] 2023-10-22
78

Cargo.lock

Lines changed: 14 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,11 @@ generic-simd = ["bytecount/generic-simd"]
3636
annotate-snippets = { version = "0.9", features = ["color"] }
3737
anyhow = "1.0"
3838
bytecount = "0.6.4"
39-
cargo_metadata = "0.15.4"
39+
cargo_metadata = "0.18"
4040
clap = { version = "4.4.2", features = ["derive"] }
4141
clap-cargo = "0.12.0"
4242
diff = "0.1"
43-
dirs = "4.0"
43+
dirs = "5.0"
4444
getopts = "0.2"
4545
ignore = "0.4"
4646
itertools = "0.11"

Configurations.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Configuring Rustfmt
22

3-
Rustfmt is designed to be very configurable. You can create a TOML file called `rustfmt.toml` or `.rustfmt.toml`, place it in the project or any other parent directory and it will apply the options in that file. If none of these directories contain such a file, both your home directory and a directory called `rustfmt` in your [global config directory](https://docs.rs/dirs/4.0.0/dirs/fn.config_dir.html) (e.g. `.config/rustfmt/`) are checked as well.
3+
Rustfmt is designed to be very configurable. You can create a TOML file called `rustfmt.toml` or `.rustfmt.toml`, place it in the project or any other parent directory and it will apply the options in that file. If none of these directories contain such a file, both your home directory and a directory called `rustfmt` in your [global config directory](https://docs.rs/dirs/5.0.1/dirs/fn.config_dir.html) (e.g. `.config/rustfmt/`) are checked as well.
44

55
A possible content of `rustfmt.toml` or `.rustfmt.toml` might look like this:
66

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 `RUSTFMT_LOG=rustfmt=DEBUG`.
62+
These messages can be printed by using the environment variable `RUSTFMT_LOG=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/items.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1166,9 +1166,9 @@ pub(crate) fn format_trait(
11661166

11671167
// FIXME(#2055): rustfmt fails to format when there are comments between trait bounds.
11681168
if !bounds.is_empty() {
1169-
let ident_hi = context
1170-
.snippet_provider
1171-
.span_after(item.span, item.ident.as_str());
1169+
// Retrieve *unnormalized* ident (See #6069)
1170+
let source_ident = context.snippet(item.ident.span);
1171+
let ident_hi = context.snippet_provider.span_after(item.span, source_ident);
11721172
let bound_hi = bounds.last().unwrap().span().hi();
11731173
let snippet = context.snippet(mk_sp(ident_hi, bound_hi));
11741174
if contains_comment(snippet) {

src/macros.rs

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ use crate::comment::{
2525
contains_comment, CharClasses, FindUncommented, FullCodeCharKind, LineClasses,
2626
};
2727
use crate::config::lists::*;
28+
use crate::config::Version;
2829
use crate::expr::{rewrite_array, rewrite_assign_rhs, RhsAssignKind};
2930
use crate::lists::{itemize_list, write_list, ListFormatting};
3031
use crate::overflow;
@@ -1245,8 +1246,16 @@ impl MacroBranch {
12451246
return None;
12461247
}
12471248

1248-
// 5 = " => {"
1249-
let mut result = format_macro_args(context, self.args.clone(), shape.sub_width(5)?)?;
1249+
let old_body = context.snippet(self.body).trim();
1250+
let has_block_body = old_body.starts_with('{');
1251+
let mut prefix_width = 5; // 5 = " => {"
1252+
if context.config.version() == Version::Two {
1253+
if has_block_body {
1254+
prefix_width = 6; // 6 = " => {{"
1255+
}
1256+
}
1257+
let mut result =
1258+
format_macro_args(context, self.args.clone(), shape.sub_width(prefix_width)?)?;
12501259

12511260
if multi_branch_style {
12521261
result += " =>";
@@ -1264,9 +1273,7 @@ impl MacroBranch {
12641273
// `$$`). We'll try and format like an AST node, but we'll substitute
12651274
// variables for new names with the same length first.
12661275

1267-
let old_body = context.snippet(self.body).trim();
12681276
let (body_str, substs) = replace_names(old_body)?;
1269-
let has_block_body = old_body.starts_with('{');
12701277

12711278
let mut config = context.config.clone();
12721279
config.set().show_parse_errors(false);

src/test/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -835,7 +835,7 @@ fn handle_result(
835835
// Ignore LF and CRLF difference for Windows.
836836
if !string_eq_ignore_newline_repr(&fmt_text, &text) {
837837
if std::env::var_os("RUSTC_BLESS").is_some_and(|v| v != "0") {
838-
std::fs::write(file_name, fmt_text).unwrap();
838+
std::fs::write(target, fmt_text).unwrap();
839839
continue;
840840
}
841841
let diff = make_diff(&text, &fmt_text, DIFF_CONTEXT_SIZE);

tests/rustfmt/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ fn rustfmt_emits_error_on_line_overflow_true() {
176176
#[test]
177177
#[allow(non_snake_case)]
178178
fn dont_emit_ICE() {
179-
let files = ["tests/target/issue_5728.rs", "tests/target/issue_5729.rs"];
179+
let files = ["tests/target/issue_5728.rs", "tests/target/issue_5729.rs", "tests/target/issue_6069.rs"];
180180

181181
for file in files {
182182
let args = [file];

tests/source/issue-3805.rs

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
// rustfmt-version: Two
2+
// rustfmt-format_macro_matchers: true
3+
4+
// From original issue example - Line length 101
5+
macro_rules! test {
6+
($aasdfghj:expr, $qwertyuiop:expr, $zxcvbnmasdfghjkl:expr, $aeiouaeiouaeio:expr, $add:expr) => {{
7+
return;
8+
}};
9+
}
10+
11+
// Spaces between the `{` and `}`
12+
macro_rules! test {
13+
($aasdfghj:expr, $qwertyuiop:expr, $zxcvbnmasdfghjkl:expr, $aeiouaeiouaeio:expr, $add:expr) => { {
14+
return;
15+
} };
16+
}
17+
18+
// Multi `{}`
19+
macro_rules! test {
20+
($aasdfghj:expr, $qwertyuiop:expr, $zxcvbnmasdfghjkl:expr, $aeiouaeiouaeio:expr, $add:expr) => {{{{
21+
return;
22+
}}}};
23+
}
24+
25+
// Multi `{}` with spaces
26+
macro_rules! test {
27+
($aasdfghj:expr, $qwertyuiop:expr, $zxcvbnmasdfghjkl:expr, $aeiouaeiouaeio:expr, $add:expr) => { { { {
28+
return;
29+
} } } };
30+
}
31+
32+
// Line length 102
33+
macro_rules! test {
34+
($aasdfghj:expr, $qwertyuiop:expr, $zxcvbnmasdfghjkl:expr, $aeiouaeiouaeiou:expr, $add:expr) => {{
35+
return;
36+
}};
37+
}
38+
39+
// Line length 103
40+
macro_rules! test {
41+
($aasdfghj:expr, $qwertyuiop:expr, $zxcvbnmasdfghjkl:expr, $aeiouaeiouaeioua:expr, $add:expr) => {{
42+
return;
43+
}};
44+
}
45+
46+
// With extended macro body - Line length 101
47+
macro_rules! test {
48+
($aasdfghj:expr, $qwertyuiop:expr, $zxcvbnmasdfghjkl:expr, $aeiouaeiouaeio:expr, $add:expr) => {{
49+
let VAR = "VALUE"; return VAR;
50+
}};
51+
}
52+
53+
// With extended macro body - Line length 102
54+
macro_rules! test {
55+
($aasdfghj:expr, $qwertyuiop:expr, $zxcvbnmasdfghjkl:expr, $aeiouaeiouaeiou:expr, $add:expr) => {{
56+
let VAR = "VALUE"; return VAR;
57+
}};
58+
}
59+
60+
// With extended macro body - Line length 103
61+
macro_rules! test {
62+
($aasdfghj:expr, $qwertyuiop:expr, $zxcvbnmasdfghjkl:expr, $aeiouaeiouaeioua:expr, $add:expr) => {{
63+
let VAR = "VALUE"; return VAR;
64+
}};
65+
}

0 commit comments

Comments
 (0)