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

style: simplify some statements for readability #1243

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
9 changes: 4 additions & 5 deletions src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,7 @@ impl core::fmt::Display for Error {
Error::Syntax(ref err) => err.fmt(f),
Error::CompiledTooBig(limit) => write!(
f,
"Compiled regex exceeds size limit of {} bytes.",
limit
"Compiled regex exceeds size limit of {limit} bytes."
),
}
}
Expand All @@ -88,9 +87,9 @@ impl core::fmt::Debug for Error {
Error::Syntax(ref err) => {
let hr: String = core::iter::repeat('~').take(79).collect();
writeln!(f, "Syntax(")?;
writeln!(f, "{}", hr)?;
writeln!(f, "{}", err)?;
writeln!(f, "{}", hr)?;
writeln!(f, "{hr}")?;
writeln!(f, "{err}")?;
writeln!(f, "{hr}")?;
write!(f, ")")?;
Ok(())
}
Expand Down
14 changes: 7 additions & 7 deletions src/regex/bytes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1787,7 +1787,7 @@ impl<'h> Captures<'h> {
.expect("number of capture groups can vary in a match")
.checked_sub(1)
.expect("number of groups is always greater than zero");
assert_eq!(N, len, "asked for {} groups, but must ask for {}", N, len);
assert_eq!(N, len, "asked for {N} groups, but must ask for {len}");
// The regex-automata variant of extract is a bit more permissive.
// It doesn't require the number of matching capturing groups to be
// static, and you can even request fewer groups than what's there. So
Expand Down Expand Up @@ -1942,7 +1942,7 @@ impl<'h> core::fmt::Debug for Captures<'h> {
fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result {
write!(f, "{}", self.0)?;
if let Some(name) = self.1 {
write!(f, "/{:?}", name)?;
write!(f, "/{name:?}")?;
}
Ok(())
}
Expand Down Expand Up @@ -2646,7 +2646,7 @@ mod tests {
fn test_debug_output_valid_utf8() {
let haystack = b"Hello, world!";
let m = Match::new(haystack, 7, 12);
let debug_str = format!("{:?}", m);
let debug_str = format!("{m:?}");

assert_eq!(
debug_str,
Expand All @@ -2658,7 +2658,7 @@ mod tests {
fn test_debug_output_invalid_utf8() {
let haystack = b"Hello, \xFFworld!";
let m = Match::new(haystack, 7, 13);
let debug_str = format!("{:?}", m);
let debug_str = format!("{m:?}");

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

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

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

assert_eq!(debug_str, r#"Match { start: 16, end: 19, bytes: "fox" }"#);
}
Expand Down
4 changes: 2 additions & 2 deletions src/regex/string.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1797,7 +1797,7 @@ impl<'h> Captures<'h> {
.expect("number of capture groups can vary in a match")
.checked_sub(1)
.expect("number of groups is always greater than zero");
assert_eq!(N, len, "asked for {} groups, but must ask for {}", N, len);
assert_eq!(N, len, "asked for {N} groups, but must ask for {len}");
// The regex-automata variant of extract is a bit more permissive.
// It doesn't require the number of matching capturing groups to be
// static, and you can even request fewer groups than what's there. So
Expand Down Expand Up @@ -1952,7 +1952,7 @@ impl<'h> core::fmt::Debug for Captures<'h> {
fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result {
write!(f, "{}", self.0)?;
if let Some(name) = self.1 {
write!(f, "/{:?}", name)?;
write!(f, "/{name:?}")?;
}
Ok(())
}
Expand Down
2 changes: 1 addition & 1 deletion tests/misc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ macro_rules! regex {
fn unclosed_group_error() {
let err = Regex::new(r"(").unwrap_err();
let msg = err.to_string();
assert!(msg.contains("unclosed group"), "error message: {:?}", msg);
assert!(msg.contains("unclosed group"), "error message: {msg:?}");
}

#[test]
Expand Down
2 changes: 1 addition & 1 deletion tests/suite_bytes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ fn run_test(re: &Regex, test: &RegexTest) -> TestResult {
.map(|caps| testify_captures(&caps));
TestResult::captures(it)
}
name => TestResult::fail(&format!("unrecognized test name: {}", name)),
name => TestResult::fail(&format!("unrecognized test name: {name}")),
}
}

Expand Down
2 changes: 1 addition & 1 deletion tests/suite_bytes_set.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ fn run_test(re: &RegexSet, test: &RegexTest) -> TestResult {
match test.additional_name() {
"is_match" => TestResult::matched(re.is_match(test.haystack())),
"which" => TestResult::which(re.matches(test.haystack()).iter()),
name => TestResult::fail(&format!("unrecognized test name: {}", name)),
name => TestResult::fail(&format!("unrecognized test name: {name}")),
}
}

Expand Down
5 changes: 2 additions & 3 deletions tests/suite_string.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@ fn run_test(re: &Regex, test: &RegexTest) -> TestResult {
Ok(hay) => hay,
Err(err) => {
return TestResult::fail(&format!(
"haystack is not valid UTF-8: {}",
err
"haystack is not valid UTF-8: {err}"
));
}
};
Expand All @@ -45,7 +44,7 @@ fn run_test(re: &Regex, test: &RegexTest) -> TestResult {
.map(|caps| testify_captures(&caps));
TestResult::captures(it)
}
name => TestResult::fail(&format!("unrecognized test name: {}", name)),
name => TestResult::fail(&format!("unrecognized test name: {name}")),
}
}

Expand Down
5 changes: 2 additions & 3 deletions tests/suite_string_set.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,14 @@ fn run_test(re: &RegexSet, test: &RegexTest) -> TestResult {
Ok(hay) => hay,
Err(err) => {
return TestResult::fail(&format!(
"haystack is not valid UTF-8: {}",
err
"haystack is not valid UTF-8: {err}"
));
}
};
match test.additional_name() {
"is_match" => TestResult::matched(re.is_match(hay)),
"which" => TestResult::which(re.matches(hay).iter()),
name => TestResult::fail(&format!("unrecognized test name: {}", name)),
name => TestResult::fail(&format!("unrecognized test name: {name}")),
}
}

Expand Down