Skip to content

Commit eca7344

Browse files
committed
Inline format-args
This makes the code a bit easier to read and smaller. Some of it was done with this command, and later fixed by hand: ``` cargo clippy --workspace --allow-dirty --fix --benches --tests --bins -- -A clippy::all -W clippy::uninlined_format_args ```
1 parent 2695e29 commit eca7344

File tree

10 files changed

+30
-32
lines changed

10 files changed

+30
-32
lines changed

regex-lite/src/hir/parse.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -593,8 +593,7 @@ impl<'a> Parser<'a> {
593593
'u' => 4,
594594
'U' => 8,
595595
unk => unreachable!(
596-
"invalid start of fixed length hexadecimal number {}",
597-
unk
596+
"invalid start of fixed length hexadecimal number {unk}"
598597
),
599598
};
600599
if !self.bump_and_bump_space() {
@@ -720,7 +719,7 @@ impl<'a> Parser<'a> {
720719
'?' => (0, Some(1)),
721720
'*' => (0, None),
722721
'+' => (1, None),
723-
unk => unreachable!("unrecognized repetition operator '{}'", unk),
722+
unk => unreachable!("unrecognized repetition operator '{unk}'"),
724723
};
725724
let mut greedy = true;
726725
if self.bump() && self.char() == '?' {
@@ -1216,7 +1215,7 @@ impl<'a> Parser<'a> {
12161215
'd' | 'D' => posix_class("digit").unwrap(),
12171216
's' | 'S' => posix_class("space").unwrap(),
12181217
'w' | 'W' => posix_class("word").unwrap(),
1219-
unk => unreachable!("invalid Perl class \\{}", unk),
1218+
unk => unreachable!("invalid Perl class \\{unk}"),
12201219
});
12211220
if ch.is_ascii_uppercase() {
12221221
class.negate();

regex-lite/src/nfa.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ impl core::fmt::Debug for NFA {
136136
writeln!(f, "NFA(")?;
137137
writeln!(f, "pattern: {}", self.pattern)?;
138138
for (sid, state) in self.states.iter().enumerate() {
139-
writeln!(f, "{:07?}: {:?}", sid, state)?;
139+
writeln!(f, "{sid:07?}: {state:?}")?;
140140
}
141141
writeln!(f, ")")?;
142142
Ok(())
@@ -206,14 +206,14 @@ impl core::fmt::Debug for State {
206206
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
207207
match *self {
208208
State::Char { target, ch } => {
209-
write!(f, "{:?} => {:?}", ch, target)
209+
write!(f, "{ch:?} => {target:?}")
210210
}
211211
State::Ranges { target, ref ranges } => {
212212
for (i, &(start, end)) in ranges.iter().enumerate() {
213213
if i > 0 {
214214
write!(f, ", ")?;
215215
}
216-
write!(f, "{:?}-{:?} => {:?}", start, end, target)?;
216+
write!(f, "{start:?}-{end:?} => {target:?}")?;
217217
}
218218
Ok(())
219219
}
@@ -225,18 +225,18 @@ impl core::fmt::Debug for State {
225225
if i > 0 {
226226
write!(f, ", ")?;
227227
}
228-
write!(f, "{:?}", sid)?;
228+
write!(f, "{sid:?}")?;
229229
}
230230
write!(f, ")")
231231
}
232232
State::Goto { target, look: None } => {
233-
write!(f, "goto({:?})", target)
233+
write!(f, "goto({target:?})")
234234
}
235235
State::Goto { target, look: Some(look) } => {
236-
write!(f, "{:?} => {:?}", look, target)
236+
write!(f, "{look:?} => {target:?}")
237237
}
238238
State::Capture { target, slot } => {
239-
write!(f, "capture(slot={:?}) => {:?}", slot, target,)
239+
write!(f, "capture(slot={slot:?}) => {target:?}")
240240
}
241241
State::Fail => write!(f, "FAIL"),
242242
State::Match => {

regex-lite/src/string.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1798,7 +1798,7 @@ impl<'h> Captures<'h> {
17981798
.nfa()
17991799
.static_explicit_captures_len()
18001800
.expect("number of capture groups can vary in a match");
1801-
assert_eq!(N, len, "asked for {} groups, but must ask for {}", N, len);
1801+
assert_eq!(N, len, "asked for {N} groups, but must ask for {len}");
18021802
let mut matched = self.iter().flatten();
18031803
let whole_match = matched.next().expect("a match").as_str();
18041804
let group_matches = [0; N].map(|_| {
@@ -1965,7 +1965,7 @@ impl<'h> core::fmt::Debug for Captures<'h> {
19651965
fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result {
19661966
write!(f, "{}", self.0)?;
19671967
if let Some(name) = self.1 {
1968-
write!(f, "/{:?}", name)?;
1968+
write!(f, "/{name:?}")?;
19691969
}
19701970
Ok(())
19711971
}
@@ -2013,7 +2013,7 @@ impl<'h> core::ops::Index<usize> for Captures<'h> {
20132013
fn index(&self, i: usize) -> &str {
20142014
self.get(i)
20152015
.map(|m| m.as_str())
2016-
.unwrap_or_else(|| panic!("no group at index '{}'", i))
2016+
.unwrap_or_else(|| panic!("no group at index '{i}'"))
20172017
}
20182018
}
20192019

@@ -2039,7 +2039,7 @@ impl<'h, 'n> core::ops::Index<&'n str> for Captures<'h> {
20392039
fn index<'a>(&'a self, name: &'n str) -> &'a str {
20402040
self.name(name)
20412041
.map(|m| m.as_str())
2042-
.unwrap_or_else(|| panic!("no group named '{}'", name))
2042+
.unwrap_or_else(|| panic!("no group named '{name}'"))
20432043
}
20442044
}
20452045

regex-lite/tests/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

regex-test/lib.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -151,17 +151,17 @@ impl RegexTests {
151151
/// The given group name is assigned to all loaded tests.
152152
pub fn load_slice(&mut self, group_name: &str, data: &[u8]) -> Result<()> {
153153
let data = std::str::from_utf8(&data).with_context(|| {
154-
format!("data in {} is not valid UTF-8", group_name)
154+
format!("data in {group_name} is not valid UTF-8")
155155
})?;
156156
let mut index = 1;
157157
let mut tests: RegexTests =
158158
toml::from_str(&data).with_context(|| {
159-
format!("error decoding TOML for '{}'", group_name)
159+
format!("error decoding TOML for '{group_name}'")
160160
})?;
161161
for t in &mut tests.tests {
162162
t.group = group_name.to_string();
163163
if t.name.is_empty() {
164-
t.name = format!("{}", index);
164+
t.name = format!("{index}");
165165
index += 1;
166166
}
167167
t.full_name = format!("{}/{}", t.group, t.name);
@@ -1101,7 +1101,7 @@ impl RegexTestFailureKind {
11011101
let mut buf = String::new();
11021102
match *self {
11031103
RegexTestFailureKind::UserFailure { ref why } => {
1104-
write!(buf, "failed by implementor because: {}", why)?;
1104+
write!(buf, "failed by implementor because: {why}")?;
11051105
}
11061106
RegexTestFailureKind::IsMatch => {
11071107
if test.is_match() {
@@ -1140,13 +1140,13 @@ impl RegexTestFailureKind {
11401140
write!(buf, "expected regex to NOT compile, but it did")?;
11411141
}
11421142
RegexTestFailureKind::CompileError { ref err } => {
1143-
write!(buf, "expected regex to compile, failed: {}", err)?;
1143+
write!(buf, "expected regex to compile, failed: {err}")?;
11441144
}
11451145
RegexTestFailureKind::UnexpectedPanicCompile(ref msg) => {
1146-
write!(buf, "got unexpected panic while compiling:\n{}", msg)?;
1146+
write!(buf, "got unexpected panic while compiling:\n{msg}")?;
11471147
}
11481148
RegexTestFailureKind::UnexpectedPanicSearch(ref msg) => {
1149-
write!(buf, "got unexpected panic while searching:\n{}", msg)?;
1149+
write!(buf, "got unexpected panic while searching:\n{msg}")?;
11501150
}
11511151
}
11521152
Ok(buf)

src/error.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +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 {limit} bytes."
74+
"Compiled regex exceeds size limit of {limit} bytes.",
7575
),
7676
}
7777
}

src/regex/bytes.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1992,7 +1992,7 @@ impl<'h> core::ops::Index<usize> for Captures<'h> {
19921992
fn index<'a>(&'a self, i: usize) -> &'a [u8] {
19931993
self.get(i)
19941994
.map(|m| m.as_bytes())
1995-
.unwrap_or_else(|| panic!("no group at index '{}'", i))
1995+
.unwrap_or_else(|| panic!("no group at index '{i}'"))
19961996
}
19971997
}
19981998

@@ -2018,7 +2018,7 @@ impl<'h, 'n> core::ops::Index<&'n str> for Captures<'h> {
20182018
fn index<'a>(&'a self, name: &'n str) -> &'a [u8] {
20192019
self.name(name)
20202020
.map(|m| m.as_bytes())
2021-
.unwrap_or_else(|| panic!("no group named '{}'", name))
2021+
.unwrap_or_else(|| panic!("no group named '{name}'"))
20222022
}
20232023
}
20242024

src/regex/string.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2000,7 +2000,7 @@ impl<'h> core::ops::Index<usize> for Captures<'h> {
20002000
fn index<'a>(&'a self, i: usize) -> &'a str {
20012001
self.get(i)
20022002
.map(|m| m.as_str())
2003-
.unwrap_or_else(|| panic!("no group at index '{}'", i))
2003+
.unwrap_or_else(|| panic!("no group at index '{i}'"))
20042004
}
20052005
}
20062006

@@ -2026,7 +2026,7 @@ impl<'h, 'n> core::ops::Index<&'n str> for Captures<'h> {
20262026
fn index<'a>(&'a self, name: &'n str) -> &'a str {
20272027
self.name(name)
20282028
.map(|m| m.as_str())
2029-
.unwrap_or_else(|| panic!("no group named '{}'", name))
2029+
.unwrap_or_else(|| panic!("no group named '{name}'"))
20302030
}
20312031
}
20322032

tests/suite_string.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +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: {err}"
26+
"haystack is not valid UTF-8: {err}",
2727
));
2828
}
2929
};

tests/suite_string_set.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ 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: {err}"
24+
"haystack is not valid UTF-8: {err}",
2525
));
2626
}
2727
};

0 commit comments

Comments
 (0)