Skip to content

Commit f0e62e3

Browse files
authored
Merge branch 'master' into issue_5735
2 parents 85d2123 + 4b01e62 commit f0e62e3

Some content is hidden

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

47 files changed

+285
-267
lines changed

Cargo.lock

+14-14
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

+2-2
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ generic-simd = ["bytecount/generic-simd"]
3535
[dependencies]
3636
annotate-snippets = { version = "0.9", features = ["color"] }
3737
anyhow = "1.0"
38-
bytecount = "0.6"
38+
bytecount = "0.6.3"
3939
cargo_metadata = "0.15.4"
4040
clap = { version = "4.2.1", features = ["derive"] }
4141
diff = "0.1"
@@ -54,7 +54,7 @@ tracing = "0.1.37"
5454
tracing-subscriber = { version = "0.3.17", features = ["env-filter"] }
5555
unicode-segmentation = "1.9"
5656
unicode-width = "0.1"
57-
unicode_categories = "0.1"
57+
unicode-properties = { version = "0.1", default-features = false, features = ["general-category"] }
5858

5959
rustfmt-config_proc_macro = { version = "0.3", path = "config_proc_macro" }
6060

ci/build_and_test.bat

+5-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,11 @@ rustc -Vv || exit /b 1
66
cargo -V || exit /b 1
77

88
:: Build and test main crate
9-
cargo build --locked || exit /b 1
9+
if "%CFG_RELEASE_CHANNEL%"=="nightly" (
10+
cargo build --locked --all-features || exit /b 1
11+
) else (
12+
cargo build --locked || exit /b 1
13+
)
1014
cargo test || exit /b 1
1115

1216
:: Build and test other crates

ci/build_and_test.sh

+5-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,11 @@ rustc -Vv
1010
cargo -V
1111

1212
# Build and test main crate
13-
cargo build --locked
13+
if [ "$CFG_RELEASE_CHANNEL" == "nightly" ]; then
14+
cargo build --locked --all-features
15+
else
16+
cargo build --locked
17+
fi
1418
cargo test
1519

1620
# Build and test other crates

src/attr.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -308,7 +308,7 @@ impl Rewrite for ast::MetaItem {
308308
// See #2479 for example.
309309
let value = rewrite_literal(context, lit.as_token_lit(), lit.span, lit_shape)
310310
.unwrap_or_else(|| context.snippet(lit.span).to_owned());
311-
format!("{} = {}", path, value)
311+
format!("{path} = {value}")
312312
}
313313
})
314314
}
@@ -342,7 +342,7 @@ impl Rewrite for ast::Attribute {
342342
let literal_str = literal.as_str();
343343
let doc_comment_formatter =
344344
DocCommentFormatter::new(literal_str, comment_style);
345-
let doc_comment = format!("{}", doc_comment_formatter);
345+
let doc_comment = format!("{doc_comment_formatter}");
346346
return rewrite_doc_comment(
347347
&doc_comment,
348348
shape.comment(context.config),
@@ -406,9 +406,9 @@ impl Rewrite for [ast::Attribute] {
406406
0,
407407
)?;
408408
let comment = if comment.is_empty() {
409-
format!("\n{}", mlb)
409+
format!("\n{mlb}")
410410
} else {
411-
format!("{}{}\n{}", mla, comment, mlb)
411+
format!("{mla}{comment}\n{mlb}")
412412
};
413413
result.push_str(&comment);
414414
result.push_str(&shape.indent.to_string(context.config));

src/attr/doc_comment.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,15 @@ impl Display for DocCommentFormatter<'_> {
2020

2121
// Handle `#[doc = ""]`.
2222
if lines.peek().is_none() {
23-
return write!(formatter, "{}", opener);
23+
return write!(formatter, "{opener}");
2424
}
2525

2626
while let Some(line) = lines.next() {
2727
let is_last_line = lines.peek().is_none();
2828
if is_last_line {
29-
write!(formatter, "{}{}", opener, line)?;
29+
write!(formatter, "{opener}{line}")?;
3030
} else {
31-
writeln!(formatter, "{}{}", opener, line)?;
31+
writeln!(formatter, "{opener}{line}")?;
3232
}
3333
}
3434
Ok(())

src/bin/main.rs

+9-12
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ fn main() {
3838
let exit_code = match execute(&opts) {
3939
Ok(code) => code,
4040
Err(e) => {
41-
eprintln!("{:#}", e);
41+
eprintln!("{e:#}");
4242
1
4343
}
4444
};
@@ -284,7 +284,7 @@ fn format_string(input: String, options: GetOptsOptions) -> Result<i32> {
284284
for f in config.file_lines().files() {
285285
match *f {
286286
FileName::Stdin => {}
287-
_ => eprintln!("Warning: Extra file listed in file_lines option '{}'", f),
287+
_ => eprintln!("Warning: Extra file listed in file_lines option '{f}'"),
288288
}
289289
}
290290

@@ -380,7 +380,7 @@ fn format_and_emit_report<T: Write>(session: &mut Session<'_, T>, input: Input)
380380
}
381381
}
382382
Err(msg) => {
383-
eprintln!("Error writing files: {}", msg);
383+
eprintln!("Error writing files: {msg}");
384384
session.add_operational_error();
385385
}
386386
}
@@ -403,12 +403,9 @@ fn print_usage_to_stdout(opts: &Options, reason: &str) {
403403
let sep = if reason.is_empty() {
404404
String::new()
405405
} else {
406-
format!("{}\n\n", reason)
406+
format!("{reason}\n\n")
407407
};
408-
let msg = format!(
409-
"{}Format Rust code\n\nusage: rustfmt [options] <file>...",
410-
sep
411-
);
408+
let msg = format!("{sep}Format Rust code\n\nusage: rustfmt [options] <file>...");
412409
println!("{}", opts.usage(&msg));
413410
}
414411

@@ -422,7 +419,7 @@ are 1-based and inclusive of both end points. Specifying an empty array
422419
will result in no files being formatted. For example,
423420
424421
```
425-
rustfmt --file-lines '[
422+
rustfmt src/lib.rs src/foo.rs --file-lines '[
426423
{{\"file\":\"src/lib.rs\",\"range\":[7,13]}},
427424
{{\"file\":\"src/lib.rs\",\"range\":[21,29]}},
428425
{{\"file\":\"src/foo.rs\",\"range\":[10,11]}},
@@ -442,7 +439,7 @@ fn print_version() {
442439
include_str!(concat!(env!("OUT_DIR"), "/commit-info.txt"))
443440
);
444441

445-
println!("rustfmt {}", version_info);
442+
println!("rustfmt {version_info}");
446443
}
447444

448445
fn determine_operation(matches: &Matches) -> Result<Operation, OperationError> {
@@ -647,9 +644,9 @@ impl GetOptsOptions {
647644
match *f {
648645
FileName::Real(ref f) if files.contains(f) => {}
649646
FileName::Real(_) => {
650-
eprintln!("Warning: Extra file listed in file_lines option '{}'", f)
647+
eprintln!("Warning: Extra file listed in file_lines option '{f}'")
651648
}
652-
FileName::Stdin => eprintln!("Warning: Not a file '{}'", f),
649+
FileName::Stdin => eprintln!("Warning: Not a file '{f}'"),
653650
}
654651
}
655652
}

src/cargo-fmt/main.rs

+4-5
Original file line numberDiff line numberDiff line change
@@ -200,14 +200,13 @@ fn convert_message_format_to_rustfmt_args(
200200
}
201201
"human" => Ok(()),
202202
_ => Err(format!(
203-
"invalid --message-format value: {}. Allowed values are: short|json|human",
204-
message_format
203+
"invalid --message-format value: {message_format}. Allowed values are: short|json|human"
205204
)),
206205
}
207206
}
208207

209208
fn print_usage_to_stderr(reason: &str) {
210-
eprintln!("{}", reason);
209+
eprintln!("{reason}");
211210
let app = Opts::command();
212211
app.after_help("")
213212
.write_help(&mut io::stderr())
@@ -460,7 +459,7 @@ fn get_targets_with_hitlist(
460459
let package = workspace_hitlist.iter().next().unwrap();
461460
Err(io::Error::new(
462461
io::ErrorKind::InvalidInput,
463-
format!("package `{}` is not a member of the workspace", package),
462+
format!("package `{package}` is not a member of the workspace"),
464463
))
465464
}
466465
}
@@ -498,7 +497,7 @@ fn run_rustfmt(
498497

499498
if verbosity == Verbosity::Verbose {
500499
print!("rustfmt");
501-
print!(" --edition {}", edition);
500+
print!(" --edition {edition}");
502501
fmt_args.iter().for_each(|f| print!(" {}", f));
503502
files.iter().for_each(|f| print!(" {}", f.display()));
504503
println!();

src/chains.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,7 @@ impl Rewrite for ChainItem {
296296
rewrite_comment(comment, false, shape, context.config)?
297297
}
298298
};
299-
Some(format!("{}{}", rewrite, "?".repeat(self.tries)))
299+
Some(format!("{rewrite}{}", "?".repeat(self.tries)))
300300
}
301301
}
302302

src/closures.rs

+2-5
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ fn rewrite_closure_with_block(
175175
shape,
176176
false,
177177
)?;
178-
Some(format!("{} {}", prefix, block))
178+
Some(format!("{prefix} {block}"))
179179
}
180180

181181
// Rewrite closure with a single expression without wrapping its body with block.
@@ -310,10 +310,7 @@ fn rewrite_closure_fn_decl(
310310
.tactic(tactic)
311311
.preserve_newline(true);
312312
let list_str = write_list(&item_vec, &fmt)?;
313-
let mut prefix = format!(
314-
"{}{}{}{}{}|{}|",
315-
binder, const_, immovable, is_async, mover, list_str
316-
);
313+
let mut prefix = format!("{binder}{const_}{immovable}{is_async}{mover}|{list_str}|");
317314

318315
if !ret_str.is_empty() {
319316
if prefix.contains('\n') {

src/comment.rs

+10-25
Original file line numberDiff line numberDiff line change
@@ -621,7 +621,7 @@ impl<'a> CommentRewrite<'a> {
621621
is_prev_line_multi_line: false,
622622
code_block_attr: None,
623623
item_block: None,
624-
comment_line_separator: format!("{}{}", indent_str, line_start),
624+
comment_line_separator: format!("{indent_str}{line_start}"),
625625
max_width,
626626
indent_str,
627627
fmt_indent: shape.indent,
@@ -951,7 +951,7 @@ const RUSTFMT_CUSTOM_COMMENT_PREFIX: &str = "//#### ";
951951
fn hide_sharp_behind_comment(s: &str) -> Cow<'_, str> {
952952
let s_trimmed = s.trim();
953953
if s_trimmed.starts_with("# ") || s_trimmed == "#" {
954-
Cow::from(format!("{}{}", RUSTFMT_CUSTOM_COMMENT_PREFIX, s))
954+
Cow::from(format!("{RUSTFMT_CUSTOM_COMMENT_PREFIX}{s}"))
955955
} else {
956956
Cow::from(s)
957957
}
@@ -1035,7 +1035,7 @@ pub(crate) fn recover_missing_comment_in_span(
10351035
} else {
10361036
Cow::from(" ")
10371037
};
1038-
Some(format!("{}{}", sep, missing_comment))
1038+
Some(format!("{sep}{missing_comment}"))
10391039
}
10401040
}
10411041

@@ -1832,8 +1832,7 @@ fn remove_comment_header(comment: &str) -> &str {
18321832
} else {
18331833
assert!(
18341834
comment.starts_with("/*"),
1835-
"string '{}' is not a comment",
1836-
comment
1835+
"string '{comment}' is not a comment"
18371836
);
18381837
&comment[2..comment.len() - 2]
18391838
}
@@ -2069,26 +2068,13 @@ fn main() {
20692068
expected_line_start: &str,
20702069
) {
20712070
let block = ItemizedBlock::new(test_input).unwrap();
2072-
assert_eq!(1, block.lines.len(), "test_input: {:?}", test_input);
2073-
assert_eq!(
2074-
expected_line, &block.lines[0],
2075-
"test_input: {:?}",
2076-
test_input
2077-
);
2078-
assert_eq!(
2079-
expected_indent, block.indent,
2080-
"test_input: {:?}",
2081-
test_input
2082-
);
2083-
assert_eq!(
2084-
expected_opener, &block.opener,
2085-
"test_input: {:?}",
2086-
test_input
2087-
);
2071+
assert_eq!(1, block.lines.len(), "test_input: {test_input:?}");
2072+
assert_eq!(expected_line, &block.lines[0], "test_input: {test_input:?}");
2073+
assert_eq!(expected_indent, block.indent, "test_input: {test_input:?}");
2074+
assert_eq!(expected_opener, &block.opener, "test_input: {test_input:?}");
20882075
assert_eq!(
20892076
expected_line_start, &block.line_start,
2090-
"test_input: {:?}",
2091-
test_input
2077+
"test_input: {test_input:?}"
20922078
);
20932079
}
20942080

@@ -2145,8 +2131,7 @@ fn main() {
21452131
let maybe_block = ItemizedBlock::new(line);
21462132
assert!(
21472133
maybe_block.is_none(),
2148-
"The following line shouldn't be classified as a list item: {}",
2149-
line
2134+
"The following line shouldn't be classified as a list item: {line}"
21502135
);
21512136
}
21522137
}

src/config/config_type.rs

+4-6
Original file line numberDiff line numberDiff line change
@@ -500,18 +500,16 @@ where
500500
// Stable with an unstable option
501501
(false, false, _) => {
502502
eprintln!(
503-
"Warning: can't set `{} = {:?}`, unstable features are only \
504-
available in nightly channel.",
505-
option_name, option_value
503+
"Warning: can't set `{option_name} = {option_value:?}`, unstable features are only \
504+
available in nightly channel."
506505
);
507506
false
508507
}
509508
// Stable with a stable option, but an unstable variant
510509
(false, true, false) => {
511510
eprintln!(
512-
"Warning: can't set `{} = {:?}`, unstable variants are only \
513-
available in nightly channel.",
514-
option_name, option_value
511+
"Warning: can't set `{option_name} = {option_value:?}`, unstable variants are only \
512+
available in nightly channel."
515513
);
516514
false
517515
}

0 commit comments

Comments
 (0)