Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 6e1638d

Browse files
style: use {name} syntax in string formatting macros
PR #1243
1 parent 6f18a22 commit 6e1638d

File tree

8 files changed

+20
-23
lines changed

8 files changed

+20
-23
lines changed

‎src/error.rs‎

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,7 @@ impl core::fmt::Display for Error {
7171
Error::Syntax(ref err) => err.fmt(f),
7272
Error::CompiledTooBig(limit) => write!(
7373
f,
74-
"Compiled regex exceeds size limit of {} bytes.",
75-
limit
74+
"Compiled regex exceeds size limit of {limit} bytes."
7675
),
7776
}
7877
}
@@ -88,9 +87,9 @@ impl core::fmt::Debug for Error {
8887
Error::Syntax(ref err) => {
8988
let hr: String = core::iter::repeat('~').take(79).collect();
9089
writeln!(f, "Syntax(")?;
91-
writeln!(f, "{}", hr)?;
92-
writeln!(f, "{}", err)?;
93-
writeln!(f, "{}", hr)?;
90+
writeln!(f, "{hr}")?;
91+
writeln!(f, "{err}")?;
92+
writeln!(f, "{hr}")?;
9493
write!(f, ")")?;
9594
Ok(())
9695
}

‎src/regex/bytes.rs‎

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1787,7 +1787,7 @@ impl<'h> Captures<'h> {
17871787
.expect("number of capture groups can vary in a match")
17881788
.checked_sub(1)
17891789
.expect("number of groups is always greater than zero");
1790-
assert_eq!(N, len, "asked for {} groups, but must ask for {}",N, len);
1790+
assert_eq!(N, len, "asked for {N} groups, but must ask for {len}");
17911791
// The regex-automata variant of extract is a bit more permissive.
17921792
// It doesn't require the number of matching capturing groups to be
17931793
// static, and you can even request fewer groups than what's there. So
@@ -1942,7 +1942,7 @@ impl<'h> core::fmt::Debug for Captures<'h> {
19421942
fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result {
19431943
write!(f, "{}", self.0)?;
19441944
if let Some(name) = self.1 {
1945-
write!(f, "/{:?}", name)?;
1945+
write!(f, "/{name:?}")?;
19461946
}
19471947
Ok(())
19481948
}
@@ -2646,7 +2646,7 @@ mod tests {
26462646
fn test_debug_output_valid_utf8() {
26472647
let haystack = b"Hello, world!";
26482648
let m = Match::new(haystack, 7, 12);
2649-
let debug_str = format!("{:?}", m);
2649+
let debug_str = format!("{m:?}");
26502650

26512651
assert_eq!(
26522652
debug_str,
@@ -2658,7 +2658,7 @@ mod tests {
26582658
fn test_debug_output_invalid_utf8() {
26592659
let haystack = b"Hello, \xFFworld!";
26602660
let m = Match::new(haystack, 7, 13);
2661-
let debug_str = format!("{:?}", m);
2661+
let debug_str = format!("{m:?}");
26622662

26632663
assert_eq!(
26642664
debug_str,
@@ -2671,7 +2671,7 @@ mod tests {
26712671
let haystack =
26722672
"Hello, 😊 world! 안녕하세요? مرحبا بالعالم!".as_bytes();
26732673
let m = Match::new(haystack, 0, haystack.len());
2674-
let debug_str = format!("{:?}", m);
2674+
let debug_str = format!("{m:?}");
26752675

26762676
assert_eq!(
26772677
debug_str,
@@ -2683,7 +2683,7 @@ mod tests {
26832683
fn test_debug_output_ascii_escape() {
26842684
let haystack = b"Hello,\tworld!\nThis is a \x1b[31mtest\x1b[0m.";
26852685
let m = Match::new(haystack, 0, haystack.len());
2686-
let debug_str = format!("{:?}", m);
2686+
let debug_str = format!("{m:?}");
26872687

26882688
assert_eq!(
26892689
debug_str,
@@ -2695,7 +2695,7 @@ mod tests {
26952695
fn test_debug_output_match_in_middle() {
26962696
let haystack = b"The quick brown fox jumps over the lazy dog.";
26972697
let m = Match::new(haystack, 16, 19);
2698-
let debug_str = format!("{:?}", m);
2698+
let debug_str = format!("{m:?}");
26992699

27002700
assert_eq!(debug_str, r#"Match { start: 16, end: 19, bytes: "fox" }"#);
27012701
}

‎src/regex/string.rs‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1797,7 +1797,7 @@ impl<'h> Captures<'h> {
17971797
.expect("number of capture groups can vary in a match")
17981798
.checked_sub(1)
17991799
.expect("number of groups is always greater than zero");
1800-
assert_eq!(N, len, "asked for {} groups, but must ask for {}",N, len);
1800+
assert_eq!(N, len, "asked for {N} groups, but must ask for {len}");
18011801
// The regex-automata variant of extract is a bit more permissive.
18021802
// It doesn't require the number of matching capturing groups to be
18031803
// static, and you can even request fewer groups than what's there. So
@@ -1952,7 +1952,7 @@ impl<'h> core::fmt::Debug for Captures<'h> {
19521952
fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result {
19531953
write!(f, "{}", self.0)?;
19541954
if let Some(name) = self.1 {
1955-
write!(f, "/{:?}", name)?;
1955+
write!(f, "/{name:?}")?;
19561956
}
19571957
Ok(())
19581958
}

‎tests/misc.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ macro_rules! regex {
1010
fn unclosed_group_error() {
1111
let err = Regex::new(r"(").unwrap_err();
1212
let msg = err.to_string();
13-
assert!(msg.contains("unclosed group"), "error message: {:?}", msg);
13+
assert!(msg.contains("unclosed group"), "error message: {msg:?}");
1414
}
1515

1616
#[test]

‎tests/suite_bytes.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ fn run_test(re: &Regex, test: &RegexTest) -> TestResult {
3636
.map(|caps| testify_captures(&caps));
3737
TestResult::captures(it)
3838
}
39-
name => TestResult::fail(&format!("unrecognized test name: {}", name)),
39+
name => TestResult::fail(&format!("unrecognized test name: {name}")),
4040
}
4141
}
4242

‎tests/suite_bytes_set.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ fn run_test(re: &RegexSet, test: &RegexTest) -> TestResult {
2020
match test.additional_name() {
2121
"is_match" => TestResult::matched(re.is_match(test.haystack())),
2222
"which" => TestResult::which(re.matches(test.haystack()).iter()),
23-
name => TestResult::fail(&format!("unrecognized test name: {}", name)),
23+
name => TestResult::fail(&format!("unrecognized test name: {name}")),
2424
}
2525
}
2626

‎tests/suite_string.rs‎

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,7 @@ fn run_test(re: &Regex, test: &RegexTest) -> TestResult {
2323
Ok(hay) => hay,
2424
Err(err) => {
2525
return TestResult::fail(&format!(
26-
"haystack is not valid UTF-8: {}",
27-
err
26+
"haystack is not valid UTF-8: {err}"
2827
));
2928
}
3029
};
@@ -45,7 +44,7 @@ fn run_test(re: &Regex, test: &RegexTest) -> TestResult {
4544
.map(|caps| testify_captures(&caps));
4645
TestResult::captures(it)
4746
}
48-
name => TestResult::fail(&format!("unrecognized test name: {}", name)),
47+
name => TestResult::fail(&format!("unrecognized test name: {name}")),
4948
}
5049
}
5150

‎tests/suite_string_set.rs‎

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,14 @@ fn run_test(re: &RegexSet, test: &RegexTest) -> TestResult {
2121
Ok(hay) => hay,
2222
Err(err) => {
2323
return TestResult::fail(&format!(
24-
"haystack is not valid UTF-8: {}",
25-
err
24+
"haystack is not valid UTF-8: {err}"
2625
));
2726
}
2827
};
2928
match test.additional_name() {
3029
"is_match" => TestResult::matched(re.is_match(hay)),
3130
"which" => TestResult::which(re.matches(hay).iter()),
32-
name => TestResult::fail(&format!("unrecognized test name: {}", name)),
31+
name => TestResult::fail(&format!("unrecognized test name: {name}")),
3332
}
3433
}
3534

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /